LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem to calculate the coherence (using NetworkFunction-VI) with only 1 row of data for each, the stimulus and response input

Hello,

I am trying to calculate the coherence of a stimulus and response signal using the Network Functions (avg) VI's. The problem is that I always get a coherence of "1" at all frequencies. This problem is already known (see KnowledgeBase document: Why is the Network Functions (avg) VI's Coherence Function Output "1"?).
My trouble is that 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 'coherence-criteria' to input at least two rows of data each when I just have one row of data each?

Any hint or idea is very much appreciated. Thanks!

Horst




0 Kudos
Message 1 of 6
(3,359 Views)
Here are some notes from a VI I wrote in LabVIEW 3, many years ago. The math has been verified by a PhD, and field tested. Back then we did not have express VIs, so I had to do the math myself, but it's more efficient that way (because some cases do not need phase information, so I didn't calculate it).

It definitely works on a single recording (of stimulus + response), though they typically use it for averaged signals.




F(x) F*(x) |F(x)|^2
Sxx = ------ * ------- = ---------- (no phase information)
N N N^2


F(y) F*(x)
Sxy = ------ * -------
N N

Cross power spectrum Sxy
Transfer function = ------------------------ = -----
Power spectrum Sxx

| Sxy | ^2
Coherence = -------------
Sxx * Syy


where:
F(x) is the complex Fourier transform of the time domain signal x, and
F*(x) is the complex conjugate of the Fourier transform of x, and
N is the number of points in x.

Note that SXX is the magnitude squared. It is faster to compute the square of the magnitude than it is to compute the magnitude. Although the complex-to-polar VI would look simpler on the diagram, it would take longer since it computes the magnitude proper, (an extra square-root operation), and it computes the angle (extra arc-tangent operations).

Since N^2 is a term in both Sxy and Sxx, and since we are dividing one by the other, we do not need to explicitly divide by N^2; it is cancelled automatically.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 2 of 6
(3,353 Views)
Thanks for your reply! My theoretical background about this topic is a bit 'rusty' but your solution sounds promising! Thanks again!

Horst
0 Kudos
Message 3 of 6
(3,346 Views)

Hi,

In this case did you manage to calculate the coherence using the power/cross power spectrum vi blocks?

 

0 Kudos
Message 4 of 6
(3,333 Views)
With this weird board layout, I'm not sure whether you were asking me, but, on the assumption that you were, here goes:

I found no need to use the cross-power spectrum and power spectrum blocks
1... I was looking for speed.
2... I already had the component spectral data there, for other purposes. From that, it's nothing but addition and multiplication.
3... The "easy" VIs, assume a time wave input, as I recall. Which means they would take the same spectrum of the same timewave several times, where I only do it once.


I have attached PNGs of my code.
The PROCESS CHANNEL vi accepts the time wave and:
1... Removes DC value.
2... Integrates (optional, used for certain sensors).
3... Windows (Hanning, etc. - optional)
4... Finds spectrum.
5... Removes spectral mirrors.
6... Scales into Eng. units.
7... From there, you COULD use COMPLEX-TO-POLAR, but I don't care about the phase data, and I need the MAG^2 data anyway, so I rolled my own COMPLEX-TO-MAG code.

The above is done on each channel. The PROCESS DATA vi calls the above with data for each channel. The 1st channel in the list is required to be the reference (stimulus) channel.

After looping over each channel, we have the Sxx, Syy, and Sxy terms. This code contains some averaging and peak-picking stuff that's not relevant.

From there, it's straightforward to ger XFER = Sxy/Sxx and COHERENCE = |Sxy|^2 / (Sxx * Syy)

Note that it uses the MAGNITUDE SQUARED of Sxy. Again, if you use the "easy" stuff, it will do a square-root operation that you just have to reverse - it is obtained faster by the sum of the squares of the real and imag parts.

Hope this helps.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 5 of 6
(3,328 Views)
Here's the other PNG.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 6 of 6
(3,327 Views)