# Correlation between a signal segment and its stretched replica

In my application the measurements are affected by temperature and the signal is stretched over time, though preserving relatively similar structure.

I want to find incremental stretching between pairs of consecutive signals. Having a pair of signals, I divide the first into N segments (windows) and for each window I want to find it's shift and new length in the next signal.

I tried to estimate these incremental shifts with peak detection, but got low accuracy estimates, probably due to the stretching effects on the waveform structure.

In addition, I was advised to try Dynamic Time Warping algorithm, but it manipulates both signals to find the minimal Euclidean distance. In my case I would want only the first segment to be warped until it correlates perfectly with some waveform in the 2nd signal. Couldn't find the way to do so with DTW.

• Can you please explain a bit more about the source of these signals (if possible) and what does this "warping" mean in your specific application? – A_A Aug 14 at 10:06
• look at (google) cross ambiguity function if the stretch is affine – Stanley Pawlukiewicz Aug 14 at 12:07
• @A_A the source is from ultrasonic transducer. What you see in the graphics is the temperature influence on the backscattering echoes – Alex Z Aug 15 at 14:38
• @AlexZ Can you post these two signals on Pastebin? Have you tried DTW already? – A_A Aug 15 at 14:55
• @A_A yeah, I've posted them on pastebin, please see the link below pastebin.com/u/LexZ . Regarding the DTW, as I wrote it manipulates both signals. I have tried it, but it stretched both signals to match between them and the euclidean distance it provided didn't make any sense... – Alex Z Aug 16 at 18:21

Say you got two similar signals when one of them is stretched and you want to know the straching ratio... Seems like you can 1. guess the straching ratio 2. resample the short signal with a resampling ratio equal to your guessed straching ratio. 3. Find the max of the convolution between the signals. 4. Optimize the estimation of the straching ratio using a numerical method.

If I understand your problem correctly, let us say $$S_1$$ and $$S_2$$ is the pair of signals, where, $$W_1$$ is the window segment from original signal and $$S_2$$ is the stretched version of the original signal. Since you do not know the stretching factor, you can only vary it over a reasonable range and check the auto correlation values. For each stretching factor $$\Delta$$ ($$\Delta \gt 1$$), you need to get the correlation of $$W_1 S_2^*$$. You can vary $$\Delta$$ over a reasonable range in steps to record peak of each auto-correlation. The value which gives you maximum should be the stretching factor you are looking for.

• Thank you, I understand what you propose. One thing that still is not clear for me, what do you mean by assumption that I know the start/stop boundaries of the signals? Do you mean that both signals should start from the same index? Say, the first peak should be matched? In order to incrementally adjust all the following windows? – Alex Z Aug 15 at 14:24
• Ok I made a mistake there when I read your statement in the question "divide it into N segments". My statement in invalid for S2. It is valid only for S1 where we know how we have divided it into N segments. I will edit my answer. – jithinrj Aug 15 at 14:44
• I'm still confused. If the 1st index of W1 is not aligned with the 1st index of the target window in S2, stretching W1 would leave the 1st index in place and hence would overstretch the W1 without matching the waveforms between the windows. Do you agree? – Alex Z Aug 16 at 18:00
• The first index of W1 may never match with 1st index of target window in S2. That is why we need to do correlation. In correlation, we slide W1 over the whole of S2. The index where the peak occurs gives an idea of the starting point of 1st index in target window. – jithinrj Aug 17 at 2:56
• Got you. Thanks! – Alex Z Aug 18 at 7:15