This should be a simple problem, yet I can seem to figure out what am I doing wrong. I have a bunch of 1-D signals which I expect to look the same up to: shifting, maybe some scaling, and noise.

I with to find the shift between adjacent signals. For example here is one pair: enter image description here

Each signal is expected to be of the same size (circa 200samples), and more or less look like the example. I would expect the that using the cross correlation between them would help me find the required shift. However, when calculating the cross correlation it is maximal at zero lag:

enter image description here.

I suspected it has to do with the fact that the signal is positive definite, and that it isn't periodic. Thus, when doing a shift we necessarily lose some correlation. By scaling (mean subtraction and division by std), we get a better result:

enter image description here

My questions:

  1. Is this really the root cause?
  2. Is there a standard scaling used in such cases
  3. Would this be resolved if one signal included several periods.
  • $\begingroup$ Re: 1. it does seem to, right? For a definte answer, you'd need to come up with a parametric signal model. 2. no, you do things for a reason, so scalings chosen are usually chosen to fit that purpose. 3. no, by the very definition of periodicity. $\endgroup$ May 16, 2023 at 10:46
  • 1
    $\begingroup$ Are you padding your signals, or letting it wrap around in a circular cross-correlation? $\endgroup$
    – cloudfeet
    May 16, 2023 at 18:07
  • $\begingroup$ My point is that when offsetting signals in time (as for autocorrelation) we need to consider what the effective value of the signal is outside that 189-sample range. $\endgroup$
    – cloudfeet
    May 16, 2023 at 18:13
  • $\begingroup$ @cloudfeet I used MATLAB's xcorr function which to my understanding uses a full linear convolution (pads signals). Would using a circular wrap around resolve the issue? $\endgroup$
    – Yair M
    May 17, 2023 at 8:10
  • 1
    $\begingroup$ @YairM so that's effectively padding your finite signals with zeros, right? Which means that the sharpest, clearest edges in both your signals are at the start and end, where it jumps to 0. Given that, your first result isn't surprising, and the improvement you see from subtracting the mean is from reducing that jump at the edges. $\endgroup$
    – cloudfeet
    May 17, 2023 at 20:37


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.