Beta. Content is under active construction and has not been peer-reviewed. Report errors on GitHub.Disclaimer

RL Theory

Kalman Filter

Optimal state estimation for linear Gaussian systems via recursive prediction and update steps using the Kalman gain.

CoreTier 1Stable~55 min

Why This Matters

Kalman Filter: Predict-Update CyclePredict_{k|k-1} = F _{k-1} + B u_kP_{k|k-1} = F P F^T + Qpropagate state and covariance forwardUpdateK_k = P H^T (H P H^T + R)^{-1}_{k|k} = + K (z_k - H )P_{k|k} = (I - K H) Pcorrect with measurementz_kprior estimatePrediction (model)F, B, Q matricesMeasurement (sensor)H, R matricesrepeat each timestep k = 1, 2, 3, ...

The Kalman filter is the exact minimum mean squared error (MMSE) estimator for linear Gaussian state-space models. It appears in GPS navigation, robotics, autonomous driving, financial time series, and any setting where you need to track a hidden state from noisy observations. Every extended or unscented variant builds on the same core recursion.

Mental Model

You have a system whose state evolves over time according to linear dynamics with Gaussian noise. At each time step, you receive a noisy measurement of the state. The Kalman filter maintains a Gaussian belief over the current state: a mean (best estimate) and covariance (uncertainty). Each step has two phases: predict (project the belief forward using the dynamics) and update (incorporate the new measurement to sharpen the estimate).

Formal Setup and Notation

Definition

Linear Gaussian State-Space Model

The state equation describes how the hidden state xtRnx_t \in \mathbb{R}^n evolves:

xt+1=Axt+But+wt,wtN(0,Q)x_{t+1} = A x_t + B u_t + w_t, \quad w_t \sim \mathcal{N}(0, Q)

The observation equation describes the measurement ztRmz_t \in \mathbb{R}^m:

zt=Hxt+vt,vtN(0,R)z_t = H x_t + v_t, \quad v_t \sim \mathcal{N}(0, R)

Here AA is the state transition matrix, BB is the control input matrix, utu_t is a known control input, HH is the observation matrix, QQ is the process noise covariance, and RR is the measurement noise covariance. The noise sequences {wt}\{w_t\} and {vt}\{v_t\} are independent of each other and of the initial state x0N(x^0,P0)x_0 \sim \mathcal{N}(\hat{x}_0, P_0).

Definition

Kalman Filter Prediction Step

Given the posterior at time tt, xtz1:tN(x^tt,Ptt)x_t | z_{1:t} \sim \mathcal{N}(\hat{x}_{t|t}, P_{t|t}), the predicted state and covariance are:

x^t+1t=Ax^tt+But\hat{x}_{t+1|t} = A \hat{x}_{t|t} + B u_t

Pt+1t=APttA+QP_{t+1|t} = A P_{t|t} A^\top + Q

This propagates the belief forward through the dynamics, increasing uncertainty by QQ.

Definition

Kalman Filter Update Step

When measurement zt+1z_{t+1} arrives, compute the innovation (measurement residual):

yt+1=zt+1Hx^t+1ty_{t+1} = z_{t+1} - H \hat{x}_{t+1|t}

The innovation covariance is St+1=HPt+1tH+RS_{t+1} = H P_{t+1|t} H^\top + R.

The Kalman gain is:

Kt+1=Pt+1tHSt+11=Pt+1tH(HPt+1tH+R)1K_{t+1} = P_{t+1|t} H^\top S_{t+1}^{-1} = P_{t+1|t} H^\top (H P_{t+1|t} H^\top + R)^{-1}

The updated state and covariance are:

x^t+1t+1=x^t+1t+Kt+1yt+1\hat{x}_{t+1|t+1} = \hat{x}_{t+1|t} + K_{t+1} y_{t+1}

Pt+1t+1=(IKt+1H)Pt+1tP_{t+1|t+1} = (I - K_{t+1} H) P_{t+1|t}

Main Theorems

Theorem

Optimality of the Kalman Filter

Statement

For a linear Gaussian state-space model, the Kalman filter posterior N(x^tt,Ptt)\mathcal{N}(\hat{x}_{t|t}, P_{t|t}) is the exact conditional distribution p(xtz1:t)p(x_t | z_{1:t}). The mean x^tt\hat{x}_{t|t} is the minimum mean squared error estimator:

x^tt=argming(z1:t)E[xtg(z1:t)2z1:t]\hat{x}_{t|t} = \arg\min_{g(z_{1:t})} \mathbb{E}[\|x_t - g(z_{1:t})\|^2 | z_{1:t}]

and PttP_{t|t} is the conditional covariance Cov(xtz1:t)\text{Cov}(x_t | z_{1:t}).

Intuition

Gaussians are closed under linear transformations and conditioning. Since the dynamics are linear and all noise is Gaussian, the joint distribution of (xt,z1:t)(x_t, z_{1:t}) is always Gaussian. Conditioning a Gaussian on observed values yields another Gaussian, and the conditional mean of a Gaussian is always the MMSE estimator.

Proof Sketch

Proceed by induction. The base case holds because x0x_0 is Gaussian. For the inductive step: if xtz1:tx_t | z_{1:t} is Gaussian, then xt+1=Axt+But+wtx_{t+1} = A x_t + B u_t + w_t is a linear function of Gaussians, so xt+1z1:tx_{t+1} | z_{1:t} is Gaussian (prediction step). The joint (xt+1,zt+1)z1:t(x_{t+1}, z_{t+1}) | z_{1:t} is then jointly Gaussian, and conditioning on zt+1z_{t+1} gives xt+1z1:t+1x_{t+1} | z_{1:t+1} as Gaussian (update step). The formulas for the conditional mean and covariance of a jointly Gaussian vector yield exactly the Kalman gain equations.

Why It Matters

This is one of the rare cases where the optimal Bayesian filter has an exact, finite-dimensional, closed-form recursion. For nonlinear or non-Gaussian systems, no such finite recursion exists, and all practical filters (EKF, UKF, particle filters) are approximations.

Failure Mode

The optimality guarantee breaks completely when any of its assumptions fail. If the dynamics are nonlinear, the posterior is no longer Gaussian and the Kalman recursion is only an approximation (EKF). If the noise is heavy-tailed, the MMSE estimator is no longer the conditional mean of a Gaussian, and the filter can diverge on outlier measurements. If the system matrices A,H,Q,RA, H, Q, R are misspecified, the filter is overconfident: PttP_{t|t} underestimates the true uncertainty.

Extensions to Nonlinear Systems

Extended Kalman Filter (EKF)

For nonlinear dynamics xt+1=f(xt,ut)+wtx_{t+1} = f(x_t, u_t) + w_t and nonlinear observations zt=h(xt)+vtz_t = h(x_t) + v_t, the EKF linearizes around the current estimate:

Ft=fxx^tt,Ht=hxx^t+1tF_t = \frac{\partial f}{\partial x}\bigg|_{\hat{x}_{t|t}}, \quad H_t = \frac{\partial h}{\partial x}\bigg|_{\hat{x}_{t+1|t}}

Then applies the standard Kalman recursion using FtF_t in place of AA and HtH_t in place of HH. This is a first-order Taylor approximation and can diverge if the nonlinearity is strong.

Unscented Kalman Filter (UKF)

The UKF avoids computing Jacobians. Instead, it propagates a set of deterministically chosen sigma points through the nonlinear functions ff and hh, then reconstructs the mean and covariance from the transformed points. For a state of dimension nn, the UKF uses 2n+12n + 1 sigma points. It captures second-order effects that the EKF misses, with the same O(n3)O(n^3) cost per step.

Canonical Examples

Example

Tracking position from noisy GPS

A vehicle moves in 1D with constant velocity model. State: xt=[position,velocity]x_t = [\text{position}, \text{velocity}]^\top. Dynamics:

A=[1Δt01],Q=q[Δt3/3Δt2/2Δt2/2Δt]A = \begin{bmatrix} 1 & \Delta t \\ 0 & 1 \end{bmatrix}, \quad Q = q \begin{bmatrix} \Delta t^3/3 & \Delta t^2/2 \\ \Delta t^2/2 & \Delta t \end{bmatrix}

Observation: GPS measures position only, so H=[1,0]H = [1, 0], R=σgps2R = \sigma_{\text{gps}}^2.

With Δt=1\Delta t = 1, q=0.1q = 0.1, σgps=5\sigma_{\text{gps}} = 5: the filter smooths out GPS noise while estimating velocity (which is never directly observed). After several steps, the position uncertainty P11P_{11} drops well below σgps2\sigma_{\text{gps}}^2 because the velocity estimate provides additional information.

Example

Sensor fusion: combining GPS and accelerometer

Same state as above, but now add an accelerometer measurement zt(2)=at+vt(2)z_t^{(2)} = a_t + v_t^{(2)} where ata_t is acceleration. Augment the state to include acceleration, or treat the accelerometer as a control input ut=zt(2)u_t = z_t^{(2)} with known noise. The Kalman filter optimally fuses both sensors by weighting each measurement inversely proportional to its noise variance. This is the principle behind inertial navigation systems.

Common Confusions

Watch Out

The Kalman gain is not a tuning parameter

The Kalman gain KtK_t is derived, not chosen. It is the unique gain that produces the MMSE estimate given the model. "Tuning" a Kalman filter means choosing QQ and RR to match the actual noise statistics, not manually adjusting KK.

Watch Out

The Kalman filter does not require stationarity

The matrices A,H,Q,RA, H, Q, R can all be time-varying: At,Ht,Qt,RtA_t, H_t, Q_t, R_t. The recursion and optimality still hold. Stationarity is only needed if you want the covariance PttP_{t|t} to converge to a steady state (solving the discrete algebraic Riccati equation).

Watch Out

EKF is not optimal for nonlinear systems

The EKF applies the Kalman equations to a linearized system. The result is not the true posterior p(xtz1:t)p(x_t | z_{1:t}), which is generally non-Gaussian for nonlinear dynamics. The EKF can diverge when the linearization is poor. The UKF and particle filters provide better approximations at higher cost.

Summary

  • Predict step: project mean and covariance forward through dynamics
  • Update step: correct using the Kalman gain K=PpredH(HPpredH+R)1K = P_{\text{pred}} H^\top (H P_{\text{pred}} H^\top + R)^{-1}
  • Optimal (MMSE) only for linear Gaussian systems
  • Covariance PttP_{t|t} does not depend on the actual measurements, only on the model
  • EKF linearizes nonlinear systems; UKF uses sigma points instead
  • Model mismatch (wrong QQ or RR) causes overconfidence, not just bias

Exercises

ExerciseCore

Problem

A scalar state evolves as xt+1=xt+wtx_{t+1} = x_t + w_t with wtN(0,1)w_t \sim \mathcal{N}(0, 1). Observations are zt=xt+vtz_t = x_t + v_t with vtN(0,4)v_t \sim \mathcal{N}(0, 4). Starting from x^00=0\hat{x}_{0|0} = 0, P00=1P_{0|0} = 1, compute x^11\hat{x}_{1|1} and P11P_{1|1} given z1=3z_1 = 3.

ExerciseAdvanced

Problem

Show that the steady-state Kalman gain for the scalar system xt+1=xt+wtx_{t+1} = x_t + w_t, zt=xt+vtz_t = x_t + v_t with Q=qQ = q, R=rR = r satisfies K=(r+r2+4qr)/(2r)K_\infty = (-r + \sqrt{r^2 + 4qr})/(2r). What happens as q/r0q/r \to 0 and as q/rq/r \to \infty?

References

Canonical:

  • Anderson & Moore, Optimal Filtering (1979), Chapters 2-5
  • Simon, Optimal State Estimation (2006), Chapters 5-7

Current:

  • Sarkka, Bayesian Filtering and Smoothing (2013), Chapters 4-5

  • Bishop, Pattern Recognition and Machine Learning (2006), Chapter 13.3

  • Murphy, Machine Learning: A Probabilistic Perspective (2012)

  • Hastie, Tibshirani, Friedman, The Elements of Statistical Learning (2009)

Next Topics

  • Particle filters: sequential Monte Carlo for nonlinear, non-Gaussian systems
  • Hidden Markov models: discrete-state analogue of the Kalman filter
  • GraphSLAM and factor graphs: batch optimization formulations that extend Kalman filtering to simultaneous localization and mapping

Last reviewed: April 2026

Prerequisites

Foundations this topic depends on.

Next Topics