Thread Subject: Difference between corrcoef and xcorr

Subject: Difference between corrcoef and xcorr

From: silvia_benetti@web.de B.

Date: 2 Sep, 2009 12:05:21

Message: 1 of 3

Hallo,
I am analysing data series for my master thesis.
I need to calculate the autocorrelation coefficient for a time series, but I get different results using xcorr and corrcoef. Can someone tell me that difference between these two algorithms? I read old threads on this topic, but didn't understand much.

Thanks in advance,

Silvia

Subject: Difference between corrcoef and xcorr

From: Evan Ruzanski

Date: 25 Nov, 2009 01:13:18

Message: 2 of 3

Hi Silvia,

'corrcoef' subtracts the mean value of each vector considered in the cross-correlation computation and 'xcorr' does not. Using the 'coeff' option with xcorr only scales the correlation values computed using xcorr.m but doesn't subtract the mean value. In statistical terms, corrcoef detrends the data before performing the correlation computation.

As you probably have already seen, there can be huge difference between the output these 2 approaches. If you subtract the mean from each vector before using xcorr, you will get the same (zero-lag) result as corrcoef:

>> test1

test1 =

     1 2 4

>> test2

test2 =

     9 1 1

>> xc1 = xcorr(test1,test2,'coeff')

xc1 =

    0.0240 0.0719 0.3593 0.5270 0.8623

>> test3 = test1 - mean(test1)

test3 =

   -1.3333 -0.3333 1.6667

>> test4 = test2 - mean(test2)

test4 =

    5.3333 -2.6667 -2.6667

>> xc2 = xcorr(test3,test4,'coeff')

xc2 =

    0.2520 0.3150 -0.7559 -0.4410 0.6299

>> xc3 = corrcoef(test1,test2)

xc3 =

    1.0000 -0.7559
   -0.7559 1.0000

>>

Hope this helps, good luck on your thesis...
Evan

"silvia_benetti@web.de B." <silvia_benetti@web.de> wrote in message <h7ln21$pnk$1@fred.mathworks.com>...
> Hallo,
> I am analysing data series for my master thesis.
> I need to calculate the autocorrelation coefficient for a time series, but I get different results using xcorr and corrcoef. Can someone tell me that difference between these two algorithms? I read old threads on this topic, but didn't understand much.
>
> Thanks in advance,
>
> Silvia

Subject: Difference between corrcoef and xcorr

From: Evan Ruzanski

Date: 25 Nov, 2009 02:05:23

Message: 3 of 3

Hello again,

Just wanted to add to my last post that:

xcov(test1,test2,'coeff')

also gives the same result as:

xcorr(test1 - mean(test1),test2 - mean(test2),'coeff').

ER

"silvia_benetti@web.de B." <silvia_benetti@web.de> wrote in message <h7ln21$pnk$1@fred.mathworks.com>...
> Hallo,
> I am analysing data series for my master thesis.
> I need to calculate the autocorrelation coefficient for a time series, but I get different results using xcorr and corrcoef. Can someone tell me that difference between these two algorithms? I read old threads on this topic, but didn't understand much.
>
> Thanks in advance,
>
> Silvia

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
corrcoef Sprinceana 10 Sep, 2009 11:25:01
xcorr Sprinceana 10 Sep, 2009 11:25:01
reference Sprinceana 10 Sep, 2009 11:25:01
rssFeed for this Thread

Contact us at files@mathworks.com