Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!


share|cite|improve this question
you may be able to get answers at if you don't receive one here. Though I must say, as currently worded, I am not entirely sure whether your problem is one about data analysis or one about matlab. – Willie Wong Mar 10 '11 at 18:52

Check out the xcorr function in MATLAB, found here:

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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.