Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
xcorr and corr giving drastically different results

Subject: xcorr and corr giving drastically different results

From: James

Date: 13 Mar, 2012 02:16:13

Message: 1 of 6

I am trying to computer to linear correlation between two timeseries.
xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = -0.41
I don't understand how we could have such different results?! When you look at the two time-series they are clearly anti-correlated. Can somebody explain why we get such results using xcorr?
Figure: http://dl.dropbox.com/u/6156036/corr_plot.jpg

Subject: xcorr and corr giving drastically different results

From: Roger Stafford

Date: 13 Mar, 2012 03:22:12

Message: 2 of 6

"James " <jfaghm@googlemail.com> wrote in message <jjmald$lc$1@newscl01ah.mathworks.com>...
> I am trying to computer to linear correlation between two timeseries.
> xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = -0.41
> I don't understand how we could have such different results?! When you look at the two time-series they are clearly anti-correlated. Can somebody explain why we get such results using xcorr?
> Figure: http://dl.dropbox.com/u/6156036/corr_plot.jpg
- - - - - - - - - -
  Those two functions are computing entirely different kinds of "correlation". The Statistics Toolbox 'corr' function computes the Pearson correlation in which the mean value is subtracted before the product is taken, whereas the Signal Processing Toolbox 'xcorr' does not. If I interpret your curves correctly their values are all well above zero, so that this difference in the functions' definitions has a large effect on the results. For 'xcorr' you would expect a very positive figure and for 'corr', based on the appearance of the curves, a negative value.

  In calculating correlation you need to be aware of how it is defined by the various kinds of "correlation" functions. It has a number of different definitions. It is prudent to always experiment with each one using very short sequences to see if their computations agree with what you think they should be.

Roger Stafford

Subject: xcorr and corr giving drastically different results

From: James

Date: 13 Mar, 2012 03:36:16

Message: 3 of 6

Roger thanks for your response.
How does one interpret the xcorr result then? Is it flat out wrong?
James
"Roger Stafford" wrote in message <jjmeh4$bec$1@newscl01ah.mathworks.com>...
> "James " <jfaghm@googlemail.com> wrote in message <jjmald$lc$1@newscl01ah.mathworks.com>...
> > I am trying to computer to linear correlation between two timeseries.
> > xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = -0.41
> > I don't understand how we could have such different results?! When you look at the two time-series they are clearly anti-correlated. Can somebody explain why we get such results using xcorr?
> > Figure: http://dl.dropbox.com/u/6156036/corr_plot.jpg
> - - - - - - - - - -
> Those two functions are computing entirely different kinds of "correlation". The Statistics Toolbox 'corr' function computes the Pearson correlation in which the mean value is subtracted before the product is taken, whereas the Signal Processing Toolbox 'xcorr' does not. If I interpret your curves correctly their values are all well above zero, so that this difference in the functions' definitions has a large effect on the results. For 'xcorr' you would expect a very positive figure and for 'corr', based on the appearance of the curves, a negative value.
>
> In calculating correlation you need to be aware of how it is defined by the various kinds of "correlation" functions. It has a number of different definitions. It is prudent to always experiment with each one using very short sequences to see if their computations agree with what you think they should be.
>
> Roger Stafford

Subject: xcorr and corr giving drastically different results

From: Roger Stafford

Date: 13 Mar, 2012 04:03:21

Message: 4 of 6

"James " <jfaghm@googlemail.com> wrote in message <jjmfbg$dn4$1@newscl01ah.mathworks.com>...
> How does one interpret the xcorr result then? Is it flat out wrong?
- - - - - - - -
  The computation from 'xcorr' isn't wrong. It has its own special purposes, presumably for people in the signal processing world. Obviously for the purposes you apparently have in mind you should not be using it. As I said, it is very important to understand what a function claims to do and to not do. Functions should not be used blindly on pure faith without carefully reading their documentation, and in fact it isn't a bad idea to check up on the computations directly sometimes, documentation notwithstanding. (In a few instances I have caught Mathworks making statements in their documentation that proved not to be true.)

Roger Stafford

Subject: xcorr and corr giving drastically different results

From: prizeworthy3@gmail.com

Date: 17 Jul, 2013 04:08:18

Message: 5 of 6

2012년 3월 13일 화요일 오전 11시 16분 13초 UTC+9, James 님의 말:
> I am trying to computer to linear correlation between two timeseries.
>
> xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = -0.41
>
> I don't understand how we could have such different results?! When you look at the two time-series they are clearly anti-correlated. Can somebody explain why we get such results using xcorr?
>
> Figure: http://dl.dropbox.com/u/6156036/corr_plot.jpg

Subject: xcorr and corr giving drastically different results

From: ihfw10@gmail.com

Date: 21 Aug, 2013 15:21:23

Message: 6 of 6

Hi, Roger
A related quick question, can't Pearson correlation be used to measure similarity of two signals?
To my understanding, signal subtract mean value means delines the amplitudes of both signals.
Thank you!

-TigerHu
  


On Monday, March 12, 2012 10:22:12 PM UTC-5, Roger Stafford wrote:
> "James " <jfaghm@googlemail.com> wrote in message <jjmald$lc$1@newscl01ah.mathworks.com>...
>
> > I am trying to computer to linear correlation between two timeseries.
>
> > xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = -0.41
>
> > I don't understand how we could have such different results?! When you look at the two time-series they are clearly anti-correlated. Can somebody explain why we get such results using xcorr?
>
> > Figure: http://dl.dropbox.com/u/6156036/corr_plot.jpg
>
> - - - - - - - - - -
>
> Those two functions are computing entirely different kinds of "correlation". The Statistics Toolbox 'corr' function computes the Pearson correlation in which the mean value is subtracted before the product is taken, whereas the Signal Processing Toolbox 'xcorr' does not. If I interpret your curves correctly their values are all well above zero, so that this difference in the functions' definitions has a large effect on the results. For 'xcorr' you would expect a very positive figure and for 'corr', based on the appearance of the curves, a negative value.
>
>
>
> In calculating correlation you need to be aware of how it is defined by the various kinds of "correlation" functions. It has a number of different definitions. It is prudent to always experiment with each one using very short sequences to see if their computations agree with what you think they should be.
>
>
>
> Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us