Cross correlation in MATLAB HELP

1.2k Views Asked by At

I have values from two sensors stored in two vectors A and B. They both represent values of the sensors at times TA and TB which is stored in two other vectors(since it is not uniform sampling) Both A and B represent the same data but A is shifted a bit to the right because of the delay in starting the sensors.

My question is, how do I calculate this delay and more importantly, how do I shift A to match B or vice versa, such that I can do a one-to-one correspondence of the data?

Right now, I am finding the peak of the cross-correlation function of A and B to find the offset (in number of samples, not time) and padding the arrays with zero upto that number, but I am 100% sure that is wrong. Problem is, I don't know how else.

PLEASE help!

Thanks!

1

There are 1 best solutions below

0
On

Check out the xcorr function in MATLAB, found here: http://www.mathworks.com/help/toolbox/signal/ref/xcorr.html

It is equivalent to "matched filtering", which is convolving some vector (input 1) with a time reversed, complex-conjugated pattern vector (call the pattern vector input 2). A peak will occur at the index where the maximum overlap occurs between input 1 and input 2.