필터 지우기
필터 지우기

Value of cross correlation in matlab?

조회 수: 62 (최근 30일)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 1월 6일
편집: Adam Danz 2023년 1월 10일
The cross correlation function xcorr in matlab provides the lag between two signals. But, Is there any matlab function that calculates the cross correlation between 2 signals and outputs a sigle value i.e < =1?

채택된 답변

Adam Danz
Adam Danz 2023년 1월 6일
편집: Adam Danz 2023년 1월 10일
You could compute the cross correlation at 0 lag using r = xcorr(___,scaleopt) where scaleopt can be set to a normalization option.
If you're looking for the cross correlation coefficient, use R = corrcoef(A,B)
Demo:
sig1 = 1./(1+exp(-5:5));
sig2 = 1./(1+exp(-6:4));
plot(sig1);
hold on
plot(sig2);
rm = corrcoef(sig1, sig2); % Column vectors
r2 = rm(2)
r2 = 0.9785
r1 = xcorr(sig1, sig2, 0)
r1 = 4.9234
r1norm = xcorr(sig1, sig2, 0, 'normalized')
r1norm = 0.9885
The difference is that corrcoef subtracts the mean from each vector and then normalizes the vectors to be unit vectors whereas xcorr with 'normalized' only normalizes but does not subtract the mean.
r1centered = xcorr(sig1-mean(sig1), sig2-mean(sig2), 0, 'normalized')
r1centered = 0.9785
  댓글 수: 3
Image Analyst
Image Analyst 2023년 1월 7일
Try using interp1 or spline to resample one of your signals so that it has the same number of samples as the other signal.
Adam Danz
Adam Danz 2023년 1월 7일
편집: Adam Danz 2023년 1월 10일
The only xcorr option that supports vectors of unequal length is xcorr(sig1, sig2, 0,'none') where 'none' is the default scale option so it's the same as xcorr(sig1, sig2, 0). But if you'd like to include normalization, either follow Image Analyst's advice above (interpolate the shorter vector) or trim the longer vector. Those are two very different comparisons. Interpolation resamples one of the vectors to match the length of the other vector. It's like stretching or compressing. Trimming assumes that the two signals have the same sampling interval but more data was collected in one of the signals.

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

추가 답변 (0개)

카테고리

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