Interactive Monograph · State Estimation

Kalman and particle filters, in plain words

Every useful quantity in a vehicle, the charge in a pack, the speed of a rotor, the position of a car, is hidden behind noisy, incomplete sensors. A filter is the disciplined way to guess the hidden truth and to know how much to trust the guess. This monograph builds the Kalman filter and its nonlinear successors from scratch, each one running live in your browser.

01 / The problem

Guessing a hidden truth from noisy clues

Suppose you want to know exactly how full a battery is. You cannot measure charge directly; you measure voltage, which is noisy and only loosely related to charge. You also know something about how charge changes: current out means charge down. A filter fuses these two imperfect sources, a model of how the state evolves and a stream of noisy measurements, into a single best estimate, updated every instant.

The trick that makes filtering powerful is that it tracks not just a best guess but an uncertainty around it. When the model is trusted, the estimate leans on prediction; when a clean measurement arrives, it leans on that. The whole method is a rhythm of two steps repeated forever:

The rhythm

Predict: use the model to project the state forward; uncertainty grows. Update: fold in the new measurement; uncertainty shrinks. Repeat.

The Kalman filter is the exact, optimal version of this rhythm when everything is linear and the noise is Gaussian. Its extensions, covered later, keep the rhythm when the world is nonlinear or the uncertainty is not a tidy bell curve.

02 / The idea

A belief that breathes

Picture your belief about the state as a bell curve: a center (best guess) and a width (uncertainty). The predict step slides the center along with the model and widens the curve, because projecting forward adds doubt. The update step meets the measurement and narrows the curve, snapping the center toward the reading by an amount set by the Kalman gain, the filter's trust in the measurement versus the model.

PREDICT project state, grow uncertainty UPDATE fold in measurement, shrink it prior belief corrected belief, next step new sensor reading enters here ↑
The two-step cycle. Prediction and correction hand the belief back and forth. Every loop, the model pushes the estimate forward and the sensor pulls it back toward reality; the gain decides who wins.

See it track

A hidden signal drifts along; you only see the noisy dots. The filter, knowing just that the signal moves slowly, produces the smooth estimate and the shaded uncertainty band. Turn up the measurement noise and the filter leans harder on its model; turn up the process noise and it chases the dots more eagerly.

0.5 0.02
filtered error = raw sensor error =
true state measurements filter estimate
Live 1D Kalman filter. The estimate stays far cleaner than the raw sensor because it remembers the past through its model. The band is the filter's own reported uncertainty, and the true signal should mostly stay inside it.
03 / The equations

The whole filter on one card

With state estimate x and its variance P, model step and noise Q, measurement z with noise R, the cycle is five short lines. The gain K is the star: near 1 it trusts the sensor, near 0 it trusts the model.

Predict
xᶕ = f(x)    P ← P + Q

Update
K = P / (P + R)   the Kalman gain
x ← xᶕ + K · (z – xᶕ)   nudge toward the reading
P ← (1 – K) · P   uncertainty shrinks

In more than one dimension these become matrix versions, with the gain a matrix and P a covariance, but the meaning is identical. The quantity z minus the prediction, the innovation, is the surprise in each measurement; a filter that is working well produces small, patternless innovations, and a filter whose innovations suddenly grow is telling you something has changed, the seed of fault detection.

04 / Two dimensions

Tracking a moving object

Give the filter a state of position and velocity and a model that says position advances by velocity, and it becomes a tracker. It sees only noisy positions, yet by estimating the unmeasured velocity it smooths the path and predicts through gaps. The uncertainty is now an ellipse, wide along directions the measurements constrain poorly.

8
true path noisy fixes estimate uncertainty ellipse
Live 2D tracker. The constant-velocity model lets the filter infer where the object is heading, so the estimate cuts through the scatter of raw fixes. The ellipse is the position covariance; it swells during prediction and tightens at each fix.
05 / Nonlinear

When the world curves: the extended filter

The plain Kalman filter assumes straight-line relationships. Real sensors rarely oblige. A battery's open-circuit voltage is a curved function of charge; a range sensor sees distance, not coordinates. The extended Kalman filter handles this by linearizing on the fly: at each step it replaces the curve with its tangent line (a derivative) at the current best guess, then runs the ordinary Kalman update on that local approximation.

The unscented Kalman filter takes a different route: instead of a derivative, it pushes a small set of carefully chosen sample points through the true nonlinear function and reads off the resulting mean and spread. It is often more accurate and needs no hand-derived Jacobians, at a modest extra cost. Both keep the predict-update rhythm intact.

Battery charge from voltage, live

Here the extended filter estimates state of charge from a noisy voltage reading through the same curved voltage law used in the companion vehicle monograph. It starts from a deliberately wrong initial guess. Watch it lock onto the true charge within a few steps and then track it down through the discharge, its uncertainty band collapsing as the measurements do their work.

-0.30 0.010
estimate error =
true SoC EKF estimate uncertainty
Live extended Kalman filter. Even from a bad start the estimate converges, because each voltage reading, run through the linearized voltage curve, corrects the charge guess. This is exactly how a battery management system reports state of charge you can trust.
Ties to PINN & the Vehicle, which fits the same battery voltage model from data. There the network learns the curve; here the filter assumes it and estimates the hidden charge behind it.
06 / Non-Gaussian

When one bell curve is not enough: particles

Linearizing works until the belief itself stops being a single hump. If a measurement is ambiguous, the truth could sit in two places at once, no bell curve can express that. The particle filter throws away the formula and represents the belief by a swarm of hundreds of candidate states, each a little hypothesis about the truth.

MOVE WEIGHby measurement fit RESAMPLEkeep the fit ones ESTIMATE
The particle filter loop. Move every hypothesis by the model, score each by how well it explains the new measurement, breed the good ones and drop the bad, then read the swarm's center as the estimate.

Below is the classic hard test: a signal whose measurement depends on its square, so a reading of four could mean plus or minus two. Watch the particle swarm split, hedge across both possibilities, and collapse onto the truth once the model breaks the tie, something no single bell curve could do.

400 1.0
tracking error =
true state particles estimate
Live particle filter. Each faint dot is one hypothesis; the cloud's shape is the full belief, free to be lopsided or split. More particles mean a richer belief at higher cost, the central tradeoff of the method.
07 / In the vehicle

Where these filters earn their keep

State estimation is quietly everywhere in a modern vehicle. A few of the load-bearing uses:

BMS SoC / SoHsensorless position & speedIMU + GPS fusionparticle-filter RULinnovation fault flags
08 / In the series

Three ways to know a hidden state

This monograph completes a trio of very different answers to the same question, how to reason about what you cannot directly see:

They share a spine. The filter's innovation, the PINN's physics residual, and the diffusion model's denoising error are three flavors of the same idea: measure how far reality departs from expectation, and treat that gap as both the correction signal and the alarm.

Companions: PINNs from Scratch · PINN & the Vehicle · Diffusion Models. See also the series overview.
09 / Practice

What actually goes wrong

10 / References

Where to go deeper

  1. Kalman, R. E. (1960). A New Approach to Linear Filtering and Prediction Problems. Journal of Basic Engineering. The founding paper.
  2. Julier, S. & Uhlmann, J. (1997). A New Extension of the Kalman Filter to Nonlinear Systems. SPIE. The unscented filter.
  3. Gordon, N., Salmond, D. & Smith, A. (1993). Novel Approach to Nonlinear and Non-Gaussian Bayesian State Estimation. IEE Proceedings F. The bootstrap particle filter.
  4. Arulampalam, M. et al. (2002). A Tutorial on Particle Filters for Online Nonlinear/Non-Gaussian Bayesian Tracking. IEEE Trans. Signal Processing.
  5. Thrun, S., Burgard, W. & Fox, D. (2005). Probabilistic Robotics. The standard modern treatment of filters for estimation.
  6. Simon, D. (2006). Optimal State Estimation: Kalman, H-infinity, and Nonlinear Approaches. A thorough engineering reference.
  7. Plett, G. (2015). Battery Management Systems, Vol. 2: Equivalent-Circuit Methods. Kalman-family SoC estimation in depth.
11 / Glossary

Terms in one line

State
The hidden quantities you want to know, such as charge, position, or rotor angle.
Process noise (Q)
How much the model is allowed to be wrong from step to step.
Measurement noise (R)
How noisy each sensor reading is.
Covariance (P)
The filter's own estimate of how uncertain it is, a width or an ellipse.
Kalman gain (K)
The trust dial that blends model prediction with new measurement.
Innovation
Measurement minus prediction, the surprise; small and patternless when healthy.
Extended KF
Handles nonlinearity by linearizing the model at the current estimate.
Unscented KF
Handles nonlinearity by propagating sample points, no derivatives needed.
Particle filter
Represents any belief by a weighted swarm of candidate states.
Resampling
Culling low-weight particles and duplicating high-weight ones.
Observability
Whether the measurements contain enough information to recover a state.