Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Programming the coherence function using Advanced Analysis Library

Hello,
 
I am trying to program the standard coherence function:  Γ2xy( f ) = |Gxy( f )|2 / [Gxx ( f )Gyy( f )]  in VC++ using the advanced analysis library. 
 
First I tried:
  CrossSpectrum(pSignal1, pSignal2, iItemCount, pMag, pPhase);
  Spectrum (pSignal1, iItemCount);
  Spectrum (pSignal2, iItemCount);
 
  loop through all points (i):
  pResult[i] =  ( pMag[i] * pMag[i] ) / (pSignal1[i] * pSignal2[i]); 
 
Then I started using AutoPowerSpectrum, CrossPowerSpectrum, etc... and couldn't find the right combination.  Has anyone implemented this before?
Thanks,
Marc

Message Edited by BiomedGuy on 07-13-2005 10:29 AM

0 Kudos
Message 1 of 9
(5,545 Views)

Hello Marc,

 

I have not implemented this before. Still, I have a suggestions and a question that will hopefully help.

 

First, from the documentation I could find on coherence, you probably want to use

 

the magnitude returned by CrossPowerSpectrum() for |Gxy( f )|

 

and

 

the autoSpectrum returned by AutoPowerSpectrum() for Gxx ( f ) and Gyy ( f ).

 

Second, should the point by point multiplication in

 

pResult[i] =  ( pMag[i] * pMag[i] ) / (pSignal1[i] * pSignal2[i]); 

 

be a vector product instead? I could be way off the mark with this question.

 

Regards,

 

Eric M

0 Kudos
Message 2 of 9
(5,525 Views)
Hi Marc:

I'm not too familiar with the analysis library, but I have noticed that the function CNiMath::NetworkFunctions can be used to compute a coherence. Perhaps this is what you're looking for.

-- Chris
0 Kudos
Message 3 of 9
(5,510 Views)

Thanks a lot for replying guys.  Eric, I'm not sure if the denominator is a vector product (my theory is a little rusty obviously!) but that might be my problem.  I'm going to try the CNIMath routine suggested by Chris, it looks like what I need. 

Thanks again, I'll let you know how it goes.

Marc

0 Kudos
Message 4 of 9
(5,502 Views)

Good call, Chris. The coherence returned by NetworkFunctions looks like it is exactly what you'll need, Mark.

Have a great weekend!

-Eric

0 Kudos
Message 5 of 9
(5,491 Views)

I have been testing out the NetworkFunctions function.  It seems to be giving me a result of 1 for all frequencies no matter what the input.  I have tried two sinusoids of exactly the same frequency with and without phase shifts, two different sinusoids and two random signals.  I know that without a handle on exactly how my code is organized it dificult to comment, but the function is relatively simple to use and I have debugged all my inputs and outputs to ensure that what I think is there is in fact accurate.   Is there some inherent trait of this function that I may be missing?   Perhaps in the windowing and / or averaging? 

Anything you can think of is much appreciated.  Thanks.

Marc

0 Kudos
Message 6 of 9
(5,479 Views)

The stimulus and response input matrices need to have at least two rows to get non-unity coherence values. This is addressed in the following KnowledgeBase document:

 

Why is the Network Functions (avg) VI's Coherence Function Output "1"?

 

The LabVIEW VI noted in the linked document makes the same DLL calls that the Measurement Studio and LabWindows/CVI NetworkFunctions functions call. The main point of this document is that, "If your input arrays contain only one reading (that is, one row of data each), the coherence function will register unity at all frequencies."

 

Regards,

 

Eric M

0 Kudos
Message 7 of 9
(5,448 Views)
Many thanks to Eric who's note of the KnowledgeBase document:

 

Why is the Network Functions (avg) VI's Coherence Function Output "1"?

 

brought me on the right track! Unfortunately, the described solution (-> the stimulus and response input matrices need to have at least two rows to get non-unity coherence values) doesn't help me much, because I only have one array of stimulus data and one array of response values.
Thus, how can I fullfil the VI-criteria to input at least two rows of data each? Can I simply split both input arrays?

Any hint or idea is very much appreciated. Thanks!

Horst


0 Kudos
Message 8 of 9
(5,401 Views)

Hello Horst,

 

The Network Functions VI has this requirement because the actual function used to calculate coherence requires an average of two or more readings of the stimulus and response signals for a valid result. The FFT-based Network Measurements section of the Developer Zone document linked in the above KnowledgeBase has more on this.

 

You could simply split both input arrays, but I recommend being careful how you split them. Ideally, the stimulus would be split into equal length subsets that contain whole periods of the signal. Then, the response would be split into the corresponding subsets. In other words, if the original stimulus has 4 periods of the signal, you could split it into 2 arrays of 2 periods or 4 arrays of 1 period.

 

Once you do this splitting, the coherence that is calculated by the Network Functions VI will have real meaning.

 

Regards,

 

Eric

0 Kudos
Message 9 of 9
(5,381 Views)