Skip to content
Kudos AI

Kalman Filter

The exact filtering algorithm for a continuous state that moves linearly with Gaussian noise and is measured linearly with Gaussian noise, carrying the whole belief as a mean and a variance.

Also known as: Linear-Gaussian filter, Linear quadratic estimator

Understanding Kalman Filter

Discrete filtering carries one number per state, which is impossible when the state is a position, a velocity or a temperature. The Kalman filter handles the continuous case by restricting the model rather than the belief: the next state is a linear function of the current one plus Gaussian noise, and each observation is a linear function of the state plus Gaussian noise. Under those restrictions the belief is Gaussian at every step, and a Gaussian is two numbers in one dimension.

Each step is a predict and an update. Prediction pushes the mean through the dynamics and adds the transition variance, so uncertainty always grows; it is what the filter believes just before looking. The update folds in the observation and always shrinks the variance. Writing the updated mean out shows it is a weighted average, with the prediction carrying weight equal to the sensor variance and the observation carrying weight equal to the predicted variance. A precise sensor pulls the estimate onto the reading; a precise model pulls it onto the prediction.

The most useful structural fact is that the variance recursion contains no observation at all. Uncertainty evolves the same way whatever the sensor reports, so the entire sequence of variances, and with it the Kalman gain, can be computed before a single measurement arrives. On a stationary problem that sequence converges, and the running filter costs one weighted average per step.

The restrictions are real. If the dynamics are nonlinear, or the belief is genuinely multi-modal - a robot that is either in one corridor or another - a Gaussian cannot represent it, and linearising around the current estimate (the extended Kalman filter) or sampling (a particle filter) is the honest repair rather than a refinement.

How to Calculate

\mu_{t+1} = \frac{(\sigma_t^2 + \sigma_x^2)\, z_{t+1} + \sigma_z^2\, \mu_t}{\sigma_t^2 + \sigma_x^2 + \sigma_z^2}, \qquad \sigma_{t+1}^2 = \frac{(\sigma_t^2 + \sigma_x^2)\, \sigma_z^2}{\sigma_t^2 + \sigma_x^2 + \sigma_z^2}

where

\mu_t, \sigma_t^2
the mean and variance of the belief after t observations
\sigma_x^2
transition noise: how much the state drifts in one step
\sigma_z^2
sensor noise: how much a single reading can be trusted
z_{t+1}
the new observation

Example of Kalman Filter

Take a random walk starting at mean 0 with variance 1, transition noise of variance 4, sensor noise of variance 1, and a first reading of 2.5. Prediction leaves the mean at 0 and grows the variance from 1 to 5. The update then gives a mean of (5 x 2.5 + 1 x 0) / 6 = 2.083 and a variance of (5 x 1) / 6 = 0.833.

Two things are worth reading off that. The mean lands short of the reading, at 2.083 rather than 2.5, because the prediction still holds a sixth of the weight. And the variance of 0.833 is below both the predicted 5 and the sensor variance of 1: combining two noisy sources beats either alone.

Iterating the variance recursion on its own, with no data at all, converges to 0.828427. At that fixed point the filter puts about 83 per cent of its trust in each new reading and 17 per cent in its own prediction, forever. A settled variance does not mean a stalled estimate: the mean keeps moving with every observation, and only the confidence attached to it has reached equilibrium.

Frequently Asked Questions

Why does the variance shrink even when the reading is surprising?

Because the variance recursion does not mention the reading. A surprising observation moves the mean a long way and shrinks the variance by exactly as much as an unsurprising one would. Surprise is information about where the state is, not about how well it is known.

What breaks first when the model is not linear-Gaussian?

The claim that the belief stays Gaussian. Once it does not, a mean and a variance are a lossy summary rather than the whole belief, and the filter can become confidently wrong. Multi-modality is the case where this is most visible and where sampling methods are the right answer.

The Bottom Line

When a continuous state moves and is measured linearly with Gaussian noise, the exact belief is a Gaussian, the update is a weighted average whose weights come from the two variances, and the whole schedule of uncertainty can be worked out before the first measurement.