2018-03-01

Folding and Interpolation: Aligning Time Series Data

Two ways to align time series data to a common interval: folding many points into one, or filling gaps between sparse ones.

TimeseriesFoldingInterpolation

Time series data shows up at all sorts of intervals from all sorts of sources. A meter might report every minute, a setpoint every five, a daily total once a day. To chart, calculate, or compare any of it side by side, you almost always need to align it to a common grid.

Two techniques do most of that work. Folding collapses many points into one (downsampling). Interpolation stretches a few points into many (filling gaps). They're common enough that most time series databases ship them as first-class operations on history queries.

Folding

Folding (also called aggregating or rolling up) takes many values in a time range and reduces them to a single representative value for that range. The fold function decides what "representative" means: a sum, an average, a minimum, a maximum, and so on.

Below are ten 1-minute energy readings folded into two 5-minute windows. The same raw data produces very different folded values depending on the function chosen.

Fold function

Ten 1-minute readings folded into two 5-minute windows. Switch the fold function and watch the dashed line redraw.

Add every value in the window.

Window 1 · 00:00 – 00:04
sum(1, 2, 3, 2, 1)
9 kWh
Window 2 · 00:05 – 00:09
sum(2, 3, 4, 3, 2)
14 kWh

Which function to use depends on the data type. Sums make sense for consumption (kWh used over the window); averages for sampled quantities (mean temperature); min and max for envelope analysis (peak demand, lowest pressure). Booleans don't average meaningfully, so for those you'd typically fold by first, last, or whichever value held the longest.

Interpolation

Interpolation is the inverse: a handful of known values stretched into many. It's how you fill gaps between sparse readings, or upsample a coarse trend onto a finer grid.

There are three common approaches, and the right one depends entirely on what the data represents:

Linear
Smooth transition between known values.
Best for: Sampled trends like temperature.
Change of Value
Hold the last known value until a new one.
Best for: Set points and boolean states.
Apportion
Spread each value evenly across its gap.
Best for: Consumption like energy or material flow.

Three known points at minutes 0, 5 and 10 (5 kWh, 10 kWh, 5 kWh) give visibly different shapes under each method. Linear draws a sawtooth between them, change-of-value steps up and back down, and apportion redistributes the totals into per-minute portions:

Interpolation method

Three known points (yellow) at minutes 0, 5 and 10. Switch methods to see how the gaps get filled.

Smoothly transition between known values.
Best for: Sampled trends like temperature or pressure.

Why it matters

Picking the wrong fold or interpolation silently distorts every downstream calculation. Average a meter reading you should have summed, or linearly interpolate a setpoint that should have held, and the numbers further down the pipeline are simply wrong, often without warning. Aligning data to a common interval is the quiet pre-step that decides whether the chart on the dashboard tells the truth.