Sketch · 2026-09-18
Kalman filter, on a noisy signal.
A target drifts across the canvas along a Lissajous curve. Every frame a sensor reports its position with Gaussian noise added, and those measurements are all the filter ever sees. A four-state Kalman filter fuses each reading with its own prediction, weighted by how much it trusts each side. The estimate sits close to the truth even when the scatter is wide, and the shaded ellipse shows the filter's own belief about where the target could actually be.
Drop the measurement noise low and the estimate hugs the dots straight through. Raise it and the filter starts to trust its own prediction; the line smooths out and the ellipse grows. The process noise σa is the other lever: it says how much the target is allowed to accelerate between frames, so a large value lets the filter turn hard corners at the cost of noisier tracking.
Note
The state is four numbers: position and velocity along each axis. A constant-velocity transition F pushes the state forward one frame, and a 2×4 matrix H picks out position for the measurement. Two loops repeat every frame. The predict step advances the state and inflates the covariance P by the process-noise matrix Q. The update step reads a measurement z, computes the innovation z − Hx, weights it by the Kalman gain K = P HT S−1, and shrinks P by (I − KH).
S in the gain formula is a 2×2 innovation covariance. Because it is the only matrix that needs to be inverted, and it is small, the whole update runs on a handful of hand-written matrix operations with no dependencies at all. The ellipse under the estimate is the unit-σ contour of the position sub-block of P; it is the filter saying how sure it is of its own answer.
Rudolf Kálmán published the recursion in 1960. NASA picked it up almost immediately for Apollo, and it now runs quietly inside radar tracking, GPS receivers, sensor fusion in phones and most self-driving stacks. The version here is the plain linear one; the same skeleton, with a linearisation step added, becomes the extended Kalman filter used for nonlinear systems.
Sources
- Kálmán, R. E. (1960). A new approach to linear filtering and prediction problems. Journal of Basic Engineering 82(1): 35–45.
- Welch, G., Bishop, G. (2006). An introduction to the Kalman filter. Technical report TR 95-041, UNC-Chapel Hill.
- Labbe, R. (2020). Kalman and Bayesian Filters in Python. Open-source book, GitHub: rlabbe/Kalman-and-Bayesian-Filters-in-Python.