1
$\begingroup$

I have two vectors of matching lengths. They are readings from two different sensors (one is from a smartphone and the other is from a wiimote) of the same hand movement. I am trying to find the time offset between them to synchronise the readings for further processing. The readings I get are of the format (Time(ms) Value) for accelerations in the X,Y and Z direction.

For the synchronization, I plotted the cross-correlation function xcorr2() between the two sets. I am getting the same graph (a weird triangle peak and a straight line at the bottom) for Accelerations along the x, y and z directions (which I guess is good) but I don't know how to interpret it. What do the axes in the graph represent?

Can anyone explain to me what xcorr2() means in a qualitative sense. From the correlation function, how do I determine the offset (i.e. how many seconds is sensor1 behind sensor2)?

Thanks!

Imelza

enter image description here

  • 0
    You will probably get a better answer from http://stats.stackexchange.com/2011-02-15

2 Answers 2

1

The peak of the triangle represents your offset. If the two vectors were identical, the peak would appear exactly in the center. If they are offset from each other, the peak will occur offset from the center.

I'd do an experiment and correlate a vector with itself. Then use a function like argmax() to find the index of the maximum position. It should be len(vector)/2 plus or minus 1. Then do the correlation of the two different signals, and do argmax on that. Subtract the value you just found for identical vectors, and you will have your offset. If you reverse the order of the signals, the offset will be negative.

Remember that there are different implementations of correlation, like a circular cross-correlation, where the signals are wrapped around. You don't want that. If the Matlab function is a circular cross-correlation (FFT-enhanced), then you need to zero pad first. Read into the different implementations and options of xcorr2.

Here's a simple example in Python.

  • 0
    Yes, I resampled it to be uniform and your method works now. Thanks a lot!!2011-03-17
1

@Imelza If the data is not uniformly sampled in time, xcorr will not work correctly (and shifting it by samples will not give the right correspondence.) You could use interp1 to resample it uniformly first.

  • 1
    Thanks! I resampled the data uniformly and it pretty much worked. Thanks very much!2011-03-17