Unscented Kalman Filter

March 23, 2026 · View on GitHub

Overview & Motivation

The Extended Kalman Filter (EKF) linearizes nonlinearities using Jacobians. This works well for mild nonlinearities, but the first-order approximation can introduce significant errors when:

  • The nonlinear functions are highly curved (large second derivatives).
  • The state uncertainty is large (the linearization point is far from the true state).
  • Jacobians are difficult or expensive to derive analytically.

The Unscented Kalman Filter (UKF) addresses all three problems by replacing linearization with a deterministic sampling approach. Instead of approximating the nonlinear function, it approximates the probability distribution by choosing a small set of carefully weighted sample points — called sigma points — and propagating them through the true nonlinear function. The statistics (mean and covariance) are then reconstructed from the transformed points.

This captures the true mean and covariance to second-order accuracy for any nonlinearity, without computing a single Jacobian.

Mathematical Theory

Sigma Point Generation

Given state estimate x^Rn\hat{x} \in \mathbb{R}^n and covariance PP, generate $2n+1$ sigma points:

σ0=x^\sigma_0 = \hat{x} σi=x^+((n+λ)P)i,i=1,,n\sigma_i = \hat{x} + \left(\sqrt{(n + \lambda) P}\right)_i, \quad i = 1, \ldots, n σi+n=x^((n+λ)P)i,i=1,,n\sigma_{i+n} = \hat{x} - \left(\sqrt{(n + \lambda) P}\right)_i, \quad i = 1, \ldots, n

where (M)i\left(\sqrt{M}\right)_i denotes the ii-th column of the matrix square root (Cholesky decomposition M=LLTM = LL^T, using columns of LL), and:

λ=α2(n+κ)n\lambda = \alpha^2 (n + \kappa) - n

Weights

w0(m)=λn+λ,w0(c)=λn+λ+(1α2+β)w_0^{(m)} = \frac{\lambda}{n + \lambda}, \quad w_0^{(c)} = \frac{\lambda}{n + \lambda} + (1 - \alpha^2 + \beta) wi(m)=wi(c)=12(n+λ),i=1,,2nw_i^{(m)} = w_i^{(c)} = \frac{1}{2(n + \lambda)}, \quad i = 1, \ldots, 2n

Parameters:

  • α\alpha: Controls spread of sigma points ($10^{-4} \leq \alpha \leq 1$). Smaller values keep points closer to the mean.
  • β\beta: Incorporates prior knowledge about the distribution (β=2\beta = 2 is optimal for Gaussian).
  • κ\kappa: Secondary scaling parameter (typically κ=0\kappa = 0 or κ=3n\kappa = 3 - n).

Predict Step

  1. Propagate sigma points through the nonlinear state transition:

σi=f(σi,u)\sigma_i^* = f(\sigma_i, u)

  1. Reconstruct predicted state and covariance:

x^k=i=02nwi(m)σi\hat{x}_k^- = \sum_{i=0}^{2n} w_i^{(m)} \sigma_i^* Pk=i=02nwi(c)(σix^k)(σix^k)T+QP_k^- = \sum_{i=0}^{2n} w_i^{(c)} (\sigma_i^* - \hat{x}_k^-)(\sigma_i^* - \hat{x}_k^-)^T + Q

Update Step

  1. Generate new sigma points from the predicted state x^k\hat{x}_k^- and PkP_k^-.

  2. Transform sigma points through the measurement function:

zi=h(σi)z_i = h(\sigma_i)

  1. Predicted measurement and covariances:

z^k=i=02nwi(m)zi\hat{z}_k = \sum_{i=0}^{2n} w_i^{(m)} z_i Sk=i=02nwi(c)(ziz^k)(ziz^k)T+RS_k = \sum_{i=0}^{2n} w_i^{(c)} (z_i - \hat{z}_k)(z_i - \hat{z}_k)^T + R Pxz=i=02nwi(c)(σix^k)(ziz^k)TP_{xz} = \sum_{i=0}^{2n} w_i^{(c)} (\sigma_i - \hat{x}_k^-)(z_i - \hat{z}_k)^T

  1. Kalman gain and state update:

Kk=PxzSk1K_k = P_{xz} S_k^{-1} x^k=x^k+Kk(zkz^k)\hat{x}_k = \hat{x}_k^- + K_k (z_k - \hat{z}_k) Pk=PkKkSkKkTP_k = P_k^- - K_k S_k K_k^T

Complexity Analysis

OperationTimeSpaceNotes
Sigma point genO(n3)O(n^3)O(n2)O(n^2)Dominated by Cholesky decomposition
State propagationO((2n+1)cf)O((2n+1) \cdot c_f)O(n2)O(n^2)cfc_f = cost of evaluating f(x)f(x)
Mean/cov reconstructO(n2(2n+1))O(n^2 \cdot (2n+1))O(n2)O(n^2)Weighted outer products
UpdateO(n2m+m3)O(n^2 m + m^3)O(nm)O(nm)Same as standard Kalman for the gain computation
Total per stepO(n3+n2m)O(n^3 + n^2 m)O(n2+nm)O(n^2 + nm)Cholesky and sigma point propagation dominate

For n10n \leq 10, the additional cost over EKF is small — and the elimination of Jacobian derivation is a significant engineering benefit.

Step-by-Step Walkthrough

System: Same pendulum as the EKF example, x=[θ,θ˙]Tx = [\theta, \dot\theta]^T, n=2n = 2, Δt=0.1\Delta t = 0.1 s.

Parameters: α=0.1\alpha = 0.1, β=2\beta = 2, κ=0\kappa = 0λ=1.98\lambda = -1.98.

Initial: x^0=[0.3,0]T\hat{x}_0 = [0.3, 0]^T, P0=diag(0.5,0.5)P_0 = \text{diag}(0.5, 0.5).

  1. Generate 5 sigma points from x^0\hat{x}_0 and P0P_0 using Cholesky of P0P_0.
  2. Propagate each sigma point through f(x)f(x) (pendulum dynamics).
  3. Reconstruct x^1\hat{x}_1^- and P1P_1^- from the weighted transformed points.
  4. Generate new sigma points from x^1\hat{x}_1^- and P1P_1^-.
  5. Transform through h(x)=θh(x) = \theta for the measurement update.
  6. Compute SS, PxzP_{xz}, KK and update state and covariance.

The UKF naturally captures the curvature of sinθ-\sin\theta without computing cosθ\cos\theta — the sigma points "feel" the nonlinearity directly.

Pitfalls & Edge Cases

  • Covariance non-positive-definiteness. Numerical errors or extreme sigma point spread can make PP lose positive-definiteness, causing the Cholesky decomposition to fail. Use a small regularization term or the square-root UKF variant.
  • Alpha tuning. Very small α\alpha (e.g., $10^{-4})cancausethezerothweight) can cause the zeroth weight w_0^{(c)}tobenegative,leadingtonegativecovariancecontributions.Largerto be negative, leading to negative covariance contributions. Larger\alpha (e.g., \0.1$) is safer for low-dimensional systems.
  • Sigma point overflow. For fixed-point types, the scaled columns (n+λ)P\sqrt{(n+\lambda)P} may exceed the representable range. Use float for the UKF or carefully bound the covariance.
  • Non-Gaussian distributions. The UKF assumes a Gaussian approximation. For multi-modal or heavily skewed distributions, consider particle filters.
  • Computational cost. For large state dimensions (n>20n > 20), the $2n+1sigmapointsandsigma points andO(n^3)$ Cholesky become significant. Consider sparsification or reduced-rank approximations.

Variants & Generalizations

  • Square-Root UKF (SR-UKF). Propagates the Cholesky factor SS (where P=SSTP = SS^T) instead of PP directly, using QR decompositions and rank-1 Cholesky updates. Guarantees positive-definiteness and improves numerical stability.
  • Augmented UKF. Augments the state vector with the process and measurement noise vectors, generating sigma points in the joint space. Captures correlations between state and noise at the cost of more sigma points ($2(n + n_w + n_v) + 1$).
  • Reduced Sigma Point Filters. Use fewer than $2n + 1sigmapoints(e.g.,theSphericalSimplexUKFusessigma points (e.g., the Spherical Simplex UKF usesn + 2$ points) to reduce computation for large state dimensions.
  • UKF with Control Input. The state transition becomes f(x,u)f(x, u) and each sigma point is propagated as f(σi,u)f(\sigma_i, u). Supported in the implementation via the ControlSize template parameter.
  • Cubature Kalman Filter (CKF). A special case of the UKF with α=1\alpha = 1, β=0\beta = 0, κ=0\kappa = 0, using third-degree spherical-radial cubature rules. Simpler weight computation with no negative weights.

Comparison with Other Filters

FilterJacobian Required?Accuracy OrderHandles High Nonlinearity?Computational Cost
Kalman FilterNo (linear only)Exact (linear)NoLowest
EKFYes1st orderModerateLow
UKFNo2nd orderGoodModerate
ParticleNoArbitraryExcellentHigh

Applications

  • Attitude estimation — Quaternion-based orientation estimation (avoiding gimbal lock and Jacobian complexity).
  • Target tracking — Radar/lidar tracking with range-bearing measurements (highly nonlinear in Cartesian coordinates).
  • Robotics — State estimation for mobile robots and manipulators with nonlinear kinematics.
  • Chemical processes — Concentration estimation in nonlinear reaction kinetics.
  • Power systems — Dynamic state estimation in electrical grids with nonlinear power flow equations.

Connections to Other Algorithms

graph LR
    UKF["Unscented Kalman Filter"]
    KF["Kalman Filter"]
    EKF["Extended Kalman Filter"]
    CHO["Cholesky Decomposition"]
    UKF -->|"linear limit"| KF
    EKF -->|"alternative to"| UKF
    CHO -->|"sigma points"| UKF
AlgorithmRelationship
Kalman FilterThe UKF reduces to the standard KF when ff and hh are linear
Extended Kalman FilterUses Jacobians instead of sigma points; simpler but less accurate for nonlinear cases
Cholesky DecompositionUsed internally to generate sigma points from the covariance matrix

References & Further Reading

  • Julier, S.J. and Uhlmann, J.K., "A New Extension of the Kalman Filter to Nonlinear Systems", in Proc. AeroSense, 1997.
  • Julier, S.J. and Uhlmann, J.K., "Unscented Filtering and Nonlinear Estimation", Proceedings of the IEEE, 92(3), 2004.
  • Wan, E.A. and van der Merwe, R., "The Unscented Kalman Filter for Nonlinear Estimation", in Proc. IEEE Adaptive Systems for Signal Processing, 2000.
  • Simon, D., Optimal State Estimation: Kalman, H∞, and Nonlinear Approaches, Wiley, 2006 — Chapter 14.