Why does the XCORR function from the Signal Processing Toolbox 6.11 (R2009a) not output a value of 1 for perfect correlation?

조회 수: 2 (최근 30일)
Why does the XCORR function from the Signal Processing Toolbox not output a value of 1 for perfect correlation?
The following code exemplifies the problem:
x=0:0.01:10;
X = sin(x);
Y = sin(x+pi/2);
[r,lags]=xcorr(X,Y,'coeff');
max(r)
ans =
0.8090

채택된 답변

MathWorks Support Team
MathWorks Support Team 2022년 2월 22일
편집: MathWorks Support Team 2022년 2월 22일
This change has been incorporated into the documentation in Release 2009b (R2009b). For previous releases, read below for any additional information:
XCORR will produce correlations identically equal to 1.0 at zero lag only when performing an auto-correlation and only when the 'coeff' flag is passed to XCORR. For example:
x=0:0.01:10; \nX = sin(x);\n[r,lags]=xcorr(X,'coeff'); \nmax(r)
ans =\n\n 1
When performing a cross-correlation, XCORR will behave as outlined in the documentation located at the following URL:
For example:
x=0:0.01:10; \nX = sin(x);\nY = sin(x+pi/2);\n[r,lags]=xcorr(X,Y);\nmax(r)
ans =\n\n 404.4763
% biased - scales the raw cross-correlation by 1/M.\n[rb,lagsb]=xcorr(X,Y,'biased'); \nmax(rb)
ans =\n\n 0.4041
% Now, if you take the raw correlation and scale it by 1/M, where M is the length of the signal, \n% you get the biased cross-correlation.\nM = length(X);\nmax(r./M)
ans =\n\n 0.4041
%unbiased - scales the raw correlation by 1/(M-abs(k)), where k \n%is the index into the result.\n[ru,lagsu]=xcorr(X,Y,'unbiased');\nmax(ru)
ans =\n\n 0.5441
% Now, if you take the raw correlation and scale it by 1/(M - abs(lags))\n% you get the unbiased cross-correlation. \nk = lags;\nmax(r./(M-abs(k)))
ans =\n\n 0.5441
For more information, see the following references:
[1] J.S. Bendat and A.G. Piersol, "Random Data: Analysis and Measurement Procedures", John Wiley and Sons, 1971, p.332.
[2] A.V. Oppenheim and R.W. Schafer, Digital Signal Processing, Prentice-Hall, 1975, pg 539.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2009a

Community Treasure Hunt

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

Start Hunting!

Translated by