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:
difference between xcorr and crosscorr?

Subject: difference between xcorr and crosscorr?

From: Iris Ehlert

Date: 4 Feb, 2012 13:22:17

Message: 1 of 7

Dear members of mathworks,

I did a cross correlation for two time series both with xcorr.m and crosscorr.m. The results are completely different, which definitely shouldn't be the case, since the documentation for both functions describe the same.

So I would really, really appreciate it, if you could tell me why this happens.

I used the same lags, same series - so it is really the function itself causing the different results.

Cheers,
ie.

Subject: difference between xcorr and crosscorr?

From: ImageAnalyst

Date: 4 Feb, 2012 14:17:17

Message: 2 of 7

I don't see crosscorr() - is that in some particular toolbox? Where
did you get it?

Subject: difference between xcorr and crosscorr?

From: Steven_Lord

Date: 7 Feb, 2012 14:42:34

Message: 3 of 7



"ImageAnalyst" <imageanalyst@mailinator.com> wrote in message
news:e40817cd-e78d-4206-a604-74277c423f74@h3g2000yqe.googlegroups.com...
> I don't see crosscorr() - is that in some particular toolbox? Where
> did you get it?

It's in Econometrics Toolbox.

http://www.mathworks.com/help/toolbox/econ/crosscorr.html

while XCORR is in Signal Processing Toolbox.

http://www.mathworks.com/help/toolbox/signal/ref/xcorr.html

One difference I see between them at first glance is what they return and
what options they allow. Signal Processing Toolbox just returns the
correlations and lags while allowing the user to specify a normalization
method, while Econometrics Toolbox returns correlations, lags, and
confidence bounds but does not allow the user to specify a normalization
method.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: difference between xcorr and crosscorr?

From: Aino

Date: 17 Oct, 2012 16:07:16

Message: 4 of 7

"Steven_Lord" <slord@mathworks.com> wrote in message <jgrd8p$q21$1@newscl01ah.mathworks.com>...
>
>
> "ImageAnalyst" <imageanalyst@mailinator.com> wrote in message
> news:e40817cd-e78d-4206-a604-74277c423f74@h3g2000yqe.googlegroups.com...
> > I don't see crosscorr() - is that in some particular toolbox? Where
> > did you get it?
>
> It's in Econometrics Toolbox.
>
> http://www.mathworks.com/help/toolbox/econ/crosscorr.html
>
> while XCORR is in Signal Processing Toolbox.
>
> http://www.mathworks.com/help/toolbox/signal/ref/xcorr.html
>
> One difference I see between them at first glance is what they return and
> what options they allow. Signal Processing Toolbox just returns the
> correlations and lags while allowing the user to specify a normalization
> method, while Econometrics Toolbox returns correlations, lags, and
> confidence bounds but does not allow the user to specify a normalization
> method.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Hi all!

I have the same problem.. Apparently if you subtract the mean out of the input vectors, both the functions give the same result. Also if you don't normalize the results (if you comment row 190 in crosscorr), there will still be a difference between the results.

So which one is the correct one?

-Aino

Subject: difference between xcorr and crosscorr?

From: Rick

Date: 18 Oct, 2012 15:55:12

Message: 5 of 7

Iris,

The distinction between the 2 functions is likely due to the intended audience.

The CROSSCORR in the Econometrics Toolbox is designed for financial/economic users, wherein the standard approach is to remove the mean from each series. For example, see Box and Jenkins. (In fact, the usual way to compute the sample variance of any series is to first extract the mean.)

In economic applications, the usual approach is also to normalize by the product of the sample standard deviations of each series x(t) and y(t).

For a sample auto-correlation function (ACF), as computed by the Econometrics Toolbox function AUTOCORR, this has the added effect of producing an ACF whose value at lag zero is unity, since x(t) = y(t).

However, for CROSSCORR, the scaling does not ensure the XCF at lag zero is one.

Also, as mentioned in another response, for two series x and y, XCORR and CROSSCORR will compute the same XCF function for N lags (to within numerical precision) for calls like this:

c = xcorr(x - mean(x), y - mean(y), N, 'coeff');
C = crosscorr(y, x, N);

As far as which is correct, they're both correct ... it just depends on what you want.

HTH,
-Rick

"Iris Ehlert" wrote in message <jgjbe9$biq$1@newscl01ah.mathworks.com>...
> Dear members of mathworks,
>
> I did a cross correlation for two time series both with xcorr.m and crosscorr.m. The results are completely different, which definitely shouldn't be the case, since the documentation for both functions describe the same.
>
> So I would really, really appreciate it, if you could tell me why this happens.
>
> I used the same lags, same series - so it is really the function itself causing the different results.
>
> Cheers,
> ie.

Subject: difference between xcorr and crosscorr?

From: Ye Gao

Date: 28 Nov, 2012 03:45:19

Message: 6 of 7

"Iris Ehlert" wrote in message <jgjbe9$biq$1@newscl01ah.mathworks.com>...
> Dear members of mathworks,
>
> I did a cross correlation for two time series both with xcorr.m and crosscorr.m. The results are completely different, which definitely shouldn't be the case, since the documentation for both functions describe the same.
>
> So I would really, really appreciate it, if you could tell me why this happens.
>
> I used the same lags, same series - so it is really the function itself causing the different results.
>
> Cheers,
> ie.

Other than the superficial difference that "crosscorr" is in the econometric toolbox and "xcorr" is in the signal processing toolbox, I find that there are two important distinctions between "crosscorr" and "xcor".
1. Means are removed from input series for "crosscorr", but not for "xor".
2. For "crosscorr", the 1st input leads the 2nd input, while for "xcross" the 1st input lags the 2nd input.

Cheers,
Ye Gao

Subject: difference between xcorr and crosscorr?

From: Greg Heath

Date: 29 Nov, 2012 18:43:15

Message: 7 of 7

"Iris Ehlert" wrote in message <jgjbe9$biq$1@newscl01ah.mathworks.com>...
> Dear members of mathworks,
>
> I did a cross correlation for two time series both with xcorr.m and crosscorr.m. The results are completely different, which definitely shouldn't be the case, since the documentation for both functions describe the same.
>
> So I would really, really appreciate it, if you could tell me why this happens.
>
> I used the same lags, same series - so it is really the function itself causing the different results.
>
> Cheers,
> ie.

If you standardize the inputs using ZSCORE or MAPSTD, you should get the same answer. I think that answer is consistent with an autocorrelation with unity amplitude at zero lag if the input functions are equal.

Hope this helps.

Greg

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