📡 Kalman Filter
Interactive Kalman filter simulation: track a moving target, tune process and measurement noise, watch the covariance ellipse grow on predict and shrink on update.
About the Kalman Filter
The Kalman Filter, developed by Rudolf Kálmán in 1960, is an optimal recursive linear state estimator that fuses a noisy process model with noisy sensor measurements to produce the minimum mean-squared-error estimate of a hidden state. It operates in two alternating phases: Predict (propagate the state estimate and grow the uncertainty covariance using the process model) and Update (incorporate a new measurement to shrink the covariance and correct the estimate via the Kalman Gain K = P·Hᵀ·(H·P·Hᵀ + R)⁻¹). It powered the Apollo guidance computer's navigation system and is ubiquitous in GPS, robotics, and financial time series.
The simulation tracks a target moving under a simple constant-velocity model. You can tune the process noise covariance Q (model uncertainty) and measurement noise covariance R (sensor noise), and observe the covariance ellipse expanding during the predict step and contracting on each measurement update. An RMSE counter compares the Kalman estimate against the raw measurements and the noise-free true trajectory.
Frequently Asked Questions
What does the Kalman Gain K represent?
The Kalman Gain K = P⁻·Hᵀ·(H·P⁻·Hᵀ + R)⁻¹ is a weighting matrix that determines how much to trust a new measurement versus the prediction. When measurement noise R is small, K approaches H⁻¹ and the estimate jumps toward the measurement. When R is large, K approaches 0 and the estimate barely moves. It elegantly blends model and sensor confidence at each step.
What is the difference between Q and R in the Kalman Filter?
Q is the process noise covariance matrix, representing uncertainty in the system dynamics model — for instance, unknown accelerations in a vehicle navigation system. R is the measurement noise covariance, representing sensor imprecision (e.g., GPS accuracy). Increasing Q makes the filter trust measurements more and respond faster to manoeuvres; increasing R makes it smooth out sensor noise but react more slowly to true state changes.
When does the Kalman Filter give the optimal estimate?
The Kalman Filter is optimal (minimum MSE) when the system is linear, the process noise is Gaussian with covariance Q, the measurement noise is Gaussian with covariance R, and the initial state estimate and its covariance are correct. Violating any of these assumptions degrades performance, motivating extensions such as the Extended Kalman Filter (EKF) for nonlinear systems and Particle Filters for non-Gaussian noise.
What is the Extended Kalman Filter (EKF)?
The EKF handles nonlinear systems by linearising the state-transition and measurement functions around the current estimate using their Jacobian matrices. While not truly optimal (linearisation introduces errors), it is widely used in robotics (SLAM), aerospace navigation, and augmented reality. Its main weakness is divergence when the nonlinearity is severe or the initial estimate is poor.
What is the Unscented Kalman Filter (UKF)?
The UKF propagates a small set of carefully chosen sigma points through the true nonlinear functions rather than linearising, giving a more accurate second-order approximation of the posterior distribution. It typically outperforms the EKF on highly nonlinear problems at similar computational cost and is the preferred choice in many aerospace and robotics applications.
How does a Kalman Filter differ from a Particle Filter?
A Particle Filter (Sequential Monte Carlo) represents the state distribution as a weighted set of random samples (particles), making no Gaussian assumption. It can handle arbitrary nonlinear, non-Gaussian systems but requires hundreds to thousands of particles and is far more computationally expensive. Kalman-family filters dominate where linearity and Gaussian noise are reasonable assumptions.
What is steady-state Kalman Filter?
For time-invariant linear systems the Kalman Gain K converges to a constant steady-state value as t → ∞, which can be computed offline by solving the discrete algebraic Riccati equation (DARE). Using this fixed gain eliminates the need to update the covariance matrix online, reducing computation to a simple matrix-vector multiply — important for high-rate embedded systems.
What is sensor fusion and how does the Kalman Filter enable it?
Sensor fusion combines readings from multiple sensors (e.g., accelerometer + GPS + barometer) to produce estimates better than any individual sensor. The Kalman Filter handles this naturally: each sensor provides a measurement equation H with its noise covariance R; sequential updates (or a joint measurement vector) incorporate all sensors optimally at each timestep. This is the basis of inertial navigation systems in aircraft and autonomous vehicles.
Was the Kalman Filter really used on the Apollo missions?
Yes. The Apollo Guidance Computer used a variant of the Kalman Filter for orbit determination and lunar landing guidance. Kálmán presented the algorithm in 1960; NASA's Stanley Schmidt adapted it for the nonlinear trajectory estimation problem in 1961, producing what became known as the Schmidt-Kalman Filter. It is one of the most consequential applications of control theory in history.
Optimally fuse noisy measurements with a motion model. The covariance ellipse grows on predict and shrinks on update; the Kalman estimate beats both raw measurements and model-only — running RMSE proves it.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install