TL;DR
A Kalman filter estimates a hidden state that moves by a linear rule and is seen only through noisy measurements. It keeps two things: a best guess of the state, which is a mean vector, and how uncertain that guess is, which is a covariance matrix. Each step it predicts forward, which makes the uncertainty grow, then corrects the guess with the new measurement, which makes the uncertainty shrink. When the noise is Gaussian, these two updates give the exact mean and covariance of the state's posterior.
Where you'll see it: in GPS and inertial navigation on phones, aircraft and spacecraft, in robot localization and object tracking, and in control loops that need an estimate of the state they cannot measure directly.
Intuition
Tracking a boat in fog
Suppose you are tracking a boat in fog. You know roughly where it was a moment ago and how fast it was moving. That gives you a prediction of where it is now, but the prediction is fuzzy because currents and wind push the boat in ways you did not model. Then a radar gives you a noisy fix on its position. You do not fully trust the prediction and you do not fully trust the radar. You blend them, leaning on whichever one is more reliable at that moment.
That blend is the whole filter. If the prediction is very uncertain, you lean on the radar. If the radar is very noisy, you lean on the prediction. The weight that controls this blend is called the Kalman gain, and the filter computes it for you from the two uncertainties.
Why the filter exists
A robot's sensors each give partial, noisy information. Wheel encoders measure how far the wheels turned, but slip ruins that. GPS gives position, but it is slow and jumpy. An inertial sensor gives acceleration, but errors pile up when you integrate them. If you trust only the latest reading, your estimate jitters. If you average the whole history, you respond too slowly and ignore the motion you already know about.
The Kalman filter sits between these extremes. It combines a model of how the state moves with each new measurement, and it stores only the last estimate and its uncertainty. It never needs the full history. Each cycle has the same two steps:
flowchart LR A[previous estimate and uncertainty] --> B[predict: move the state forward, uncertainty grows] B --> C[new measurement arrives] C --> D[update: blend prediction and measurement, uncertainty shrinks] D --> A
The picture also shows how uncertainty behaves over time. Without measurements it typically grows, because the motion model is imperfect. Each measurement cuts it down. The plot below shows this for a constant value measured repeatedly with noise variance 4, starting from a prior variance of 10.
- posterior variance after k measurements
The math
The hidden state evolves and is observed by Here is the state at step , is the state transition matrix, is a known control input with matrix , and is process noise with covariance . The measurement is , read through the measurement matrix , with measurement noise of covariance .
The filter tracks a belief about given all measurements up to step . The belief is Gaussian, so it is fully described by a mean and a covariance . A superscript minus marks the prediction made before the measurement arrives. The standard forms of the mean and covariance appear in the linear dynamical system lesson, and the covariance rule below depends on the Covariance Matrix lesson.
The predict step
The mean moves by the motion model. The covariance is pushed through the same linear map, which gives , and then the independent process noise adds . The added always increases uncertainty, which is the honest effect of an imperfect model.
The update step
Let the innovation be the part of the measurement the prediction did not expect:
The Kalman gain, the weight on the innovation, and the corrected estimate are
The update is Bayes' rule applied to two Gaussians: the prior from the prediction and the likelihood of the measurement. A product of two Gaussians is again Gaussian, so the posterior has a closed form.
Where the gain comes from, in one dimension
Take a scalar state with prior mean and variance , and a measurement with noise variance . The posterior density is proportional to a Gaussian in with variance times a Gaussian in with variance centred on . Their precisions add:
- Posterior precision: .
- Solve for : .
- Define . Then , which is the matrix formula with .
- The posterior mean is the precision-weighted average of and , which rearranges to .
So the gain is the prior variance divided by the sum of the two variances. If the measurement is very precise, is small and is near 1, so the filter follows the sensor. If the prior is very precise, is small and is near 0, so the filter ignores the sensor.
Worked examples
A sensor reads a constant voltage . The model is , , , , because the voltage does not move. The measurement noise variance is . The prior is mean and variance , a weak belief.
Measurement 1 arrives with .
- Predict: nothing changes, so and .
- Gain: .
- Mean: .
- Variance: .
- Check: , so .
Measurement 2 arrives with .
- Predict: , so and .
- Gain: .
- Mean: .
- Variance: .
- Check: , so .
Interpretation: the estimate is 4.0, not the simple average of the readings, 4.8. The prior at 0 still has a small weight, because it is precision against for each reading. A precision-weighted average confirms it: . The variance fell from 10 to 1.67, a factor of six, after two readings.
Now the state is a cart with position and velocity, . Over one second with constant velocity, . The sensor reads position only, so , with and for clarity. Start from with . The sensor reads .
- Predicted mean: .
- Predicted covariance: .
- Innovation variance: .
- Gain: .
- Innovation: .
- Mean: .
- Covariance: .
Interpretation: the sensor measures position only, yet the velocity estimate also changed, from 1 to 1.67. That happens because the predicted covariance has an off-diagonal term of 1, so position and velocity are correlated. An error in position is partly an error in velocity, and the filter uses the correlation to spread the correction to both. Here the gain on velocity is , half the gain on position. The new covariance is symmetric and smaller in every direction than the prediction.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Nonlinear motion or sensor, such as a turning robot or a range-bearing sensor | The linear model is wrong, and linearizing it introduces error. The extended Kalman filter can diverge | Unscented Kalman filter, which propagates sample points through the nonlinearity, or a particle filter |
| Non-Gaussian noise, such as sensor outliers or a belief with several peaks | A single Gaussian cannot represent the belief, and one bad reading can pull the estimate far off | Robust updates that down-weight outliers, or a particle filter |
| Wrong or | If is too small or too large, the filter becomes sluggish. If is too large or too small, it becomes overconfident and jumpy | Estimate the noise levels from logged data, and check that the innovations have the variance predicts |
| Large state vector | Storing and inverting costs memory that grows with the square of the state size and time that grows with its cube | Reduce the state, or use a sparse or factored form |
| Round-off over long runs | loses symmetry or positive definiteness, and the filter fails | Joseph form, , which keeps symmetric |
| A state that no sensor sees | Its variance never shrinks, so the estimate stays uncertain. Heading with no compass or magnetometer is an example | Add a sensor that observes the state, or accept and report the uncertainty |
| Offline analysis, when you can wait for all the data | The filter uses only past data, so early estimates are poor | A smoother such as the Rauch–Tung–Striebel smoother, which uses future measurements too |
History
Rudolf E. Kálmán published the linear filter in 1960, in a paper on linear filtering and prediction. With Richard Bucy he wrote the continuous-time version in 1961. The problem was navigation and tracking, where the earlier approach, the Wiener filter, was awkward to compute for multidimensional state.
Stanley Schmidt at NASA Ames adapted the idea to nonlinear trajectory estimation in the early 1960s. That adaptation became the basis of the extended Kalman filter, which was used in the navigation software for the Apollo program. The filter caught on because it is a fixed recursion over a small state: digital computers of the time could run it on each measurement, and it needed to store only the current estimate and its covariance. It is now used in phones, aircraft and robots, mostly without anyone naming it.
Check yourself
QuestionWhat two quantities does a Kalman filter store between steps, and what does each one describe?Show answer
It stores the mean , the best estimate of the hidden state, and the covariance , which describes how uncertain that estimate is and how the uncertainties of the state components are correlated. Together they describe the whole Gaussian belief, so nothing about older measurements needs to be kept.
QuestionA scalar prior has mean 2 and variance 4. A measurement arrives with and noise variance . Find the gain, the posterior mean and the posterior variance.Show answer
The gain is . The posterior mean is . The posterior variance is . Check: , so .
QuestionWhy does the predict step increase the covariance even when no measurement arrives?Show answer
The motion model is imperfect. The process noise represents the part of the motion that the model does not capture, and it adds variance at every step. Pushing the old covariance through can also spread it out. Without a measurement to cut it down, the uncertainty keeps growing, so the update step is the only place it shrinks.
QuestionA sensor is replaced by a much more precise one, so drops toward zero. What happens to the gain, and how does the estimate behave?Show answer
The gain approaches 1, so the posterior mean moves almost all the way to the measurement and the posterior variance approaches . The filter now trusts the sensor. The estimate follows each reading closely, so it is responsive, but it also passes through the sensor's noise. The filter has no way to smooth noise it is told to believe.