http://www.mathworks.com/matlabcentral/newsreader/view_thread/317900
MATLAB Central Newsreader  xcorr and corr giving drastically different results
Feed for thread: xcorr and corr giving drastically different results
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Tue, 13 Mar 2012 02:16:13 +0000
xcorr and corr giving drastically different results
http://www.mathworks.com/matlabcentral/newsreader/view_thread/317900#869758
James
I am trying to computer to linear correlation between two timeseries.<br>
xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = 0.41<br>
I don't understand how we could have such different results?! When you look at the two timeseries they are clearly anticorrelated. Can somebody explain why we get such results using xcorr?<br>
Figure: <a href="http://dl.dropbox.com/u/6156036/corr_plot.jpg">http://dl.dropbox.com/u/6156036/corr_plot.jpg</a>

Tue, 13 Mar 2012 03:22:12 +0000
Re: xcorr and corr giving drastically different results
http://www.mathworks.com/matlabcentral/newsreader/view_thread/317900#869764
Roger Stafford
"James " <jfaghm@googlemail.com> wrote in message <jjmald$lc$1@newscl01ah.mathworks.com>...<br>
> I am trying to computer to linear correlation between two timeseries.<br>
> xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = 0.41<br>
> I don't understand how we could have such different results?! When you look at the two timeseries they are clearly anticorrelated. Can somebody explain why we get such results using xcorr?<br>
> Figure: <a href="http://dl.dropbox.com/u/6156036/corr_plot.jpg">http://dl.dropbox.com/u/6156036/corr_plot.jpg</a><br>
         <br>
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.<br>
<br>
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.<br>
<br>
Roger Stafford

Tue, 13 Mar 2012 03:36:16 +0000
Re: xcorr and corr giving drastically different results
http://www.mathworks.com/matlabcentral/newsreader/view_thread/317900#869765
James
Roger thanks for your response.<br>
How does one interpret the xcorr result then? Is it flat out wrong?<br>
James<br>
"Roger Stafford" wrote in message <jjmeh4$bec$1@newscl01ah.mathworks.com>...<br>
> "James " <jfaghm@googlemail.com> wrote in message <jjmald$lc$1@newscl01ah.mathworks.com>...<br>
> > I am trying to computer to linear correlation between two timeseries.<br>
> > xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = 0.41<br>
> > I don't understand how we could have such different results?! When you look at the two timeseries they are clearly anticorrelated. Can somebody explain why we get such results using xcorr?<br>
> > Figure: <a href="http://dl.dropbox.com/u/6156036/corr_plot.jpg">http://dl.dropbox.com/u/6156036/corr_plot.jpg</a><br>
>          <br>
> 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.<br>
> <br>
> 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.<br>
> <br>
> Roger Stafford

Tue, 13 Mar 2012 04:03:21 +0000
Re: xcorr and corr giving drastically different results
http://www.mathworks.com/matlabcentral/newsreader/view_thread/317900#869766
Roger Stafford
"James " <jfaghm@googlemail.com> wrote in message <jjmfbg$dn4$1@newscl01ah.mathworks.com>...<br>
> How does one interpret the xcorr result then? Is it flat out wrong?<br>
       <br>
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.)<br>
<br>
Roger Stafford

Wed, 17 Jul 2013 04:08:18 +0000
Re: xcorr and corr giving drastically different results
http://www.mathworks.com/matlabcentral/newsreader/view_thread/317900#908249
prizeworthy3@gmail.com
2012년 3월 13일 화요일 오전 11시 16분 13초 UTC+9, James 님의 말:<br>
> I am trying to computer to linear correlation between two timeseries.<br>
> <br>
> xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = 0.41<br>
> <br>
> I don't understand how we could have such different results?! When you look at the two timeseries they are clearly anticorrelated. Can somebody explain why we get such results using xcorr?<br>
> <br>
> Figure: <a href="http://dl.dropbox.com/u/6156036/corr_plot.jpg">http://dl.dropbox.com/u/6156036/corr_plot.jpg</a>

Wed, 21 Aug 2013 15:21:23 +0000
Re: xcorr and corr giving drastically different results
http://www.mathworks.com/matlabcentral/newsreader/view_thread/317900#910057
ihfw10@gmail.com
Hi, Roger<br>
A related quick question, can't Pearson correlation be used to measure similarity of two signals?<br>
To my understanding, signal subtract mean value means delines the amplitudes of both signals.<br>
Thank you!<br>
<br>
TigerHu<br>
<br>
<br>
<br>
On Monday, March 12, 2012 10:22:12 PM UTC5, Roger Stafford wrote:<br>
> "James " <jfaghm@googlemail.com> wrote in message <jjmald$lc$1@newscl01ah.mathworks.com>...<br>
> <br>
> > I am trying to computer to linear correlation between two timeseries.<br>
> <br>
> > xcorr(X,Y,0,'coeff) = 0.9056; corr(X,Y) = 0.41<br>
> <br>
> > I don't understand how we could have such different results?! When you look at the two timeseries they are clearly anticorrelated. Can somebody explain why we get such results using xcorr?<br>
> <br>
> > Figure: <a href="http://dl.dropbox.com/u/6156036/corr_plot.jpg">http://dl.dropbox.com/u/6156036/corr_plot.jpg</a><br>
> <br>
>          <br>
> <br>
> 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.<br>
> <br>
> <br>
> <br>
> 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.<br>
> <br>
> <br>
> <br>
> Roger Stafford