Coherence Calculation
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
Coherence Calculation
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP
Author Message
David L. Jones
Guest





Posted: Wed Nov 30, 2005 9:16 am    Post subject: Coherence Calculation Reply with quote

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 :)
Back to top
Real_McCoy
Guest





Posted: Wed Nov 30, 2005 9:16 am    Post subject: Re: Coherence Calculation Reply with quote

"David L. Jones" <altzone@gmail.com> wrote in message
news:1133322147.878771.305150@z14g2000cwz.googlegroups.com...
Quote:
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 :)

No - I always average.


McC
Back to top
David L. Jones
Guest





Posted: Wed Nov 30, 2005 9:16 am    Post subject: Re: Coherence Calculation Reply with quote

Peter K. wrote:
Quote:
David L. Jones wrote:

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.

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.

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.

Quote:
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.

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.

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.

Quote:
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?

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

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 :)
Back to top
Peter K.
Guest





Posted: Wed Nov 30, 2005 9:16 am    Post subject: Re: Coherence Calculation Reply with quote

David L. Jones wrote:

Quote:
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.

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.

Quote:
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.

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.

Quote:
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?

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.
Back to top
Alan Peake
Guest





Posted: Wed Nov 30, 2005 9:16 am    Post subject: Re: Coherence Calculation Reply with quote

David L. Jones wrote:
Quote:
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.

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
Back to top
David L. Jones
Guest





Posted: Wed Nov 30, 2005 9:16 am    Post subject: Re: Coherence Calculation Reply with quote

Alan Peake wrote:
Quote:
David L. Jones wrote:
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.

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

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

Dave :)
Back to top
Stan Pawlukiewicz
Guest





Posted: Wed Nov 30, 2005 5:16 pm    Post subject: Re: Coherence Calculation Reply with quote

David L. Jones wrote:
Quote:
Peter K. wrote:

David L. Jones wrote:


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.

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.


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.


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.

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.


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.


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?

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


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.

In Matlab

coh=rand;

;)
Quote:

Dave :)
Back to top
Peter K.
Guest





Posted: Wed Nov 30, 2005 5:17 pm    Post subject: Re: Coherence Calculation Reply with quote

"David L. Jones" <altzone@gmail.com> writes:

Quote:
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.

OK.

Quote:
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.

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

Quote:
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.

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.

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".

Quote:
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.

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

Quote:
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.

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.
Back to top
Vladimir Vassilevsky
Guest





Posted: Wed Nov 30, 2005 11:16 pm    Post subject: Re: Coherence Calculation Reply with quote

David L. Jones wrote:

Quote:
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.

To get the reasonable answer, please clarify what exactly are you trying
to accomplish. What is the task and what is your goal?

Vladimir Vassilevsky

DSP and Mixed Signal Design Consultant

http://www.abvolt.com
Back to top
Peter K.
Guest





Posted: Thu Dec 01, 2005 12:31 am    Post subject: Re: Coherence Calculation Reply with quote

Stan Pawlukiewicz wrote:


Quote:
In Matlab

coh=rand;

;)

:-)

Ciao,

Peter K.
Back to top
Peter K.
Guest





Posted: Thu Dec 01, 2005 1:16 am    Post subject: Re: Coherence Calculation Reply with quote

"David L. Jones" <altzone@gmail.com> writes:

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

You poor b*st*rd! :-)

Ciao,

Peter K.
Back to top
David L. Jones
Guest





Posted: Thu Dec 01, 2005 1:16 am    Post subject: Re: Coherence Calculation Reply with quote

Stan Pawlukiewicz wrote:
Quote:
David L. Jones wrote:
Peter K. wrote:

David L. Jones wrote:


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.

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.


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.


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.

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.


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.


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?

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


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.

In Matlab

coh=rand;

;)

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 :)
Back to top
David L. Jones
Guest





Posted: Thu Dec 01, 2005 1:17 am    Post subject: Re: Coherence Calculation Reply with quote

Peter K. wrote:
Quote:
"David L. Jones" <altzone@gmail.com> writes:

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.

OK.

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.

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

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.

Quote:
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.

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.

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

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

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

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.

Quote:
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".

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.

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

The #1 killer of every cool project!

Quote:
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.

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?

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.

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

Let us know if any of this is a help.

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 :)
Back to top
David L. Jones
Guest





Posted: Thu Dec 01, 2005 7:23 am    Post subject: Re: Coherence Calculation Reply with quote

Peter K. wrote:
Quote:
"David L. Jones" <altzone@gmail.com> writes:

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

You poor b*st*rd! :-)

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

Dave :)
Back to top
Le Chaud Lapin
Guest





Posted: Thu Dec 01, 2005 9:16 am    Post subject: Re: Coherence Calculation Reply with quote

David L. Jones wrote:
Quote:
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.

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-
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB