4
$\begingroup$

How to apply filter to data that was sampled in certain moments of time? Examples from documentation deal only with uniformly sampled data:

data = Table[SquareWave[i/100] + RandomReal[{-0.1, 0.1}], {i, 225}];
GraphicsRow[ListLinePlot /@ {data, LowpassFilter[data, .5]}]

I.e. time is not included in the array. How to apply similar filter to the case when sampling times are explicitly stated? The following fails:

data = Table[{i/100, SquareWave[i/100] + RandomReal[{-0.1, 0.1}]}, {i,225}];
GraphicsRow[ListLinePlot /@ {data, LowpassFilter[data, .5]}]
$\endgroup$
2
  • $\begingroup$ @kglr this won't work for non uniform sampling time: data = Table[{(i/100)^2, SquareWave[(i/100)^2] + RandomReal[{-0.1, 0.1}]}, {i, 525}]; $\endgroup$ May 3, 2018 at 19:39
  • $\begingroup$ @kglr this works, thank you $\endgroup$ May 3, 2018 at 19:55

2 Answers 2

2
$\begingroup$

Just apply TemporalData or TimeSeries to your data:

data = TemporalData[Table[{i/100, SquareWave[i/100] + RandomReal[{-0.1, 0.1}]}, {i,225}]];
ListLinePlot[{data, LowpassFilter[data, 60]}]

enter image description here

You can use Timeseries objects essentially like a InterpolatingFunction:

data0 = Table[{i/100 + RandomReal[{-0.005, 0.005}], 
    SquareWave[i/100] + RandomReal[{-0.1, 0.1}]}, {i, 225}];
f = TimeSeries[data0, 
   "ResamplingMethod" -> {"Interpolation", InterpolationOrder -> 0}];
g = TimeSeries[data0, 
   "ResamplingMethod" -> {"Interpolation", InterpolationOrder -> 1}];
h = TimeSeries[data0, 
   "ResamplingMethod" -> {"Interpolation", InterpolationOrder -> 3}];
Plot[{f[t], g[t], h[t]}, {t, f["Times"][[1]], f["Times"][[-1]]}]

enter image description here

The default resampling method is of order 1 (piecewise-linear interpolation). You can get the InterpolatingFunction with g["PathFunction"].

Also interesting for you might be to inspect other properties with g["Properties"] (this works also for TemporalData objects.

$\endgroup$
3
  • $\begingroup$ Is there any difference between TimeSeries and TemporalData? $\endgroup$ May 3, 2018 at 20:12
  • $\begingroup$ How do I plot TimeSeries like a usual function? $\endgroup$ May 3, 2018 at 20:42
  • $\begingroup$ This proved to work much faster than Timeseries. $\endgroup$ Jul 1, 2018 at 23:04
4
$\begingroup$
data = Table[{(i/100)^2, SquareWave[(i/100)^2] + RandomReal[{-0.1, 0.1}]}, {i, 180}]; 
GraphicsRow[ListLinePlot /@ {data, LowpassFilter[TimeSeries@data, Quantity[5, "Hertz"]]}]

enter image description here

$\endgroup$

Your Answer

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

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