Cross Correlation - resulting vector not normalized properly? Help!

조회 수: 16 (최근 30일)
Pocho
Pocho 2011년 11월 29일
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
Wayne King
Wayne King 2011년 11월 30일
yes, you could.
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by