How to align two signals using xcorr function?

2 次查看(过去 30 天)
Hello,
I need to align two signals presented below:
I use xcorr function:
[acor,lag] = xcorr(PROFILE2,PROFILE1);
[~,I] = max(abs(acor));
lagDiff = lag(I)
I don't know why but lagDiff value is 0.
Could anyone help me?
Arletta

回答(1 个)

Image Analyst
Image Analyst 2017-4-26
Since the bottom plot will never equal the top plot, unless it's circularly shifted, you might have to replicate the second signal 3 times
PROFILE1 = [PROFILE1, PROFILE1, PROFILE1];
Then try correlating. Be aware that finding the max value in the correlation signal just finds where the sum of the products of the signals is max. This does not necessarily happen when you think the signals are aligned, as a little thought will reveal to you. As an extreme example, what it the first 5 values of PROFILE1 had a value of a billion? Where do you think the max element will be?

Community Treasure Hunt

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

Start Hunting!

Translated by