How to align two signals using xcorr function?

2 views (last 30 days)
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

Answers (1)

Image Analyst
Image Analyst on 26 Apr 2017
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?
  1 Comment
Image Analyst
Image Analyst on 26 Apr 2017
Maybe you could attach your two signals in a .mat file to help speed this along.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!