Coherence Calculation

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View


A rather unusual question...
I am looking for a way to calculate the coherence value of two signals
which are several cycles of a fixed frequency sinusoidal like waveform.
i.e. I need a single value in the range 0-1 for the coherence of the
two waveforms.

I have tried calculating the coherence using the standard formula:
    |Sxy|^2 / (Sxx.Syy)
where Sxy is the Cross Power Spectrum and Sxx and Syy are the AutoPower
Spectrums
and then extracting the value of the single frequency I am interesed in
from the frequency domain response.
But the coherence specturm calcuation using this technique is only
valid with averaged data samples, and I only have *one* set of sampled
data for each waveform, so I always get a result of 1.0 regardless of
the actual coherence between the two waveforms.

Does anyone know of a way to calculate coherence, or a "coherence like"
result for *non-averaged* data that gives a result from 0 to 1 for two
similar sine waves?

Any help appreciated.

Thanks
Dave :)


Re: Coherence Calculation



Quoted text here. Click to load it
No - I always average.

McC



Re: Coherence Calculation



Quoted text here. Click to load it

Using coherence on pure (or close-to-pure) sinusoids is usually a bad
idea -- because, if the sinusoids are of the same frequency (i.e. are
phase or frequency locked), they'll be "completely coherent", and if
they're not they won't be.

Quoted text here. Click to load it

I don't think it's because you only have one set of data, I think it's
because you're only looking at one frequency --- that of the sinusoids
of interest.

Quoted text here. Click to load it

Start back at square one: tell us why you're really interested in the
sine waves! :-)

Do they have a phase-shift between them? -> Use correlation to find it.

Do they have a frequency-shift between them? -> Mix (multiply) them and
look at the beat frequency.

You'll need to supply the background before we can help further, I
think.

Ciao,

Peter K.


Re: Coherence Calculation


Quoted text here. Click to load it

Yes, I am aware it's not the best of ideas, as coherence is usually
done and calculated over a frequency domain with broadband data.

The two waveforms will in practice not be pure sinusoids, but will have
minor noise and distortion components, so in theory a coherence
calculation is possible. In fact, the goal is to have them as
completely coherent as possible (as it is for most systems) i.e. no
noise or distortion is added to the system, and all of the output
signal is due entirely to the input signal.

Quoted text here. Click to load it

No, it's the same over the entire frequency domain. The standard
coherence function as presented relies on averaging. If you have
calculate coherence with no averaging you get a result of 1.0 in every
frequency bin. This is why every dynamic signal analyser will not allow
you to display coherence without turning on averaging.

Quoted text here. Click to load it

For mostly political reasons (don't ask!) I require a "coherence"
number of 0 to 1 to indicate the "quality" of one waveform compared to
a reference.
The standard way to do this is with a coherence function, but in this
case I do not have the averaged data sets available to do this usign
the standard technique.

In the end I may have to compare the signals in the time domain instead
of using the coherence function in the frequency domain. I have a way
to do this to give a 0 to 1 "coherence like" number, but I am wondering
if anyone knows how to do it in the frequency domain using a coherence
function?

I know there are many other ways to compare two waveforms, but I need a
0 to 1 "coherence" indication display.

Dave :)


Re: Coherence Calculation



Quoted text here. Click to load it

OK.


So the outcome you'd like is for the "coherence" to be 1.

Quoted text here. Click to load it

OK. That's a little strange, but perhaps you're right about the
averaging... though I'm not exactly sure what you mean.

Dumb question: why can't you just block the data you have into,
admittedly smaller, datasets so you _can_ use the averaging technique?

That's what matlab does: if I do this:

x = sin(0.090823*[0:1023]+rand(1)*2*pi) + randn(1,1024);
y = sin(0.090823*[0:1023]+rand(1)*2*pi) + randn(1,1024);

and then try

cohere(x,y,1024)

everything is 1, but if I go

cohere(x,y,128)

I don't get the frequency resolution, but I do get something that's 1
around the right frequency and not 1 outside of that.

Bear in mind that this example is very fake: even with random phases,
the freqyencies are effectively "locked".

Quoted text here. Click to load it

OK. Ain't politics a killer? :-)

Quoted text here. Click to load it

Total harmonic distortion (THD)?  That'll start at zero and probably never
get close to 1.  If you need "good" to be close to 1, how about: 1 - THD?

Thanks for taking the time to explain more about the problem.

Let us know if any of this is a help.

Ciao,

Peter K.



Re: Coherence Calculation


Quoted text here. Click to load it

Yep. That is the desired outcome for any measurement system, which is
why coherence measurement is of such importance, especially in the
vibration and acoustics systems I am involved with.

Quoted text here. Click to load it

Unfortunately I don't have the necessary math skills to explain it, but
the coherence function is inherently meaningless if you don't do it
over averaged data. Your Matlab example below shows that the result is
1 for all frequency bins, and that is exactly my problem too.
If you are interested, this might explain it a little better:
http://www.educatorscorner.com/media/Exp96.pdf

Quoted text here. Click to load it

Yes, I thought about this, but I don't think I have sufficent data to
do this.
I'm already getting 10Hz frequency bins on the output of my FFT power
spectrum functions, and the signal I want to measure is 40Hz. Not
exactly crash-hot resolution :-(
Also, I might only have several cylces in total to work with (it is
user selected in software). In fact, in some cases I might only have 1
cycle to work with, so my coherence calculation function might have to
handle that eventuality too.

Quoted text here. Click to load it

The #1 killer of every cool project!

Quoted text here. Click to load it

Gave that a brief thought, but I suspect it may be be a bit "touchy"
and not robust enough. I would actually need a THD "envelope" pass/fail
band as my two signals may (or may not) have significant THD, but have
still perfect coherence.
Not sure how you would scale that to a 0-1 result either...

In any case, I've already got a time domain analysis method in mind
that will work, based on scaled means and error difference between the
two waveforms. I just have to go through the motions to eliminate the
possibility of any other frequency domain coherence method.

Quoted text here. Click to load it

Thanks for your help Peter. It is good to know that Matlab gives the
same result I am getting in my LabWindows/CVI software.

Regards
Dave :)


Re: Coherence Calculation


Quoted text here. Click to load it

Hi David,

It seems that it is unecessary to go to the frequency domain for this
problem,  since all you want to do compare time-domain images of short
duration.  As you probably discovered, you get impulses in the
frequency domain for signals of low spectral variance.

One way to calculate the "coherence" in the time domain for
short-duration signals is:

1.  take the time-domain samples of two signals and treat them as
vectors in N-space.
2. Normalize each vector so as to kill any power advantage that one
might have over the other.   They will retain their positive and
negative components.
3. Take the scalar product between X & Y to yield a value from -1 to
+1.
4. Shift the scalar product +1 to get value between 0 and 2.
5. Divide result by 2 to get value between 0 and 1.

If you prefer, you can avoid steps 4 and 5, so you could end up with
confidences of
+1 = strongly correlated
0 neutral
-1 strongly uncorrelated

Naturally, the hills and valeys will dominate the output of the
correlation if you use this, so if you are really interested in
phase/magnitude correlation, you can do something similar:

1. Normalize both signals (before or after DFT - after relieves any
cofactor fuzzies in FT)
2. Take DFT
3. Treating phase and magnitude separately, take scalar products to
yield -1 < x > +1.

But again, for signals that are both in phase with same spectral
content, you should not be surprised to  get something very close to 1
on both accounts, as the frequency domain will contain weak noise
dominated by impulses convolved with sin(x)/x.

-Le Chaud Lapin-


Re: Coherence Calculation


Quoted text here. Click to load it

In Matlab

coh=rand;

;)
Quoted text here. Click to load it

Re: Coherence Calculation



Stan Pawlukiewicz wrote:


Quoted text here. Click to load it

:-)

Ciao,

Peter K.


Re: Coherence Calculation


Quoted text here. Click to load it

In Labwindows/CVI:
coherence=Random(0.8,1.0);

Tempting, very tempting! ;-)

The stupid thing is, I could most likely get away with it, having just
shifted our managerial focus to being "results driven"!

Dave :)


Re: Coherence Calculation



Quoted text here. Click to load it

You poor b*st*rd! :-)

Ciao,

Peter K.


Re: Coherence Calculation


Quoted text here. Click to load it

It's ok, it'll change again next month, regular as clockwork!

Dave :)


Re: Coherence Calculation


Quoted text here. Click to load it

Have you looked at one of the Bendat and Piersol books, like Random
Data? Most of the stuff they do is vibration analysis and I do recall
they cover coherence in some detail.

Re: Coherence Calculation




David L. Jones wrote:
Quoted text here. Click to load it

Try Average Cross-Correlation
    R12(t) = (Integration sign from -infinity to +infinity)
v1(t)*v2(t)*(T+t)dt
This is for non-peiodic waveforms.
reference: Principles of Communication Systems - Taub+Schilling

Alan


Re: Coherence Calculation


Quoted text here. Click to load it

Thanks Alan.
My waveform will however be periodic, several full cycles of fixed
frequency data.
So probably not suitable?

Dave :)


Site Timeline