S9 · Lesson 39 · The Kalman filter
Estimating a state from noisy measurements by blending a model's prediction with each new measurement, the discrete predict and update steps, the steady-state gain from the noise ratio, the continuous-time filter as the dual of the LQR, and LQG control
An observer's gain was chosen by hand: fast enough to track, slow enough not to amplify noise. Rudolf Kálmán showed in 1960 that if you know how noisy the measurements are and how much random disturbance the plant receives, there's one best gain, and it can be computed recursively, one measurement at a time. The Kalman filter guided Apollo to the Moon and now runs in every GPS receiver, phone and drone. This lesson builds it from the simplest case, a single noisy reading of a drifting quantity.
- A quantity that drifts as a random walk (variance Q added each step) is measured with noise of variance R. The plot shows the steady-state Kalman gain K and the estimate's standard deviation (relative to the sensor's) against the ratio Q/R.
- When the quantity barely drifts (Q/R small), the filter trusts its prediction: K is small and the estimate averages many readings, so it's far less noisy than the sensor.
- When it drifts fast, K approaches 1 and the filter simply follows the latest measurement.
Predict
A sensor reading a constant has noise with standard deviation 0.5 °C. After 25 readings, how good can the best estimate be?
For a constant, the Kalman filter reduces to the running average, and averaging n independent readings divides the standard deviation by √n: 0.5/5 = 0.1 °C. Its gain after the nth reading is 1/n, which is exactly how a running average updates.
Name it
The model
with independent zero-mean noises of covariance (process) and (measurement).
The two steps
Predict with the model, and grow the uncertainty:
Update with the measurement, weighting it by the Kalman gain:
The filter is an observer whose gain changes with time, settling to a constant for a time-invariant system.
One state
For a random walk, A = C = 1 with variances Q and R, the steady-state prior variance solves :
The update is an exponential average with weight K.
Continuous time and duality
For , with noise intensities , , the steady-state filter has gain , where : the LQR's Riccati equation with , , , . For one state, and the error pole is at .
LQG
The LQR fed by a Kalman filter's estimate is optimal for linear plants with Gaussian noise and quadratic cost (the separation principle again). But its margins aren't guaranteed (Doyle, 1978), so LQG designs must be checked for robustness like any other.
Worked example
A temperature drifts by a random walk with σ = 0.05 °C per sample, and its sensor has σ = 0.5 °C. Find the steady-state filter.
Show the solution
- Noise variances.
- Prior variance.
- Gain and posterior variance.
- The estimate's spread. It has σ = 0.154 °C, about a third of the sensor's.
- What the filter is. It's an exponential average with weight 0.095, remembering about 1/K ≈ 10.5 samples.
- Check. Iterating the predict and update equations from any starting variance converges to the same numbers.
Answer the steady-state gain is K = 0.0951, and the estimate has σ = 0.154 °C, about a third of the sensor's.
Worked example
The filter's prior is 20.0 °C with variance 0.04, and the sensor (variance 0.25) reads 20.6 °C. What's the update?
Show the solution
- Gain.
- Update the estimate. It moves 13.8% of the way toward the reading:
- Update the variance.
- Why the step is small. A confident prior and a noisy sensor mean a small step.
Answer the estimate moves to 20.08 °C, with variance 0.0345.
Worked example
Two sensors measure the same temperature, one with σ = 0.5 °C and one with σ = 0.2 °C. How should they be combined, and how good is the result?
Show the solution
- Inverse-variance weights.
- Share of the better sensor.
- Fused variance. better than either sensor alone.
- The Kalman view. This is the Kalman update with the first sensor as the prior; adding a poor sensor still helps, a little.
Answer weight each by its inverse variance, so the better sensor gets 0.862 of the weight; the result has σ = 0.186 °C.
Check
A random walk with step variance 0.01 is measured with noise variance 0.1. What's the steady-state Kalman gain?
Check
For the same filter, what's the standard deviation of the estimate after each update?
Check
A constant is measured 4 times with noise σ = 1. What's the best estimate's standard deviation?
Check
A prior estimate 10 with variance 0.02 meets a measurement of 10 + (1) with noise variance 1. What's the updated estimate?
Check
A continuous-time state is measured as , with noise intensities = 0.1, = 1. What's the steady-state Kalman gain?
Check
A prior variance 0.04 meets a measurement with noise variance 0.1. What's the variance after the update?
Check
Two independent sensors measure the same quantity, with σ = 0.5 and σ = 0.1.
(a)
What is the standard deviation of the best combination?
(b)
What weight does the first sensor get?
Check
A random walk with step variance Q is measured with noise variance R; the Kalman filter has reached steady state.
Step 1
What is the prior variance ?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is the gain K?
Step 3
What is the posterior variance?
Explain why
Why does the Kalman gain fall when the measurements are noisier?
The gain sets how far each update moves the estimate toward the new measurement, and the filter chooses it to minimize the estimate's variance. A noisy measurement carries little information compared with the prediction, so the best compromise moves only a short way toward it; a precise measurement is worth trusting and gets a large gain. The formula says exactly this: K is the prediction's uncertainty as a share of the total, so larger measurement noise R shrinks it. In steady state this makes the filter average over more readings when the sensor is poor, at the cost of following real changes more slowly.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.