3.5.22 · D2Guidance, Navigation & Control (GNC)

Visual walkthrough — Kalman gain — minimizes trace of covariance

2,769 words13 min readBack to topic

Step 1 — Two blurry guesses on one number line

WHAT. Imagine we want to know one number: call it (say, a rocket's altitude in metres). We are never told exactly. Instead we have two foggy opinions about it.

  • A prediction — the little minus sign means "before we look at the sensor." It came from a physics model.
  • A measurement — a number a sensor reported.

WHY start here. Everything in the Kalman filter is about combining these two foggy opinions into one sharper opinion. Before we can combine them, we have to draw them honestly: not as sharp points, but as bell-shaped fog. A wide fog means "I'm not sure"; a narrow fog means "I'm confident."

PICTURE. Below, the blue fog is the prediction and the pink fog is the measurement. The horizontal axis is the value of . The width of each hill is its uncertainty.

Figure — Kalman gain — minimizes trace of covariance

Step 2 — The error is what we actually want to shrink

WHAT. We do not get to see , so we cannot measure "how wrong am I?" directly. But we can reason about it. Define the error If our guess is perfect, . If we guess too high, is negative; too low, positive.

In particular, the pre-update error — the error of the prediction, before we touch the sensor — gets its own name and its own minus sign to match : Its average squared size is exactly the prediction fog from Step 1: .

WHY this quantity. We cannot minimise "distance from the truth" if we insist on a single guaranteed number — the noise makes every trial different. So we minimise it on average, over many imagined trials. The honest score is the mean squared error: Here means "average over all the ways the noise could have played out," and (the trace) means "add up the diagonal" — for one number it is just the variance itself. We square the error so that being wrong by is exactly as bad as being wrong by .

PICTURE. The error is the gap between the true spike (yellow) and our guess. Averaging the squared gap over the fog gives the number we are trying to make small.

Figure — Kalman gain — minimizes trace of covariance

Step 3 — The blend rule: a slider between the two guesses

WHAT. We build our corrected guess (the plus means "after using the sensor") as:

Let us read every piece where it sits:

  • — we begin at the prediction.
  • turns a state into "what the sensor should read." For altitude with an altimeter, : state and reading are the same units. So is "the reading we expected." ( is the measurement map; keep this name, we use it again in Step 6.)
  • — the innovation: measured reading minus expected reading. This is the surprise. If it is zero, the sensor told us nothing new.
  • — the gain, our slider. means "ignore the surprise, keep the prediction." (for ) means "jump all the way to the measurement."

WHY this exact form. It is the simplest rule that is unbiased: if both fogs are centred on the truth on average, this blend is too, for any . It also has a beautiful geometric meaning — see the picture.

PICTURE. The corrected guess lives on the line segment between prediction and measurement. picks where on that segment we land.

Figure — Kalman gain — minimizes trace of covariance

Step 4 — How the fog transforms: the Joseph form

WHAT. We ask: if we blend with slider , how wide is the new fog ? Track the error through the blend. Start from the post-update error , substitute the blend rule from Step 3 and the sensor model (where is the sensor's random noise, with spread ). Using the pre-update error we defined in Step 2, this collapses to:

Here is the identity — the "do-nothing" element, the number in the scalar case (and the identity matrix in general), so that . Term by term:

  • — the leftover prediction error. The factor shrinks toward zero as grows: leaning on the sensor erases the old error.
  • — the freshly imported sensor noise. This grows with : the more we listen to the sensor, the more of its noise we swallow.

WHY the cross-terms vanish. To get the new variance we multiply by its own transpose and average. Multiplying out gives four blocks; two of them are the "cross" blocks and its mirror. Here is the key fact we must state, because the whole formula rests on it:

With those cross blocks gone, only the two "self" blocks survive: This is the Joseph form (see Joseph Form Covariance Update). It is honest for any slider position .

PICTURE. Two contributions, pulling opposite ways: the blue "prediction-error" term falls as rises; the pink "noise" term climbs.

Figure — Kalman gain — minimizes trace of covariance

Step 5 — The uncertainty is a U-shaped valley

WHAT. Write as a function of the single number (scalar case, , so ): Expand: . The last term is a parabola opening upward — because can never be negative.

WHY a parabola matters. An upward parabola has exactly one lowest point. So there is exactly one best slider setting — no ambiguity, no second competing minimum. This is why the Kalman gain is unique.

PICTURE. Plot total uncertainty against . It is a smiling U. Too-small (left) clings to a bad model; too-large (right) drowns in sensor noise; the bottom is the sweet spot.

Figure — Kalman gain — minimizes trace of covariance

Step 6 — Find the bottom: set the slope to zero (scalar first, then the matrix)

WHAT (scalar). The bottom of any smooth valley is where the ground is momentarily flat — the slope is zero. Take the derivative of with respect to and set it to :

Read it term by term:

  • — the downhill pull from erasing prediction error.
  • — the uphill push from imported noise, growing with .

Balance them:

WHY a derivative and not guessing. The derivative is the tool that answers "at which does the valley stop falling and start rising?" — precisely the flat bottom. Nothing else pins down the exact minimum in one clean step.

WHAT (matrix — and why it is not just "put back"). In real GNC the state is a list of numbers (position, velocity, ...), so is a vector, is a symmetric matrix, and the gain is a matrix: it has as many rows as there are states and as many columns as there are measurements. The slider is no longer one knob but a whole grid of knobs, so "slope = 0" must become "the trace stops changing in every direction of at once." We minimise the honest scalar score . Expanding the Joseph form and abbreviating : where the two mixed traces merged into one factor of because . Now use two standard matrix-calculus facts — the direct generalisation of "" and "": So the "slope in every direction is zero" condition reads The scalar is exactly this with and everything a number — so the matrix result contains the scalar one, it does not merely decorate it.

WHY can be inverted. To solve for we need to undo , i.e. multiply by — which only exists if is invertible. It is, because (any real sensor has nonzero noise) is positive-definite and is positive-semidefinite (it is a covariance mapped through ), and (positive-definite) + (positive-semidefinite) is positive-definite, hence invertible. So we are entitled to write:

PICTURE. The tangent line to the U is flat exactly at ; we mark that point. In the matrix case, "flat" means flat along every axis of the -grid at once.

Figure — Kalman gain — minimizes trace of covariance

Step 7 — The two extreme sliders (degenerate cases)

WHAT. Push the sensor to its two extremes and watch the slider snap to an end.

Case A — perfect sensor, (pink fog collapses to a spike). Slider all the way right: . We copy the measurement outright. Makes sense — why trust a foggy model over a flawless sensor?

Case B — useless sensor, (pink fog spreads to a flat sheet). Slider all the way left: . We ignore the sensor entirely and keep the prediction.

WHY show both. A reader must never meet a scenario we skipped. These two limits are the guardrails of the slider: it can never demand more than "all sensor" or less than "all model." Everything real lives strictly between.

PICTURE. Two mini-boards: on the left the pink spike drags ; on the right the flat pink sheet lets .

Figure — Kalman gain — minimizes trace of covariance

The one-picture summary

Everything above, on a single board: two fogs go in, the slider picks the blend, the total uncertainty traces a U-shaped valley, and its flat bottom is , producing an output fog narrower than both inputs.

Figure — Kalman gain — minimizes trace of covariance
Recall Feynman: the whole walkthrough in plain words

You have two guesses about one number: a model's guess and a sensor's reading. Draw each as a hill of fog — wide fog means unsure, narrow fog means confident. You want a final guess that sits between them, and a slider called decides where. Slide toward the sensor and you erase the model's error but drink in the sensor's noise; slide toward the model and you keep the sensor's noise out but trust a shaky model. So the total "how-wrong-am-I" score dips down and then climbs back up — a valley. The best slider sits at the very bottom of that valley, and doing the arithmetic gives (or with the sensor map, ). When the state is a list of numbers the slider becomes a grid of knobs, but the same idea holds: turn every knob until the total uncertainty stops falling in every direction — that flat bottom is the gain. We are allowed to divide by because a real sensor always has some noise, so is never zero. At the optimum the final fog is narrower than both starting fogs — you now know the number better than either source could tell you alone. Perfect sensor? Slider snaps to the sensor. Useless sensor? Slider snaps to the model. Nothing in between is ever a surprise.


Connections