Skip to content
Tactiverge

School/✦ Research Engineer/Week 17

The Kalman gain as the variance-minimising weight

Why P/(P + R)? Not a guess, not a rule of thumb: it is the only weight that makes the error as small as possible.

About 45 min · 3 goals · Checked by automated tests

1.Why should I care?

The gain is the filter's only decision: how much to believe the newest measurement. Deriving it yourself shows that the Kalman filter is just inverse-variance weighting applied again and again, with the prediction as one of the two sensors.

  • ◇ Derive the scalar Kalman gain by minimising the posterior error variance.
  • ◇ Interpret K at its limits and as the steady-state gain.
  • ◇ Compute the steady-state variance for a random-walk model.

2.Predict

The prediction has variance P⁻ = 3 and the measurement R = 1. The best gain K is…

Guess first. Being wrong here is how the surprise works.

3.Discover

Set R small (0.1) and step: K stays near 1, and the estimate jumps to every fix. Set R large (5): K is small and the estimate glides. Then fix R = 1 and step 15 times: watch K settle to a constant. That constant is the steady-state gain.

Loading the interactive…

Can't use the interactive? Read a description instead

The derivation is fully written in text. The stepper's readout reports the gain at every update, so the convergence to a steady gain can be followed as numbers.

4.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1 · a fresh version every time

After predicting, a 1-D Kalman filter's variance is P = 2 m². The camera measurement variance is R = 0.25 m². What is the Kalman gain K?

5.Watch

→ Match each equation on screen to predict or update, and spot the gain formula in its matrix form.

Walks through the predict and update equations of the Kalman filter one line at a time, including what the gain and covariances mean.

Length: see YouTube · 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.

6.Understand

Reading the gain

K → 1 when R ≪ P⁻: trust the sensor, x ≈ z. K → 0 when R ≫ P⁻: trust the prediction, ignore the reading. K is not a tuning knob you set; it is computed from the variances you believe. What you tune are Q and R.

Steady state

With constant Q and R the variance stops changing. For the random-walk model x[k+1] = x[k] + u + w, the prior variance converges to P⁻∞ = (Q + √(Q² + 4QR))/2. With Q = 0.3, R = 2: P⁻∞ ≈ 0.939, K∞ ≈ 0.319. Many embedded filters precompute this constant gain.

In more dimensions

For vector states, K = P⁻Hᵀ(HP⁻Hᵀ + R)⁻¹ and P = (I − KH)P⁻, where H maps the state to what the sensor sees. The scalar case is H = 1. The same minimum-variance argument, done with matrices, gives the same structure.

Explain it another way

The gain is a trust dial between 'my model says' and 'my sensor says', set automatically from how unsure each one is right now.

Derivation: The scalar Kalman gain
  1. Update rule: x = x⁻ + K(z − x⁻) = (1 − K)x⁻ + Kz. Prediction error e⁻ has variance P⁻; measurement error v has variance R; they are independent.

  2. Posterior error e = (1 − K)e⁻ + K·v (the true x cancels because both terms are unbiased).

  3. Its variance: P(K) = (1 − K)²P⁻ + K²R.

  4. Minimise: dP/dK = −2(1 − K)P⁻ + 2KR = 0 ⇒ K = P⁻/(P⁻ + R).

  5. Substitute back: P = (1 − K)P⁻ = P⁻R/(P⁻ + R), i.e. 1/P = 1/P⁻ + 1/R: inverse-variance weighting, again.

Worked example 1

Q = 0.3, R = 2. Find the steady-state prior variance, gain and posterior variance.

P⁻∞ = (0.3 + √(0.09 + 2.4))/2 ≈ 0.939. K∞ = 0.939/2.939 ≈ 0.319. P∞ = (1 − 0.319) × 0.939 ≈ 0.639.

Common mix-ups

  • K is a gain you tune by hand.
    ✓ K is computed from P⁻ and R. You tune the noise models Q and R; the gain follows.
  • The Kalman filter is a different idea from averaging.
    ✓ Its update is inverse-variance weighting of the prediction and the measurement.

7.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

A random-walk filter has Q = 1 and R = 1. What is the steady-state gain K∞ (3 decimal places)?

Practice 3

A filter is told R = 0 (a perfect sensor). What does it do at each update?

Practice 4 · a fresh version every time

A rover's estimate is x = 5 m with variance P = 2 m². It drives u = 3 m (process noise Q = 2 m²), then a landmark fix reads z = 10 m with R = 1 m². After predict and update, what is the new estimate x, in m?

m

Practice 5

P⁻ = 4 m², R = 1 m². What is the posterior variance P, in m²?

m²

8.Apply it

In the stepper, measure the gain after 15 steps for Q = 0.2 and three values of R (0.5, 1, 2). Compare with the steady-state formula. Then explain, in one sentence each, what physically changing Q and R would mean for a rover.

9.Reflect

10.Go further

Research mode: limits and open questions

Comparing a filter's gain sequence with its innovation sequence is a standard diagnostic: in a well-tuned filter, innovations are white (uncorrelated in time) with variance HP⁻Hᵀ + R.

    Concepts: Kalman filtering · Bayesian estimation