3
$\begingroup$

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:

Example Image

$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – JeffDror Aug 4 '15 at 14:47
  • $\begingroup$ 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 $\endgroup$ – Rene Duchamp Aug 4 '15 at 14:48
  • 1
    $\begingroup$ ListConvolve might prove useful. $\endgroup$ – image_doctor Aug 4 '15 at 15:30
4
$\begingroup$

Load the data

{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}]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ This is computationally intensive method,but very accurate. $\endgroup$ – Rene Duchamp Aug 6 '15 at 16:38
  • $\begingroup$ @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). :) $\endgroup$ – rhermans Aug 6 '15 at 17:02
4
$\begingroup$

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}]

enter image description here

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]

enter image description here

f = ListInterpolation[ListCorrelate[t0, t1, {1, 1}, 0], Range[0, 100, 1/4]];
ArgMax[{f[t], t > 0}, t]
(* 1.99011 *)
$\endgroup$
  • $\begingroup$ Couldn't get your code to work on my data. Please do try it on the Example data in question. $\endgroup$ – Rene Duchamp Aug 6 '15 at 16:29
  • $\begingroup$ 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) ? $\endgroup$ – Rene Duchamp Aug 6 '15 at 16:55
3
$\begingroup$

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

Mathematica graphics

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

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.