- Two noise terms make the model honest: process noise with covariance Q, and measurement noise with covariance R.
- Predict moves the state with F and grows the covariance with F P Fᵀ + Q.
- Correct compares the reading z with what we expected to see, H x⁻. The gap is the innovation.
- The Kalman gain K = P⁻Hᵀ(H P⁻ Hᵀ + R)⁻¹ is the 1D gain P⁻/(P⁻ + R) written with matrices.
- Through the off-diagonal of P⁻, a position reading also corrects the velocity.
Adding noise to the model
The state-space model of slide 4 was perfect physics. Real robots get bumped and real sensors are noisy, so we add one noise term to each equation:
w is the process noise: gusts, wheel slip, everything the model leaves out. Its covariance Q plays the role Q played in 1D. v is the measurement noise, with covariance R, the matrix version of the GPS variance R. The true state is hidden: we never see it. We keep a best estimate x and its covariance P, and update both every tick. From here, x means our estimate of the state.
The five equations, side by side
The left side is lesson 2. The right side is the same rhythm for vectors. If you only need a recipe, this is it: write F, H, Q and R for your system and run the loop. The rest of the slide shows where each line comes from, on one running example: x = (30, 5) (30 m, 5 m/s), P with 4 and 1 on the diagonal, F = 1101, Q = I, H = 10, R = 4, and a GPS reading z = 38. The first worked example below collects the whole cycle.
Predict: the transform rule plus Q
Move the state with the model: x⁻ = F x + B u. Moving a vector by F moves its covariance by F P Fᵀ, the rule from slide 3. Then add Q for the bumps the model ignores. The ellipse grows, because we moved without looking.
Correct: fuse in the sensor's space, then come back
The GPS reads one number, but the state has two. We cannot fuse things of different sizes, so first we turn the prediction into a predicted reading: H x⁻, with variance H P⁻ Hᵀ (slide 3 again). Now we have two estimates of the same reading: H x⁻ from the model, and z from the sensor with variance R.
Fuse them with the lesson 1 rule. Its gain was σ₁² / (σ₁² + σ₂²). Here σ₁² is H P⁻ Hᵀ, the variance of the model's predicted reading, and σ₂² is R, the sensor's variance. Call the total S = H P⁻ Hᵀ + R. With matrices, "divide by S" becomes "multiply by the inverse S⁻¹".
A quick word on the inverse. For one number, S⁻¹ is 1/S. For a matrix, S⁻¹ is the matrix that undoes S: S⁻¹S = I. For a diagonal matrix, flip each diagonal entry: 100010⁻¹ = 0.1000.1. Bigger ones you leave to the computer: np.linalg.inv in the lab.
But we want to correct the state, not the reading. The rule in one plain sentence: each state number is moved by (its covariance with the reading) ÷ S. For H = 10, the reading is the position, so "covariance with the reading" means "covariance with the position": the first column of P⁻ (6 and 1). We divide that column by S. A number strongly linked to the position moves a lot; an unlinked one does not move. In matrix form:
K is the Kalman gain. The gap z − H x⁻ is the innovation: how much the reading surprised us.
Why this works (optional)
Two facts make the rule above the right one. You can skip this part on a first read.
First, P⁻Hᵀ really is the covariance between each state number and the predicted reading. The state's deviation is d and the reading's deviation is H d. Since (H d)ᵀ = dᵀHᵀ, we get d (H d)ᵀ = d dᵀ Hᵀ, and its average is P⁻ Hᵀ, by the same reasoning as slide 3.
Second, this K gives exactly the fused reading from the lesson 1 rule. One step at a time:
This K moves each state number in proportion to how strongly it is linked to the position, so an unlinked number does not move at all.
Keep reading with the full course
Finish lesson 3 and you will be able to: track position and velocity in 2D with the matrix Kalman filter.
Still locked here:
- The rest of this explanation
- 3 more examples with step-by-step solutions
- Five extra members-only problems with worked solutions
$20 once, lifetime access. Lessons 1 and 2 stay free.
Examples
Example 1 · One full cycle in numbers
Δt = 1 s. Start at x = (30, 5): 30 m, 5 m/s. P = 4001, F = 1101, Q = I, H = 10, R = 4. The GPS reads z = 38.
Show solutionHide solution
The position variance fell from 6 to 2.4 as the GPS pinned it down. The velocity moved too, from 5 to 5.3, and its variance fell from 2 to 1.9. An off-diagonal of 0.4 remains: position and velocity errors are still linked. That one update is the whole Kalman filter, in numbers.
Example 2 · Velocity learned from position
Start at x = (0, 2), P = I, Δt = 1, Q = 0, R = 1. The GPS reads 3.
Show solutionHide solution
The robot was 1 m further than expected, so the filter decides it was faster than it thought: velocity up from 2 to 2.33 m/s. The velocity variance fell from 1 to 2/3 without any speed sensor.

Questions and comments
Stuck on something, or found a mistake? Ask here and I'll answer. You sign in with GitHub.