1D Recursive Filters

Compares a moving average, an exponential moving average, and a Kalman filter for smoothing a noisy 1D signal.
Author

Apurva Nakade

Published

August 7, 2026

NoteConvergence plots

Each of these filters updates a running estimate from only the previous estimate and the newest measurement \(z_i\) — no stored history of the stream — which is what makes them run in O(1) memory and O(1) compute per sample. The simple moving average and exponential moving average (a.k.a. a first-order low-pass filter) both trade responsiveness for smoothness through a hand-picked constant (\(k\) or \(\alpha\)) that never changes:

\[ \text{SMA: } \hat x_i = \frac{1}{k}\sum_{j=i-k+1}^{i} z_j, \qquad \text{EMA: } \hat x_i = \alpha\, \hat x_{i-1} + (1-\alpha)\, z_i. \]

The Kalman filter instead maintains a running estimate of its own uncertainty \(P_i\) and derives its gain from it at every step, given only two beliefs about the noise: \(R\), the assumed measurement-noise (sensor) variance, and \(Q\), the assumed process-noise variance (how much the true value is expected to drift between samples):

\[ P_i^- = P_{i-1} + Q,\qquad K_i = \frac{P_i^-}{P_i^- + R},\qquad \hat x_i = \hat x_{i-1} + K_i\,(z_i - \hat x_{i-1}),\qquad P_i = (1-K_i)\,P_i^-, \]

with no \(\alpha\) or \(k\) to tune by hand — open the convergence plots on the constant-signal example below to watch \(K_i\) shrink automatically as the filter grows more confident.

References

Staszewski, Kuba. “Recursive Filters.” Blog post. https://www.staszewski.xyz/blog/recursive-filters/