Kalman Smoother (RTS Smoother)
April 4, 2026 · View on GitHub
Overview & Motivation
The Kalman filter is a causal estimator: its state estimate at time uses only observations up to and including time . When the full observation sequence is available (offline/batch setting), the Rauch-Tung-Striebel (RTS) smoother refines every filtered estimate by incorporating future measurements. The result is the minimum-mean-square-error (MMSE) state estimate given the entire sequence .
The RTS smoother is the prerequisite for the Expectation-Maximization (EM) algorithm for Kalman Filter parameter identification: the E-step requires smoothed means, smoothed covariances, and the lag-1 cross-covariance in order to form the sufficient statistics used by the M-step.
Mathematical Theory
State-Space Model
with .
Forward Pass (Kalman Filter)
For :
Initialise (t = 0 only):
Update:
Log-likelihood contribution:
where = MeasurementSize. The total is .
Predict (for ):
Backward Pass (RTS Smoother)
Initialise at :
For :
Smoother gain:
Smoothed mean and covariance:
Lag-1 Cross-Covariance
The EM M-step requires .
Initialisation (Shumway & Stoffer, 1982):
Recursion for :
Note: is undefined; index 0 of lagCrossCovariances is always zero.
Complexity Analysis
| Case | Time | Space | Notes |
|---|---|---|---|
| All | stack | Dominant cost: solves at each step |
All storage is stack-allocated via std::array. There is no heap usage.
Step-by-Step Walkthrough
Consider a 1-D constant-position model (, , ) with , , , , , , and observations .
Forward pass:
| 0 | 1.0 | 2.0 | 0.500 | 0.250 | 0.500 |
| 1 | 0.600 | 1.600 | 0.375 | 0.363 | 0.375 |
| 2 | 0.475 | 1.475 | 0.322 | 0.620 | 0.322 |
Backward pass ( then ):
: ;
: ;
Notice how the smoothed incorporates all three observations, whereas the filtered only used the first.
Pitfalls & Edge Cases
- Near-singular : The smoother gain is computed via
SolveSystem(Gaussian elimination with partial pivoting) rather than explicit matrix inversion. If the predicted covariance becomes near-singular (possible when ), numerical accuracy degrades. Ensure has positive diagonal entries. - Joseph-form update: The standard update is numerically unstable for finite-precision arithmetic. This implementation uses the Joseph form to maintain positive semi-definiteness.
lagCrossCovariances[0]is always zero: The lag-1 cross-covariance for index 0 () is undefined. The first valid entry is index 1 ().- Unsigned loop guard: The backward loop uses
std::size_t; the break guardif (t == 0) breakprevents unsigned wrap-around. - Stack usage: For large or , the five internal
std::arraymembers dominate stack usage. ChooseMaxStepsconservatively on resource-constrained targets.
Variants & Generalizations
- Square-root RTS smoother: Propagates Cholesky factors instead of full covariance matrices for improved numerical conditioning.
- Information filter smoother: Operates in the dual (information) domain; preferable when observations are dense relative to state transitions.
- Extended / Unscented smoother: Replace the linear forward pass with EKF or UKF; the backward pass equations remain identical in form.
Applications
- EM parameter identification: Used as the E-step by
ExpectationMaximizationto compute the sufficient statistics for the M-step. - Offline trajectory estimation: Position/velocity smoothing in GNSS post-processing and inertial navigation.
- Batch signal denoising: Any application where the full observation sequence is available before estimation begins.
Connections to Other Algorithms
filters::KalmanFilter: The forward pass ofKalmanSmootherreplicates the KF update equations. The smoother is applied after the filter, not instead of it.estimators::ExpectationMaximization: The smoother is owned and invoked byExpectationMaximizationas its E-step. Users who only need EM should interact withExpectationMaximizationdirectly.solvers::GaussianElimination: Used for all matrix "division" operations (smoother gain, Kalman gain) to avoid explicit matrix inversion.solvers::CholeskyDecomposition: Used to compute for the log-likelihood.
References & Further Reading
- Rauch, H. E., Tung, F., & Striebel, C. T. (1965). Maximum likelihood estimates of linear dynamic systems. AIAA Journal, 3(8), 1445–1450.
- Shumway, R. H., & Stoffer, D. S. (1982). An approach to time series smoothing and forecasting using the EM algorithm. Journal of Time Series Analysis, 3(4), 253–264.
- Shumway, R. H., & Stoffer, D. S. (2000). Time Series Analysis and Its Applications. Springer. (Chapter 6)
- Särkkä, S. (2013). Bayesian Filtering and Smoothing. Cambridge University Press. (Chapter 8)