Cross-correlation signal alignment
Show older comments
I would like to align two pulses through the use of cross-correlation. I create two pulses located at different parts within a sequence of 100 samples. For instance:
sig1 = zeros(1,100);
sig1(71:90) = 1;
sig2 = zeros(1,100);
sig2([21:41]) = 1;
I then do the cross-correlation between both signals
[xc1,l1] = xcorr(sig1,sig2);
[mx1,ix1] = max(xc1);
Usign the lag information from cross-correlation I can align both sequences where the maximum cross-correlation is found.
plot(1:100,sig1,'.-','linewidth',2);hold on;grid on;
plot((1:100)+l1(ix1),sig2,'.-','linewidth',2);hold on;grid on;
But this only seem to work when sig2 is not wrapped around the begin and the end. For the case where sig2 is:
sig2 = zeros(1,100);
sig2([1:10 91:100]) = 1;
Then the procedure doesn't work. Probably I should wrap the lags and the signal to align the sig2 pulse to the master sig2? Perhaps I should do circular cross-correlation in frequency domain or convolution? Thanks
Accepted Answer
More Answers (0)
Categories
Find more on Correlation and Convolution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!