2
$\begingroup$

I can't seem to figure out the best way for directly inputting interpolated values into a dataset. I turn to your expertise for guidance.

So, I have a multi-year time-series dataset. Column 1 is time in AbsoluteTime and Column 2 is measurements. The set has data points every 30 minutes. I want to get the interpolated values for every 15 minute mark directly put into my dataset. I have used interpolation on the set, but now I want to create the datapoints (timestamp and measurement) for each midpoint between two datapoints.

Here is a small sample of the data:

s1 = {{3534364800, 0}, {3534365700, 0}, {3534366600,12.3}, {3534367500, 53.8}, {3534368400, 100.1}, {3534369300, 141.8}, {3534370200, 131.2}, {3534371100,90.3}, {3534372000, 50.2}, {3534372900, 11.2}, {3534373800, 0}, {3534374700, 0};

The time stamp increases by 900 each step. I'd like to get the data at each 450 mark

Here's what I got so far.

a = Interpolation[s1];
b = Table[a[3534364800 + 450 i], {i, 0, 22}]
c = Table[# & /@ s1[[1, 1]] + 450 i, {i, 0, 22}]
Transpose[{c, b}]
{{3534364800, 0.}, {3534365250, -0.48125}, {3534365700,0.}, {3534366150, 3.55625}, {3534366600, 12.3}, {3534367050,30.925}, {3534367500, 53.8}, {3534367950, 76.9375}, {3534368400, 100.1}, {3534368850, 124.506}, {3534369300, 141.8}, {3534369750, 141.663}, {3534370200, 131.2}, {3534370650, 112.594}, {3534371100, 90.3}, {3534371550, 70.1313}, {3534372000, 50.2}, {3534372450, 28.8938}, {3534372900, 11.2}, {3534373350, 3.1625}, {3534373800, 0.}, {3534374250, -0.3625}, {3534374700, 0.}} 

Seems like there is a MUCH better way to go about this.

Any thoughts are much appreciated. Thanks ahead of time for all your help.

$\endgroup$
  • 1
    $\begingroup$ You might want to look at the documentation for Interpolation. Define s = Interpolation[s1]; Then s[3534364850] gives the value at that time point. $\endgroup$ – bill s Mar 9 '16 at 1:54
3
$\begingroup$

I suggest you take a look at TimeSeries and related. They are a very powerful set of tools to use. Using your data, we can build a time series:

ts = TimeSeries[s1, ResamplingMethod -> {"Interpolation", InterpolationOrder -> 3}];

You can change the interpolation order to be whatever you want.

Now that we have a TimeSeries you can use TimeSeriesResample to get what you want:

rts = TimeSeriesResample[ts, 450];

Now we can visualize the resampled TimeSeries versus the original:

DateListPlot[{ts, rts}, Joined -> False, PlotStyle -> {PointSize[0.02], Automatic}]

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.