Skip to main content

1D Recursive Filters

Probability
Filtering
Bayes' Theorem
Smooth a noisy signal with a moving average, an exponential moving average and a Kalman filter.
Author

Apurva Nakade

Published

August 7, 2026

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: \(Q\), the assumed process-noise variance (how much the true value is expected to drift between samples), and \(R\), the assumed sensor-noise variance (how noisy each measurement is).

Start

Set \(\hat x_0 \leftarrow z_0\)

Set \(P_0 \leftarrow R\)

Predict

Grow variance

Set \(\bar P_i \leftarrow P_{i-1} + Q\)

Update

Measure

\(z_i\): the newest noisy measurement

Compute Gain

Set \(K_i \leftarrow \bar P_i \big/ \bigl(\bar P_i + R\bigr)\)

Update estimate

Set \({\hat x_i \leftarrow (1 - K_i)\, \hat x_{i-1} + K_i\, z_i}\)

Update variance

Set \(P_i \leftarrow (1 - K_i)\, \bar P_i\)

next measurement

NoteConvergence plots

References

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