An Intuitive Introduction to Kalman Filtering
Eleven modules that go from “what is sensor noise?” to a working error-state Kalman filter. Each module adds one idea, starts from something the previous module got wrong, and has a MATLAB script where you build the idea yourself.
“How much should I trust this new measurement, compared with what I already believe?”
That question runs through the whole course. The answer is always a gain K between 0 and 1, used the same way every time: estimate = prediction + K · (measurement − prediction).
Along the way you will find that a Kalman filter does only two things to what it believes: when time passes it widens its uncertainty, and when a measurement arrives it narrows it, by fusing two uncertain estimates into one more certain one.
Modules
- 1Signals, noise and sensorsA sensor reading is the truth plus random error, and that error has a describable shape.Open slides
- 2Smoothing without a modelBlend each new measurement with the previous estimate using a fixed gain.Open slides
- 3Adding a motion model with fixed gainsPredict with kinematics, then correct with the measurement.not online yet
- 4Fusing two uncertain estimatesMultiply two bell curves: the result has a new mean and a smaller sigma, set by the two sigmas.not built yet
- 5Uncertainty in motion and the one-state Kalman filterPrediction widens the bell curve, a measurement narrows it, and the filter sets its own gain.not built yet
- 6Two states and correlationWhy a position measurement can correct a velocity that is never measured.not built yet
- 7Adding an accelerometerLet the accelerometer drive the prediction and the position sensor correct it.not built yet
- 8The linear Kalman filterName and organize, in matrix form, what you have already built.not built yet
- 9Estimating sensor errorsAnything unknown that affects the system can be made a state.not built yet
- 10The error-state Kalman filter in one dimensionA nominal solution, plus a filter that estimates only its small errors.not built yet
- 11Capstone: a planar vehicle with headingAttitude makes the problem nonlinear, and the error-state form handles it.not built yet
How each module works
1. Slides. Open the module’s slides from the list above. Use the arrow keys or the on-screen buttons to move, and press N for instructor notes.
2. MATLAB. Open the module’s mNN_student.m and press Run. It works as it is. Fill in the TODO blocks one at a time and run again; the Command Window prints PASS or FAIL for each. The finished version is mNN_solution.m. Only base MATLAB is needed, no toolboxes.
3. Scoreboard. Most modules end by adding a bar to a chart of RMS error, so you can see each technique improve on the last.
Color code
Used in every figure, widget and MATLAB plot: blue is the truth, red is a sensor measurement, green is our estimate.
Notation
| Symbol | Meaning | First used |
|---|---|---|
| p, v, a | True position, velocity and acceleration of the sled | Module 1 |
| z | A sensor measurement | Module 1 |
| n | Measurement noise | Module 1 |
| σ, σ² | Standard deviation (“one sigma”) and variance | Module 1 |
| k | Sample index: zk is the reading at sample k | Module 1 |
| x̂ | A hat marks an estimate: p̂ is our estimate of p | Module 2 |
| K | Gain: how much of the measurement’s disagreement we accept, from 0 to 1 | Module 2 |
| x̂− | A minus superscript marks a prediction, before the measurement is used | Module 3 |
| r | Residual: measurement minus prediction (called the innovation from Module 8) | Module 3 |
| P | Variance (later, covariance matrix) of our estimate | Module 4 |
| R | Variance of the measurement noise | Module 4 |
| Q | Variance of the process noise: how much uncertainty each prediction step adds | Module 5 |
| S | Variance the residual is expected to have: S = P− + R | Module 5 |