cross-correlation of two signal always shows unexpected 0 lag

37 views (last 30 days)
Hi,everyone, I got a very strange issue.
b is a signal of 251 samples. c is got by shifting b by 5 sample. (b and c are attached).
Image 5.png
But when I do xcorr on b and c, the max correlation always occurs at 0 lag. which I do not understand. Can someone help?
Below is my code. Thank you.
load b.mat
load c.mat
plot(b);hold on;
[r,lag] = xcorr(b,c,'coeff');
[m, i_max]=max(r);
% plot(lag,r);

Accepted Answer

Honglei Chen
Honglei Chen on 20 Nov 2018
You may want to try
[r,lag] = xcorr(b-mean(b),c-mean(c),'coeff');
Honglei Chen
Honglei Chen on 20 Nov 2018
Since your goal is to look for similarity between two signals, I think in theory the cross correlation really requires both signal to be zero mean. Otherwise, the DC component will affect your result. For example, let's say two signals are uncorrelated and have all positive values. In theory, the correlation coefficient should be 0. However, without removing the means, the result will always be positive.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!