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 4

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 4

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

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 4

"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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
xcorr James 12 Mar, 2012 22:19:23
corr James 12 Mar, 2012 22:19:23
crosscorrealtion James 12 Mar, 2012 22:19:23
rssFeed for this Thread

Contact us