# Finding delay between signals

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:

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:

.

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:

## 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.
• 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. May 16, 2023 at 10:46
• Are you padding your signals, or letting it wrap around in a circular cross-correlation? May 16, 2023 at 18:07
• 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. May 16, 2023 at 18:13
• @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? May 17, 2023 at 8:10
• @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. May 17, 2023 at 20:37