School/✦ Research Engineer/Week 15
The predict–update cycle
Drive a metre: your uncertainty grows. See a landmark: it shrinks. Repeat forever. That rhythm is the whole idea of a filter.
About 45 min · 3 goals · Checked by automated tests
1.Why should I care?
This is the loop running inside every rover, drone and phone that knows where it is. Once you can step it by hand, the Kalman filter stops being a formula and becomes a story: predict, get surprised, correct by the right amount.
- ◇ Run the predict and update steps of a one-dimensional estimator by hand.
- ◇ Explain the roles of process noise Q and measurement noise R.
- ◇ Evaluate an estimator against ground truth in simulation using RMSE and a consistency check.
2.Discover
Step predict → update ten times in clear skies and watch the band settle to a steady width. Reset, switch on dust, and step again: note how wide the band gets during the gaps. Check after each update that the green truth line stays inside the ±2σ band most of the time.
Loading the interactive…
Can't use the interactive? Read a description instead
The Kalman stepper plots truth, landmark fixes and the estimate with a ±2σ band over 20 steps. Each button press updates a text readout with the estimate, σ, truth, error and gain.
3.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1 · a fresh version every time
A rover's estimate is x = 10 m with variance P = 1 m². It drives u = 1 m (process noise Q = 2 m²), then a landmark fix reads z = 10 m with R = 3 m². After predict and update, what is the new estimate x, in m?
4.Predict
During a dust storm the camera fix is unavailable for 5 steps in a row. What happens to the filter's variance P?
Guess first. Being wrong here is how the surprise works.
5.Understand
Predict
Push the estimate through the model: x⁻ = x + u (here, the commanded move) and P⁻ = P + Q. Q is the variance the model adds each step: wheel slip, gusts, anything unmodelled. Prediction always increases uncertainty.
Update
When a measurement z with variance R arrives, compute the innovation z − x⁻, the gain K = P⁻/(P⁻ + R), then x = x⁻ + K(z − x⁻) and P = (1 − K)P⁻. This is the conjugate normal update from week 13 with the prediction as prior.
Checking a filter honestly
In simulation you know the truth, so measure RMSE of x − x_true. Also check consistency: about 95% of errors should fall within ±2√P. If the truth often leaves the band, the filter is overconfident (Q or R too small); if it never comes close to the edge, it is too cautious.
Explain it another way
You are walking in fog. Each step you are a little less sure where you are. When a lamppost appears you correct, more if you trust your eyes, less if the fog is thick.
With constant Q and R the variance converges to a steady state: prior variance P⁻∞ = (Q + √(Q² + 4QR))/2, giving a constant steady-state gain. Many embedded filters just use that constant gain.
x = 0, P = 1, u = 1, Q = 0.25: x⁻ = 1, P⁻ = 1.25. z = 1.6, R = 0.5: K = 1.25/1.75 ≈ 0.714, x = 1 + 0.714 × 0.6 ≈ 1.43, P = 0.286 × 1.25 ≈ 0.357.
BUILD 006's rover uses exactly this cycle: odometry predicts, a landmark photo updates. Its Level 2 numbers, odometry σ = 1 m meeting a camera σ = 0.5 m, give K = 0.8 and a fused σ ≈ 0.45 m.
Worked example 1
x = 0, P = 1 m². Drive u = 1 m with Q = 0.25 m². Fix z = 1.6 m with R = 0.5 m². Predict and update.
x⁻ = 1, P⁻ = 1.25. K ≈ 0.714. x ≈ 1.43 m, P ≈ 0.357 m² (σ ≈ 0.60 m).
Common mix-ups
- A low RMSE proves the filter is right.
✓ It must also be consistent: its own σ should match its actual errors, or downstream decisions will be over- or under-cautious. - The update step can increase uncertainty.
✓ For a correct linear-Gaussian model P = (1 − K)P⁻ is always smaller than P⁻. A surprising measurement moves x a lot, but P still shrinks.
6.Watch
→ Listen for the two reasons given for a filter: noisy measurements, and quantities you cannot measure at all.
Builds intuition for estimating what you can't measure directly when your sensors are noisy.
6 min 47 s · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2
A filter has P = 0.4 m² after an update. Q = 0.3 m² per step. With no fixes for 6 steps, what is P, in m²?
Practice 3
In simulation, the true position leaves the filter's ±2σ band on 40% of steps. The most likely problem is…
Practice 4 · a fresh version every time
After predicting, a 1-D Kalman filter's variance is P = 1 m². The camera measurement variance is R = 2 m². What is the Kalman gain K?
8.Apply it
In the stepper, run 20 steps in dusty conditions with Q = 0.2 and R = 1. Record the error and √P at each step and compute the fraction of steps where |error| < 2√P. Repeat with Q set ten times too small (in your head, the filter's Q, not the truth's). What changes?
9.Reflect
Concepts: Kalman filtering · Sensor fusion · Bayesian estimation