S939 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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?

Name it

The model

xk+1=Axk+Buk+wk,yk=Cxk+vk

with independent zero-mean noises of covariance Rw (process) and Rv (measurement).

The two steps

Predict with the model, and grow the uncertainty:

x^k−=Ax^k−1+Buk−1,Pk−=APk−1AT+Rw

Update with the measurement, weighting it by the Kalman gain:

Kk=Pk−CT(CPk−CT+Rv)−1,x^k=x^k−+Kk(yk−Cx^k−),Pk=(I−KkC)Pk−

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 P−2−QP−−QR=0:

P−=Q+Q2+4QR2,K=P−P−+R,P=KR

The update x^←x^+K(y−x^) is an exponential average with weight K.

Continuous time and duality

For x˙=Ax+w, y=Cx+v with noise intensities Rw, Rv, the steady-state filter has gain L=PCTRv−1, where AP+PAT−PCTRv−1CP+Rw=0: the LQR's Riccati equation with A→AT, B→CT, Q→Rw, R→Rv. For one state, L=a+a2+Rw/Rv and the error pole is at −a2+Rw/Rv.

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
  1. Noise variances. Q=0.0025R=0.25
  2. Prior variance. P−=Q+Q2+4QR2=0.0263
  3. Gain and posterior variance. K=P−P−+R=0.0951P=KR=0.0238
  4. The estimate's spread. It has σ = 0.154 °C, about a third of the sensor's.
  5. What the filter is. It's an exponential average with weight 0.095, remembering about 1/K ≈ 10.5 samples.
  6. 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
  1. Gain. K=0.040.04+0.25=0.138
  2. Update the estimate. It moves 13.8% of the way toward the reading: x^=20.0+0.138×0.6=20.08°C
  3. Update the variance. P=(1−0.138)×0.04=0.0345
  4. 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
  1. Inverse-variance weights. 1/0.25=41/0.04=25
  2. Share of the better sensor. 25/29=0.862
  3. Fused variance. σ2=14+25=0.0345σ=0.186°C better than either sensor alone.
  4. 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 x˙=0.5x+w is measured as y=x+v, with noise intensities Rw = 0.1, Rv = 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 P−?

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°.

Explain why

Why does the Kalman gain fall when the measurements are noisier?

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.