Kalman Filter
March 24, 2026 · View on GitHub
Overview & Motivation
In any real system, sensors are noisy and models are imperfect. The Kalman filter answers a deceptively simple question: given a noisy measurement and an imperfect prediction, what is the best estimate of the true state?
The answer is an optimal, recursive, minimum-variance estimator for linear systems with Gaussian noise. At each time step it performs two operations:
- Predict — propagate the state and covariance forward using the system model.
- Update — correct the prediction using the new measurement, weighted by the Kalman gain, which automatically balances trust in the model vs. trust in the sensor.
The filter is computationally lightweight (matrix operations on small state vectors), requires no storage of past measurements, and adapts its confidence in real time via the covariance matrix.
Mathematical Theory
State-Space Model
Discrete-time linear system with process noise and measurement noise :
where:
- — state vector
- — measurement vector
- — state transition matrix ()
- — control input matrix ()
- — measurement matrix ()
- — process noise covariance ()
- — measurement noise covariance ()
Predict Step
Update Step
Optimality
The Kalman filter is the minimum mean-square error (MMSE) estimator among all linear estimators. Under the assumption that and are Gaussian, it is also the MMSE among all estimators (linear or not).
Complexity Analysis
| Operation | Time | Space | Notes |
|---|---|---|---|
| Predict | Matrix multiply | ||
| Update | Dominated by ( inversion) and gain computation | ||
| Total per step | For , approximately |
For typical embedded use with and , each step completes in microseconds.
Step-by-Step Walkthrough
System: Estimating position and velocity from noisy position measurements.
State: , s.
Initial: ,
Measurement: (true position = 1.0)
Predict:
Update:
The filter quickly moves toward the measurement because the initial covariance is large (low confidence). Over subsequent steps, shrinks and the gain decreases — the filter becomes more reliant on the model.
Pitfalls & Edge Cases
- Model mismatch. If the true system is nonlinear or the noise is non-Gaussian, the Kalman filter is suboptimal. Consider the Extended Kalman Filter (EKF) or Unscented Kalman Filter (UKF) for moderate nonlinearities.
- Covariance divergence. Numerical errors can cause to lose positive-definiteness over time. Symmetrize after each update; consider a square-root or UD factorization form for long-running filters.
- Tuning and . These are rarely known exactly. Increasing makes the filter more responsive (trusts model less); increasing makes it smoother (trusts measurements less). Tune empirically or use adaptive methods.
- Innovation covariance singularity. If is singular, the measurement does not provide new information in some direction. Regularize or reduce the measurement model.
- Missing measurements. If no measurement is available, skip the update step entirely and only predict. The covariance will grow, correctly reflecting increasing uncertainty.
- Fixed-point caution. Matrix inversions and multiplications in the update step can overflow Q15/Q31 ranges. Use floating-point or carefully scale all matrices.
Variants & Generalizations
| Variant | Key Difference |
|---|---|
| Extended Kalman Filter (EKF) | Linearizes nonlinear and around the current estimate |
| Unscented Kalman Filter (UKF) | Propagates sigma points through nonlinearities; avoids explicit Jacobians |
| Square-root Kalman Filter | Maintains instead of for improved numerical stability |
| Information Filter | Works with the inverse covariance (information matrix); better for multi-sensor fusion |
| Kalman Smoother | Uses future measurements to refine past estimates (offline, non-causal) |
| Adaptive Kalman Filter | Estimates and online from innovation statistics |
Applications
- GPS/INS navigation — Fusing inertial measurements (high rate, drifty) with GPS (low rate, noisy).
- Object tracking — Radar, lidar, or camera-based tracking of moving targets.
- Sensor fusion — Combining accelerometer, gyroscope, and magnetometer for attitude estimation.
- Process control — State estimation for model-based controllers (LQG = LQR + Kalman).
- Battery state-of-charge estimation — Estimating internal states from voltage and current measurements.
- Econometrics — Estimating latent economic variables from noisy indicators.
Connections to Other Algorithms
graph LR
KF["Kalman Filter"]
LQR["LQR Controller"]
DARE["DARE Solver"]
PID["PID Controller"]
KF -->|"state estimate"| LQR
DARE -->|"steady-state gain"| KF
KF -->|"filtered measurement"| PID
| Algorithm | Relationship |
|---|---|
| LQR Controller | The Kalman filter + LQR = LQG (Linear Quadratic Gaussian), the separation principle |
| DARE Solver | The steady-state Kalman gain can be found by solving a DARE (dual of the LQR DARE) |
| PID Controller | Kalman-filtered measurements can serve as the PID's process variable input |
References & Further Reading
- Kalman, R.E., "A New Approach to Linear Filtering and Prediction Problems", Journal of Basic Engineering, 82(1), 1960.
- Simon, D., Optimal State Estimation: Kalman, H∞, and Nonlinear Approaches, Wiley, 2006.
- Bar-Shalom, Y., Li, X.R. and Kirubarajan, T., Estimation with Applications to Tracking and Navigation, Wiley, 2001.