I have a time series - let's say I'm given one new sample (a real value) every second.

I could take a moving average of the last 50 samples or I could use exponential smoothing of the samples with a time constant of 50 . The resulting graphs of the "output" would be fairly similar. The "current output" of the algorithm assumes that the underlying values are constant plus some noise and the algorithm gives a best-guess of that underlying value.

Or I could do "double exponential smoothing". The "current output" is an estimate of a linear graph. After each sample arrives I have as estimate of the current value and how it is linearly increasing.

What I want is to get a best guess of the quadratic expression for that last 50 samples.

I can find the quadratic expression for that last 50 samples. It's just a regression. But to calculate a regression I'd have to actually look at the last 50 samples - that's too much calculation. I want to do it using some sort of recursive function; rather like exponential smoothing is a cheap way of taking a moving average.

I assumed that "triple exponential smoothing" was what I'm looking for but that's something completely different. It includes a term for "seasonality".

So what is the algorithm? Or what is the Google search term?

  • $\begingroup$ As mentioned by @Hilmar, with uniform sampling, you can have a formulation with a stored inverse. If you want to be less sensitive of the past, a sliding power weight can be applied as well. Not much computations if done properly, especially with 0-indexing as proposed in CHOPtrey: contextual online polynomial extrapolation for enhanced multi-core co-simulation of complex systems. Have a look, I'll elaborate if useful $\endgroup$ Aug 10 at 17:33
  • $\begingroup$ Yes, that tells me to search for "Polynomial Extrapolation/Interpolation" - which gives interesting hits. But all I've found so far assumes I want an N-degree polynomial exactly fitting N+1 points. What I want is a 2nd-degree polynomial "best fit" to the past N points - hence a regression. And I want a recursive algorithm so I store a just few values and do just a few mults/adds for each new sample. "Double exponential smoothing" is a recursive way of calculating a 1st-degree polynomial using the "sliding power weight" that you suggest. What's the 2nd-degree equivalent? Please do elaborate. $\endgroup$ Aug 10 at 20:38

1 Answer 1


Moving average and exponential smoothing are just very simple lowpass filters. There are many different types of low pass filters available and chances finding the right one will be a good option for whatever it is you need to do. If you want "quintuple exponential smoothing", just use a 5th order IIR lowpass filter and you can still play around with cutoff frequency, ripple, stop band attenuation, etc.

Quadratic regression can be done, but it is a fairly non-linear operation and you have to make sure that's acceptable in your context.

But to calculate a regression I'd have to actually look at the last 50 samples - that's too much calculation.

It's not that hard to do. Quadratic regression can be expressed as three equations with three unknowns (see for example here) in the form a matrix equation.

$$X \cdot \begin{bmatrix} a \\ b \\c \end{bmatrix} = Y $$

Assuming your data is sampled at a constant rate, the coefficient matrix, $X$ on the left never changes, so you only need to calculate it once, invert it and store it. Your regression then becomes a simple matrix multiplication

$$\begin{bmatrix} a \\ b \\c \end{bmatrix} = X^{-1} \cdot Y $$

The only thing that needs to be updated the is the vector, $Y$

$$ Y = \begin{bmatrix} \sum_i i^2 \cdot y_i \\ \sum_i i \cdot y_i \\ \sum_i y_i\end{bmatrix} $$

That doesn't seem particularly difficult to do.

  • $\begingroup$ Thank you. I'm not trying to make a low-pass filter. What I'm asking is how to calculate the best guess of the current values of a, b and c over, say, the last 50 samples. $\endgroup$ Aug 10 at 14:08
  • $\begingroup$ Does what I wrote answer your question? For every sample you just need to recalculate $Y$ multiply with $X^{-1}$ and that will give you the current estimate of a, b, and c. $\endgroup$
    – Hilmar
    Aug 10 at 22:02
  • $\begingroup$ Sorry but I don't understand how it answers the question. You can use the matrix method to obtain a,b,c from the most recent 3 samples. Or use the matrix method to get a least-squares estimate from all the samples. Which are you proposing? Neither is what I want. Where does the time-constant of the exponential fit in? $\endgroup$ Aug 11 at 9:30

Your Answer

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

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