Cross Correlation - resulting vector not normalized properly? Help!

16 次查看(过去 30 天)
I am performing a cross correlation between two vectors (both functions of time). My goal is to obtain a resulting vector dependent on the time shift, that shows the correlation between the original two vectors (with the max value of the related vector as 1, minimum value of -1)
None of the options in xcorr are giving me this. The normalization options 'bias' and 'unbias' provide me with values not constrained to -1 < y < 1, and 'coeff' automatically assigns the most correlated time shift a value of 1. This isn't very helpful when I am trying to compare correlated vectors of many different inputs.
Does MatLab have a way to cross-correlate in the way I'm looking for?
Thanks!
  2 个评论
Walter Roberson
Walter Roberson 2011-11-30
I see from the status that you edited the question, Pocho, but I do not see any difference between your current wording and your previous wording?
Pocho
Pocho 2011-11-30
I was trying to emphasize that I'm wondering if the community knows of a function in Matlab that is more suitable to what I'm looking for, since xcorr doesn't seem to be producing a "universal" normalized vector (i.e., sometimes a vector produced from the correlation will have a maximum value of 0.2, but no matter what the process will not produce a value greater than 1)

请先登录,再进行评论。

回答(2 个)

Wayne King
Wayne King 2011-11-29
The 'coeff' option only produces a value of 1 or -1 if a given time shift (lag) results in a perfect positive or negative correlation of two series.
It does not normalize on the maximum cross correlation value as you suggest. It does not assign the maximum cross correlation value 1. For example:
rng default;
x = randn(10,1);
y = randn(10,1);
[c,lags] = xcorr(x,y,'coeff');
max(abs(c))
On the other hand, create two sine waves where y is a delayed version of x (delayed by two samples).
n = 0:100;
x = cos(pi/4*n);
y = cos(pi/4*n-pi/2);
[c,lags] = xcorr(y,x,20,'coeff');
stem(lags(21:end),c(21:end));
Now the maximum is very close to 1 and occurs at lag 2 as expected.
Accordingly, if you obtain a cross correlation value of 1 with the 'coeff' option, that indicates that the two series are perfectly correlated at a given lag.

Pocho
Pocho 2011-11-30
What if two data sets are not perfectly correlated? Could I obtain the maximum be close to 0, for a given lag?
  2 个评论
Pocho
Pocho 2011-11-30
For some reason, 'coeff' produces a vector that always results in a triangular shape..I'm doubting this for some reason. Do you know of any references that can help me understand the statistical reasoning behind this?

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by