Aligning 2 signals using cross correlation

10 views (last 30 days)
Mp897
Mp897 on 7 Oct 2013
Commented: dpb on 8 Oct 2013
I want to align 2 signals of same sampling rate using cross correlation. I was thinking of taking 1min data of signal 2 and finding the cross correlation(highest correlation value) at signal1. How do I find the cross correlation at every point on signal 1? Is there any better method? Signal 1: 4000seconds;Signal 2: 2500seconds. Please pour in your suggestions. Thanks for your time.

Answers (2)

dpb
dpb on 8 Oct 2013
doc xcorr
Seems like I answered this and gave an example application not that long ago (then again, it could have been on the newsgroup instead, I don't recall). Try a search on my answers and correlation and see if joy ensues...
But, it's pretty much just do the cross correlation, find the largest lag and adjust...

Image Analyst
Image Analyst on 8 Oct 2013
The max of a cross correlation shows where the sum of the products of the signals is max but that is not necessarily where you would visually place the signal if you did it manually. For example a Gaussian and a big giant step (rect function) correlated with another Gaussian (same as the first one) may put the max at the big giant step rather than where the two Gaussians overlap exactly. This is why normalized cross correlation was invented, and that may work better for you. It's done by normxcorr2 in the Image Processing Toolbox. I have a demo for it that I've attached below. A discussion of template matching methods is given here: http://en.wikipedia.org/wiki/Template_matching
  1 Comment
dpb
dpb on 8 Oct 2013
Yeah, if the two signals are disparate simple correlation may lead to peculiar results -- I was presuming OP has similar waveforms that weren't collected respective to a consistent triggering for which correlation generally works well...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!