1

I have 2 acceleration vectors, each represented by a matrix with its first column corresponding to the magnitude of acceleration and second column corresponding to the time (in ms) They both represent the same data, but one sensor is started a little later than the other, so I'm trying to remove the time lag using correlation.

How do I find the correlation between these 2 matrices? I tried to do xcorr2 but it doesn't seem right and doing xcorr would probably calculate correlation with only the values into consideration, but I also want to account for the time. The idea is that I should finally get a correlation vector wrt time and then when I calculate the peak of the correlation vector, its index would correspond to the time lag.

I'm really confused here, will an FFT help? How would you suggest I go about it?

mpiktas
  • 33,140
  • 5
  • 82
  • 138
  • @mbq, @imelza, this is pretty much a duplicate of **[this question](http://stats.stackexchange.com/questions/7727/how-to-correlate-two-time-series-with-gaps-and-different-time-bases)**. Usually if there is a question that would provide the answer you need, it's a little frowned upon to submit another that is very similar. You'd be better off waiting to see if you can glean an adequate answer from the original one. Regards. – cardinal Mar 01 '11 at 03:31
  • Hi, I understand that the questions are very similar, but I cannot comment on that question and I really need this answer. –  Mar 01 '11 at 03:36
  • Is the time scale identical for both of the variables? Can you post an example of your data set? – mpiktas Mar 01 '11 at 04:28
  • I'm not familiar with Matlab functions... in R I would use `ccf`, that calculates the cross correlation function of the two signals. The FFT won't help here, as you don't want to do anything in the frequency domain, as far as I understand. – nico Mar 01 '11 at 07:57
  • @nico, in terms of *implementation*, the FFT will most definitely help if the matrices have a large number of rows. Both MATLAB and R use a frequency-domain approach to calculation of crosscorrelation. R's is incredibly naive, unfortunately, unless you understand the underlying approach and resize your matrix to take advantage of it. MATLAB's is a bit smarter, if I recall correctly. – cardinal Mar 01 '11 at 12:19
  • @cardinal: thanks, I didn't know about that :) – nico Mar 01 '11 at 12:53
  • @nico, sure. A naive correlation takes $O(n^2)$ operation where it's easy to calculate the leading constant. An FFT-based implementation is $O(n \log n)$, where the leading constant can be taken somewhere between 8 and 16 or so. The value of $n$ doesn't have to be too large to make that worth it. – cardinal Mar 01 '11 at 13:15

0 Answers0