- The filter is a loop: predict (P grows by Q), then correct (P is multiplied by (1 − K)).
- The growth and the shrink balance, so P settles at a steady state instead of running away.
- High R: small K, a smooth estimate that is slow to react, and drifts if R is far too high.
- High Q: big K, the filter snaps to every GPS reading and gets jumpy.
The rhythm
Walk with your eyes closed for one step, peek, adjust. Step, peek, adjust. Each step makes you a bit less sure. Each peek makes you a bit more sure. You never get lost, and you never shake around like the blurry peeks themselves. That rhythm is the whole filter.
The loop
At every time step n the filter does:
Then it hands x̂ and P to the next step. That is the entire 1D Kalman filter: three steps, five equations. It only needs to remember two numbers between steps.
Here is the loop on the robot from slides 1 and 2, with the filter's two noise numbers set to the real sensors: Q = 0.25, the process noise variance (how much each encoder move can be off), and R = 4.84, the measurement noise variance (how noisy the GPS is):
Over the 30 steps in this picture the RMS errors are about 3.1 m for dead reckoning, 2.4 m for the GPS, and 0.9 m for the Kalman estimate. The filter beats both of its sensors.
Two steps by hand
Start where slide 4 stopped: x̂ ≈ 36.07 m with P ≈ 3.21 (Q = 1, R = 9). The encoder says u = 5 m again, and the GPS reads z = 40 m.
The steady state
Dead reckoning's P grew forever. Here it does not. When P⁻ is small, K is small and the correct step barely shrinks it, so the predict step wins and P grows. When P⁻ is big, K is big and the correct step shrinks it hard. P settles where the two balance. In the big picture above, the blue band quickly reaches a fixed width and stays there.
Steady means every step looks the same as the last one. So P⁻ is the same number each time, and the predict step brings P back up to it: P + Q = P⁻, or P = P⁻ − Q. The correct step says P = P⁻R/(P⁻ + R).
This is a quadratic equation in P⁻. The quadratic formula gives two roots. A variance can't be negative, so we keep the + root:
With Q = 1 and R = 9, as in the two steps above:
The GPS alone has σ = 3 m. The filter settles at about half that, and it stays there no matter how long the robot drives.
Tuning: two knobs
In a real robot, you do not know the true noise exactly. You choose Q and R, and that choice is called tuning.
R too high (you distrust the GPS): K is small, corrections are gentle and the estimate leans on the smooth prediction. Smooth, but slow to react. Push R far too high and the filter drifts like the encoder.
Q too high (you distrust the encoder): P⁻ balloons, K grows, and the filter snaps to each GPS reading. It gets jumpy, like raw GPS.
For the robot in the picture, the steady-state gain shows this directly:
A neat fact: only the ratio Q/R moves the estimate, as long as P starts at 0. Compare two tunings, (Q, R) = (1, 9) and (2, 18), for the first two steps:
Every P⁻ doubled, and so did P⁻ + R, so K stayed the same. The rule: multiply Q and R by the same number, and every K, and so the Kalman line, stays exactly the same. Only the band changes. (If P started at, say, 4, that starting 4 would not double, and the line would change a little.) A good starting point is to set R to the GPS's real variance from its datasheet, and Q to the encoder's real variance per step.
A bigger example: the first six steps of the picture
Here are the first six steps of the robot in the big picture, by hand. These readings come from the picture's own noise draw, not from the lab, so the lab's numbers will be different. The start is known: x̂ = 2 m, P = 0. The filter uses Q = 0.25 and R = 4.84.
The gain starts tiny, because at first the filter trusts its known start more than a 2.2 m GPS. Then K and P climb toward their steady values for this Q = 0.25 and R = 4.84: K ≈ 0.20 and P ≈ 0.98, from the steady-state formula (worked out in the examples below). The computer runs the same three steps, five equations, for every step after this, thousands of times if needed.
Where this shows up
This exact loop runs inside drones for altitude (a barometer, which senses height from air pressure, plus an accelerometer, which senses changes in speed), in robot vacuums for heading, and in phones for the blue dot. Tuning Q and R is the first thing an engineer does when a filter feels "laggy" or "twitchy".
Next: the whole lesson on one page, with a free lab to try any Q, R and sensor noise.
Examples
Example 1 · Two steps from a fresh start
Start at x̂ = 0 m with P = 1. The filter uses Q = 1 and R = 3. Step 1: u = 2 m, z = 2.5 m. Step 2: u = 2 m, z = 3.6 m.
Show solutionHide solution
The second GPS reading was below the prediction, so the estimate moved down. P went 1 → 2 → 1.2 → 2.2 → 1.27: up by Q, down by the correction, again and again.
Example 2 · Where the lab robot's P settles
The lab robot uses Q = 0.25 and R = 4.84. Where does P end up?
Show solutionHide solution
The GPS alone has σ = 2.2 m. The filter settles below 1 m, so its ±2σ band is about ±2 m. That is the band you'll see in the lab once you set R = 4.84 (the lab starts at R = 50).
Example 3 · The tuning knobs on the lab's robot
These numbers come from the lab's longer 80-step run, not the 30-step picture above. The lab robot has a real encoder σ of 0.5 m per step (Q = 0.25) and a real GPS σ of 2.2 m (R = 4.84). With the same noise, compare RMS errors:
Show solutionHide solution
Matched noise values beat both sensors by a wide margin. Mistuning either knob throws much of that gain away.
Example 4
Your estimate trails behind the robot every time it speeds up, and the line looks very smooth. Your colleague's estimate shakes around with every GPS reading. Which knob does each of you turn, and which way?
Show solutionHide solution
Smooth but lagging means K is too small: lower R or raise Q, so the filter listens to the GPS more.
Shaky means K is too big: raise R or lower Q, so the filter leans on its prediction more. Only the ratio Q/R matters, so turning either knob works.
Example 5
The filter sits at P = 1 when the robot enters a tunnel. For 10 steps there is no GPS (Q = 0.25). Then a GPS reading arrives with R = 4.84. Find P before that reading, and K and P after it.
Show solutionHide solution
Ten predict steps: P⁻ = 1 + 10 · 0.25 = 3.5 (σ ≈ 1.87 m).
K = 3.5 / (3.5 + 4.84) ≈ 0.42, and P = (1 − 0.42) · 3.5 ≈ 2.03. The first reading after the tunnel gets a big gain, because the filter knows it has been guessing.

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