# Interpreting Results of Repeated Measures - Shift calculation in plots

What would be a more accurate method to calculate the shift in waveform (waveform drift) from a collection of 20 or more data plots.

Current method, Plot all using Show and see if there is some distinctive shifts. But since the change in plots is very minute, how can I get a more accurate value for the shifts ?

Example data

My idea is something like below:

• I'm not sure if its the best way but you could just compute the shift for every point and average? I would guess this would be very precise since you are sampling many points Commented Aug 4, 2015 at 14:47
• I gave a thought to that idea, but resorted to this assuming that the shifts can be seen and also a calculated value can be given Commented Aug 4, 2015 at 14:48
• ListConvolve might prove useful. Commented Aug 4, 2015 at 15:30

{a, b, c} =
Transpose@
Rest@Import[
"Example_Data.csv",
"Data"];


And you can let Mathematica find it by integrating the difference with a shift,

FindMinimum[
NIntegrate[
Abs[
Interpolation[b, InterpolationOrder -> 1][x]
- Interpolation[c, InterpolationOrder -> 1][x - s]
], {x, Min[a], Max[a]}]
, {s, 0}]

{4543.82, {s -> 0.00914418}}


You can get a visual idea where the minimum is and its quality (Beware these is computationally intensive).

Plot[
NIntegrate[
Abs[
Interpolation[b, InterpolationOrder -> 1][x]
- Interpolation[c, InterpolationOrder -> 1][x - s]
], {x, Min[a], Max[a]}]
, {s, -0.1, 0.1}]


• This is computationally intensive method,but very accurate. Commented Aug 6, 2015 at 16:38
• @abhilashsukumari There are things to do after your question has been answered, but don't rush, you may want stay vigilant some time after you get the first answers as its likely that the best approaches may come later improving over a previous reply. Therefore, its a good idea to wait two days before voting the deserving answers and accepting the best one for you. (Links contain useful information). :) Commented Aug 6, 2015 at 17:02

ListCorrelateis useful as well.

Let's make some sample data

Block[{\[Omega]0 = 1/2},
t0 = RandomVariate[NormalDistribution[0, 1/25]] +
Sinc[\[Omega]0 (# - 50)] & /@ Range[0, 100, 1/4];
t1 = RandomVariate[NormalDistribution[0, 1/25]] +
Sinc[\[Omega]0 (# - 52)] & /@ Range[0, 100, 1/4];
]

ListLinePlot[{t0, t1}, PlotRange -> All, DataRange -> {0, 100}]


Use ListCorrelate (with maximal overhang to the right and zero padding to avoid circular correlation). Now look for the argmax (I interpolated, but it's not needed).

ListLinePlot[ListCorrelate[t0, t1, {1, 1}, 0], PlotRange -> All]


f = ListInterpolation[ListCorrelate[t0, t1, {1, 1}, 0], Range[0, 100, 1/4]];
ArgMax[{f[t], t > 0}, t]
(* 1.99011 *)

• Couldn't get your code to work on my data. Please do try it on the Example data in question. Commented Aug 6, 2015 at 16:29
• would the question be any different, if I were to ask - how much does the two list differ if we were to compare amplitude values (assuming there is no shift on time scale) ? Commented Aug 6, 2015 at 16:55

You can plot the two curves with a shift defined as a Manipulate variable.

Manipulate[
ListLinePlot[{
Transpose[{measureX + shift, measureY}],
Transpose[{controllerX,      controllerY}]
}],

{{shift, 0}, -0.3, 0.3}
]


Initial plot with a shift of zero

and now shifted by -0.15. You can type in the value as accurately as your eye is able to view.