Extended Kalman Filter (EKF): Equations, Example and Why It Fails
The Extended Kalman Filter (EKF) is the most widely used state estimator for nonlinear systems. It applies the Kalman filter to a first-order Taylor linearization of the nonlinear process and measurement models around the current estimate. This page gives the EKF equations, a worked example, the difference to the linear Kalman filter, and, in the second half, why the EKF so often becomes inconsistent and what to use instead.
Nonlinear state-space model
The EKF assumes a discrete-time model with additive noise
\[ \mathbf{x}(k) = \mathbf{f}\left(\mathbf{x}(k-1), \mathbf{u}(k-1)\right) + \mathbf{z}(k-1) \]
\[ \mathbf{y}(k) = \mathbf{h}\left(\mathbf{x}(k)\right) + \mathbf{v}(k) \]
where \( \mathbf{f} \) is the nonlinear process model, \( \mathbf{h} \) the nonlinear measurement model, and \( \mathbf{z} \) and \( \mathbf{v} \) are zero-mean process and measurement noise with covariances \( \mathbf{Q}_d \) and \( \mathbf{R} \). The notation follows the Kalman filter page.
Jacobians
Instead of the matrices \( \mathbf{A}_d \) and \( \mathbf{C} \), the EKF uses the Jacobians of \( \mathbf{f} \) and \( \mathbf{h} \), evaluated at the most recent estimate:
\[ \mathbf{F}(k-1) = \left. \frac{\partial \mathbf{f}}{\partial \mathbf{x}} \right\vert _{\mathbf{x}(k-1), \mathbf{u}(k-1)} , \qquad \mathbf{H}(k) = \left. \frac{\partial \mathbf{h}}{\partial \mathbf{x}} \right\vert _{\mathbf{x}(k\vert k-1)} . \]
Note the evaluation points: the process Jacobian uses the last updated estimate, the measurement Jacobian the predicted estimate.
EKF equations
Prediction
\[ \mathbf{x}(k\vert k-1) = \mathbf{f}\left(\mathbf{x}(k-1), \mathbf{u}(k-1)\right) \]
\[ \mathbf{P}(k\vert k-1) = \mathbf{F}(k-1)\mathbf{P}(k-1)\mathbf{F}(k-1)^T + \mathbf{Q}_d(k-1) \]
Update
\[ \boldsymbol{\nu}(k) = \mathbf{y}(k) - \mathbf{h}\left(\mathbf{x}(k\vert k-1)\right) \]
\[ \mathbf{S}(k) = \mathbf{H}(k)\mathbf{P}(k\vert k-1)\mathbf{H}(k)^T + \mathbf{R}(k) \]
\[ \mathbf{K}(k) = \mathbf{P}(k\vert k-1)\mathbf{H}(k)^T\mathbf{S}(k)^{-1} \]
\[ \mathbf{x}(k) = \mathbf{x}(k\vert k-1) + \mathbf{K}(k)\boldsymbol{\nu}(k) \]
\[ \mathbf{P}(k) = \left(\mathbf{I} - \mathbf{K}(k)\mathbf{H}(k)\right)\mathbf{P}(k\vert k-1)\left(\mathbf{I} - \mathbf{K}(k)\mathbf{H}(k)\right)^T + \mathbf{K}(k)\mathbf{R}(k)\mathbf{K}(k)^T \]
Two details matter: the state is propagated and the measurement is predicted with the nonlinear functions \( \mathbf{f} \) and \( \mathbf{h} \); the Jacobians are used only for the covariance and the gain. The covariance update is written in the Joseph form, which is the safer choice in an EKF because the gain is computed from an approximate covariance anyway. The vector \( \boldsymbol{\nu}(k) \) is the innovation and \( \mathbf{S}(k) \) its covariance, which feed the NIS consistency test.
EKF vs. Kalman filter
The EKF reduces exactly to the linear Kalman filter when the process and measurement models are linear: then \( \mathbf{f}(\mathbf{x},\mathbf{u}) = \mathbf{A}_d\mathbf{x} + \mathbf{B}_d\mathbf{u} \), \( \mathbf{h}(\mathbf{x}) = \mathbf{C}\mathbf{x} \), and the Jacobians are \( \mathbf{F} = \mathbf{A}_d \) and \( \mathbf{H} = \mathbf{C} \).
| Kalman filter (KF) | Extended Kalman filter (EKF) | |
|---|---|---|
| Models | linear | nonlinear, differentiable |
| Covariance propagation | exact | first-order approximation |
| Gain | can be precomputed offline | depends on the estimate, computed online |
| Optimality | best linear MMSE estimator | no optimality guarantee |
| Typical risk | wrong noise tuning | linearization error, inconsistency, divergence |
A broader comparison including the Unscented and Cubature Kalman filter is on the page KF vs. EKF vs. UKF.
Example: tracking a target with radar
A target moves in the plane with a constant-velocity model, state \( \mathbf{x} = [p_x, v_x, p_y, v_y]^T \). A radar at the origin measures range and bearing,
\[ \mathbf{h}(\mathbf{x}) = \begin{bmatrix} \sqrt{p_x^2 + p_y^2} \\ \operatorname{atan2}(p_y, p_x) \end{bmatrix}, \qquad \mathbf{H} = \begin{bmatrix} p_x/r & 0 & p_y/r & 0 \\ -p_y/r^2 & 0 & p_x/r^2 & 0 \end{bmatrix} \]
with \( r = \sqrt{p_x^2 + p_y^2} \). The motion model is linear, so the prediction is the standard Kalman filter prediction with \( \mathbf{F} = \mathbf{A}_d \); only the measurement needs linearization. The bearing component of the innovation must be wrapped to \( (-\pi, \pi] \).
Typical implementation pitfalls in this example are: forgetting to wrap angular innovations, evaluating \( \mathbf{H} \) at the old instead of the predicted state, and predicting the measurement with \( \mathbf{H}\mathbf{x} \) instead of \( \mathbf{h}(\mathbf{x}) \). Checking the Jacobian against finite differences once during development catches most remaining errors. To judge whether the filter is consistent, evaluate the NEES in simulation and the NIS on real data.
Why the EKF often fails, and what to use instead
TL;DR: The Extended Kalman Filter (EKF) often underestimates uncertainty on nonlinear systems, can become inconsistent or even diverge, is brittle to modeling/tuning errors, and struggles with constraints and multi-modal posteriors. Modern alternatives—Unscented/σ-point filters, smoothing/factor-graph methods, particle filters, or optimization-based Moving Horizon Estimation—are usually safer and more accurate.
The Core Problems
1. Linearization error → bias, inconsistency, and divergence
EKF relies on first-order Taylor expansions of your process and measurement models. When the system is meaningfully nonlinear between updates, the approximation injects bias and the covariance becomes too optimistic—a classic route to inconsistency and eventual divergence. This has been observed repeatedly in navigation, control, and SLAM applications.
2. Broken observability from local linearizations
In coupled, partially observed systems (e.g., SLAM), evaluating Jacobians at the latest estimate can change the observable subspace of the linearized system, producing mathematically inconsistent updates (the filter appears confident while being wrong). Observability-based analyses pin this down as a fundamental failure mode of EKF-SLAM.
3. Can’t represent non-Gaussian or multi-modal posteriors
Even with Gaussian process/measurement noise, nonlinear transformations produce skewed or multi-modal posteriors. EKF’s single mean/covariance is a poor fit in these cases; decades of work motivated σ-point and particle approaches precisely because EKF’s first-order moment matching is inadequate.
4. Fragile in practice: Jacobians, tuning, and maintenance
EKF needs correct, differentiable models and hand-crafted Jacobians. Small algebra mistakes, unmodeled latencies, or mis-calibration can quietly corrupt estimates. Classic surveys note that EKF works best only when the system is “almost linear on the timescale of updates.”
5. Constraints are awkward
Physical constraints (positivity, bounds, contact/no-slip, geometry) are hard to enforce in a Gaussian filter. Workarounds (projection, clamping, inflation) are ad hoc. Optimization-based estimators incorporate constraints natively.
Better Defaults (and When to Use Them)
Unscented / σ-point Kalman Filters (UKF)
When: You want a drop-in Kalman-style recursion with better nonlinear handling and no Jacobians.
See the Unscented Kalman Filter and the parameter-free Cubature Kalman Filter.
Why better: Deterministic sigma points propagate mean/covariance through nonlinearities more accurately than first-order linearization; robustness improves with only a modest compute increase.
Smoothing & Factor Graphs (Gauss–Newton, LM, √SAM, iSAM)
When: You can batch or slide a window and care about global consistency (robotics/SLAM/VIO, sensor fusion).
Why better: Solve a nonlinear least-squares problem over a trajectory or window. This respects system structure and observability and avoids EKF’s myopia; sparse linear algebra yields scalable, stable solutions.
Moving Horizon Estimation (MHE)
When: You need constraints, robust loss functions, or strong nonlinearities—and can afford per-step optimization.
Why better: MHE explicitly optimizes over a finite history, enforces constraints, and often outperforms EKF on challenging systems.
Particle Filters / Ensemble Methods
When: Posteriors are strongly non-Gaussian or multi-modal, state dimension is moderate, or you need full Bayesian flexibility.
Why better: Particle filters represent arbitrary distributions (at higher compute cost). Ensemble Kalman filters (EnKF) offer a practical middle ground for large-scale systems, with proven success in geosciences.
If You Must Stick with a Kalman-Style Filter
Consider error-state (for attitude: the multiplicative EKF) or invariant formulations (better geometry, stability) and, where feasible, second-order terms. These can reduce—but not eliminate—EKF’s structural issues.
Practical Decision Checklist
Use EKF only if most of these are true:
- Dynamics & measurements are nearly linear between updates.
- Models and calibrations are excellent; unmodeled effects are small.
- You can derive and maintain correct Jacobians.
- You don’t need hard constraints or multi-modal beliefs.
- You’ll monitor residuals/NEES/NIS and use covariance inflation or gating if needed.
If not, reach for UKF, smoothing/factor graphs, MHE, or particle/ensemble methods—your future self (and your stability plots) will thank you.
References
- Julier & Uhlmann, Unscented Filtering and Nonlinear Estimation, Proc. IEEE, 2004 — Foundational critique of EKF and σ-point alternative.
- Bailey et al., Consistency of the EKF-SLAM Algorithm, 2006 — Demonstrates inconsistency in EKF-SLAM.
- Huang, Mourikis, & Roumeliotis, Observability-based Rules for Designing Consistent EKF-SLAM Estimators, IJRR, 2010 — Observability explanation for inconsistency.
- Haseltine & Rawlings, Critical Evaluation of Extended Kalman Filtering and Moving-Horizon Estimation, 2005 — Constraints and MHE vs EKF.
- Dellaert & Kaess, Square Root SAM: SLAM via Square Root Information Smoothing, IJRR, 2006 — Factor-graph alternative to EKF.
- Wan & van der Merwe, The Unscented Kalman Filter for Nonlinear Estimation, 2000 — Practical UKF introduction.
- Arulampalam et al., A Tutorial on Particle Filters for Online Nonlinear/Non-Gaussian Tracking, IEEE TSP, 2002 — Particle filters for non-Gaussian posteriors.
- Evensen, The Ensemble Kalman Filter: Theoretical Formulation and Practical Implementation, 2003 — Ensemble methods at scale.