Small Group Tutorials

Here to help students catch up, keep up, and move ahead. Book a consultation here.

How to Learn the Kalman Filter: State Prediction, Covariance, Innovation, Gain and Consistent Estimation

Wait, What?

A sensor can be wrong on every reading and still help you estimate the truth better.

That is the central idea behind the Kalman filter. It does not ask whether the model or the sensor is perfectly correct. It asks a better question: given what I believed before, how uncertain that belief was, what I just measured, and how uncertain the measurement is, what should I believe now?

This makes the Kalman filter one of the most important algorithms for learning how professional systems combine prediction with evidence. It appears in navigation, aerospace, robotics, tracking, control, signal processing and many other state-estimation problems.

Quick Answer

Learn the Kalman filter in this order: hidden state → model prediction → uncertainty prediction → measurement residual → innovation covariance → Kalman gain → state correction → covariance correction → consistency tests → numerical robustness. Do not begin by memorising matrix equations. Begin with the meaning of each quantity.

1. Start With the Hidden-State Problem

Suppose a moving object has a true position and velocity. You cannot observe those quantities perfectly. A sensor gives noisy measurements, and a motion model predicts where the object should move next. The state is therefore partly hidden.

The filtering problem is to maintain an estimate of that hidden state as time advances. In a linear discrete model, a common form is:

x_k = F_k x_(k-1) + B_k u_k + w_k
z_k = H_k x_k + v_k

Here x is the state, F advances it through the process model, u is a known control input, B maps that control into state change, z is the measurement, and H maps state into measurement space. The disturbances w and v represent process and measurement uncertainty.

2. Learn the Two-Phase Rhythm Before the Algebra

Every basic Kalman-filter cycle has two phases:

  • Predict: use the model to move the state estimate and its uncertainty forward.
  • Correct: compare the new measurement with the predicted measurement and adjust the estimate.

This predict–correct rhythm is more important for a beginner than any single formula. If a learner cannot explain which phase a quantity belongs to, the matrix notation will become a memorisation exercise rather than an algorithm.

3. Predict the State

The predicted state is commonly written:

x_hat_prior = F x_hat_previous + B u

If the state is position and velocity, the model may say that position changes according to velocity while velocity remains roughly constant over a short interval. The prediction is not a claim of certainty. It is a provisional estimate before the new measurement is incorporated.

4. Predict the Uncertainty Too

A professional implementation never updates the state alone. It also propagates the covariance matrix P, which describes uncertainty and correlations between state variables:

P_prior = F P_previous F^T + Q

Q represents process-noise covariance: uncertainty introduced because the real process is not exactly the model. If a vehicle can accelerate unpredictably, a constant-velocity model should not pretend otherwise. The uncertainty should grow accordingly.

5. The Innovation Is the Surprise

Next compare what the sensor reported with what the model predicted the sensor should report:

innovation = z - H x_hat_prior

This quantity is also called the measurement residual. It is one of the most informative signals in the whole filter. A large innovation means the measurement and the prediction disagree. But disagreement alone does not tell you which one should be trusted more; you must compare their uncertainties.

6. Measure How Surprising the Innovation Really Is

The innovation covariance is:

S = H P_prior H^T + R

R is the measurement-noise covariance. A ten-metre residual might be shocking for a millimetre-precision sensor but routine for a very noisy detector. The same numerical error can therefore carry very different evidential weight depending on S.

7. The Kalman Gain Balances Prediction and Measurement

The Kalman gain is:

K = P_prior H^T S^-1

Intuitively, the gain becomes larger when the predicted state is uncertain relative to the measurement, so the filter moves more strongly toward the measurement. It becomes smaller when the measurement is noisy relative to the prediction.

A common beginner mistake is to treat K as a fixed percentage. It is not. In the multivariable case it is a matrix shaped by state uncertainty, measurement uncertainty and the geometry of how the sensor observes the state.

8. Correct the State

x_hat_posterior = x_hat_prior + K innovation

This is the easiest equation to understand once the preceding quantities are clear. The estimate moves away from the model prediction in the direction indicated by the measurement residual, scaled by the gain.

9. Correct the Covariance

The covariance must also be updated. A compact form is often written as:

P_posterior = (I - K H) P_prior

In finite-precision software, however, the Joseph form is often preferable when robustness matters:

P_posterior = (I-KH) P_prior (I-KH)^T + K R K^T

The Joseph form uses more arithmetic but better preserves the covariance structure against numerical round-off. This is an important transition from classroom mathematics to production engineering: equations equivalent in exact arithmetic may behave differently on real computers.

10. Work a One-Dimensional Case Before a Matrix Case

Imagine an estimated temperature of 20.0°C with uncertainty variance 4.0. A new sensor reading is 22.0°C with measurement variance 1.0. Ignoring process evolution for this tiny example, the gain is approximately:

K = 4 / (4 + 1) = 0.8

The corrected estimate becomes:

20 + 0.8 × (22 - 20) = 21.6

The measurement receives more weight because it is considered more precise than the prior estimate. If the measurement variance were much larger, the gain would shrink and the update would move much less.

This scalar example is not the full Kalman filter, but it gives the learner a mental anchor for what the matrix equations are doing.

11. Covariance Is Not a Confidence Percentage

The covariance matrix does two jobs. Its diagonal entries describe uncertainty associated with individual state components, while off-diagonal entries describe how errors in different state components move together. If position and velocity errors are correlated, treating them as independent can produce poor updates even if each marginal variance appears reasonable.

12. Know the Assumptions Behind the Classical Filter

The classical discrete Kalman filter is built around a linear model with noise represented through covariance, with the familiar optimality result under standard assumptions such as Gaussian noise. Outside that envelope, the filter can still be useful, but the word optimal must be used carefully.

Professional practice therefore asks: Is the process sufficiently represented by the model? Are sensor errors biased? Are outliers present? Are noise statistics stationary? Is the state observable from the available measurements? Is the timing correct?

13. Observability Comes Before Tuning

A filter cannot estimate information that the measurements and dynamics do not reveal. Before spending hours tuning Q and R, check whether the chosen state is observable under the available sensor model and motion. A beautifully tuned estimator can still fail if the underlying state cannot be inferred.

14. Q and R Are Models of Uncertainty, Not Magic Knobs

Increasing Q generally tells the filter to distrust its process model more. Increasing R generally tells it to distrust the measurement more. But tuning them only until a plot “looks smooth” is not a professional method.

Estimate sensor noise from data where possible, model genuine process disturbances, inspect innovations, and test the filter across operating conditions. Smoothing a trajectory is not evidence that the uncertainty model is correct.

15. Validate With Innovations, Not Just Pretty Plots

The innovation sequence should behave consistently with the covariance predicted by the filter. One useful diagnostic is the Normalized Innovation Squared (NIS):

NIS = innovation^T S^-1 innovation

Under the modelling assumptions, NIS can be compared with a chi-squared distribution. When ground truth is available, the related Normalized Estimation Error Squared (NEES) checks consistency of the state estimate and its covariance. These tests move evaluation from “the line looks good” toward statistical evidence.

16. Avoid Explicit Matrix Inversion in Production Code

Textbook notation writes S⁻¹, but numerical software should usually solve a linear system instead of forming an explicit inverse. Cholesky or other factorizations may be appropriate when the matrix properties allow them. This is faster, more stable and better aligned with professional numerical linear algebra.

17. Numerical Robustness Is Part of the Algorithm

  • Preserve covariance symmetry rather than assuming round-off will do so.
  • Monitor positive-semidefinite behaviour of covariance matrices.
  • Use stable update forms such as Joseph form when appropriate.
  • Consider square-root filtering when numerical conditioning is demanding.
  • Scale state variables sensibly so that one variable is not many orders of magnitude larger than another without reason.
  • Timestamp measurements correctly; delayed or out-of-sequence measurements are not merely “noise.”

18. Nonlinear Problems Need a Different Conversation

The Extended Kalman Filter linearizes nonlinear models. The Unscented Kalman Filter propagates selected sigma points through nonlinear transformations. Particle filters represent distributions with samples. These are related state-estimation tools, but they are not interchangeable names for the same algorithm.

Master the linear Kalman filter first because prediction, innovation, covariance and consistency remain foundational concepts even when the estimator becomes more sophisticated.

19. Reference Pseudocode

# Predict
x = F @ x + B @ u
P = F @ P @ F.T + Q

# Innovation
y = z - H @ x
S = H @ P @ H.T + R

# Solve for gain; avoid explicit inverse in real code
K = solve(S.T, (P @ H.T).T).T

# Correct state
x = x + K @ y

# Joseph covariance update
A = I - K @ H
P = A @ P @ A.T + K @ R @ K.T

20. Common Failure States

  • Memorising equations without knowing what state, measurement and uncertainty mean.
  • Treating covariance as an arbitrary confidence score.
  • Choosing Q and R only to make an output curve look smooth.
  • Using the filter on an unobservable state and blaming tuning.
  • Ignoring bias, latency, outliers or frame/unit mismatches.
  • Computing matrix inverses directly because the textbook prints an inverse symbol.
  • Updating the state but forgetting the covariance.
  • Assuming a small residual automatically means a consistent estimator.
  • Using an EKF or UKF without first understanding the linear predict–correct cycle.

21. Practice Ladder: Beginner to Professional

  • Beginner: combine a scalar prior estimate with one noisy measurement and explain why the result lies between them.
  • Foundation: implement a one-dimensional constant-state Kalman filter and plot the innovation after every update.
  • Intermediate: build a two-state position–velocity filter, write F, H, Q and R explicitly, and trace one full matrix update by hand.
  • Advanced: simulate sensor noise and process disturbances, then test whether changing Q and R has the predicted effect on innovations and uncertainty.
  • Professional: use stable linear solves, Joseph or square-root forms where justified, timestamped asynchronous measurements, outlier gating and consistency diagnostics such as NIS/NEES.
  • Transfer: explain why a filter can produce a visually smooth estimate while still being statistically inconsistent.

Learning Hall Boundary

This article owns the teaching job of understanding the classical Kalman filter as an estimation algorithm, from scalar intuition through matrix implementation and professional validation. It does not replace separate material on general probability, linear algebra, control theory, robotics planning, learner-state diagnosis or study-workflow design.

Evidence Boundary

The foundational source is R. E. Kalman’s 1960 paper, A New Approach to Linear Filtering and Prediction Problems, Journal of Basic Engineering, DOI 10.1115/1.3662552. For modern teaching and engineering context, NASA’s NESC Academy published Fundamentals of Kalman Filtering and Estimation, last updated 16 August 2024. MIT’s Underactuated Robotics state-estimation notes place Kalman filtering within observers and recursive Bayesian estimation. Numerical implementation should also account for stable covariance updates, linear solves and consistency checks rather than treating textbook algebra as executable code without qualification.

Professional rule: you understand a Kalman filter when you can explain what every prediction and update means, state what uncertainty model it assumes, and demonstrate with diagnostics that the estimator is behaving consistently—not merely smoothly.