Kalman and Extended Kalman Filters (EKF)
Tracking a full arbitrary probability map over a 3D room would melt a small onboard computer in milliseconds. The Kalman filter makes a clever practical bargain: what if we assume our belief is always a clean bell curve — a Gaussian — described completely by a mean pose and a covariance matrix?
Core ideas covered in this module
- Gaussian covariance ellipses
- Kalman gain & sensor weighting
- Nonlinear motion linearization (EKF)
Ellipses as a compact language for uncertainty
In 2D, a Gaussian belief over (x, y) draws as an ellipse. The center of the ellipse is our mean estimate. A tiny tight circle means we're confident to within a couple centimeters; a long, stretched-out oval means we know roughly which lane we're in, just not how far forward we've rolled.
That ellipse is encoded by a small covariance matrix P. When we fuse two noisy sensors — say, shaky wheel odometry and a range-bearing beacon — the Kalman filter computes an optimal blend called the Kalman Gain K.
- When process noise Q is large and measurement noise R is tiny, Kalman Gain K leans toward 1: trust the new landmark sighting and snap the ellipse onto it.
- When the sensor is noisy (R is large) and our motion model is solid (Q is small), K stays small: nudge the estimate gently instead of chasing sensor jitter.
Handling curves with the Extended Kalman Filter
The textbook linear Kalman filter only works when motion and sensors are straight-line matrix multiplications. Real mobile robots steer in arcs using sines and cosines, and range-bearing beacons involve square roots and arctangents. Push a Gaussian through a curve and it bends into a banana shape instead of a clean ellipse.
The Extended Kalman Filter (EKF) solves this pragmatically: at each step, it takes the local tangent plane — the Jacobian matrix — around the current mean pose, propagates the ellipse along that local linear approximation, and runs the exact same Kalman Gain math.
Interactive lab
2D Extended Kalman Filter Uncertainty Ellipse Visualizer
marimo· LiveKalman Gain K (3×2) & 2σ Spread
Where the EKF shines — and where it cracks
Try cranking Process Noise Q way up while turning Landmark dropout ON, then turning dropout back OFF. Notice how quickly the filter recovers once a single clean beacon reading arrives — that's the magic of tracking cross-covariances between x, y, and heading θ.
The catch is that an EKF can only represent one unimodal bell curve at a time. If your robot genuinely has no idea whether it's in the north hallway or the identical south hallway, a single Gaussian ellipse will awkwardly average the two and land in the solid wall between them.
EKF Predict, Kalman Gain, and Update
P̄ = F P Fᵀ + Q | K = P̄ Hᵀ (H P̄ Hᵀ + R)⁻¹ | x = x̄ + K(z − h(x̄))
F and H are the local Jacobians of motion and sensing. K automatically balances our predicted covariance P̄ against sensor noise R.
Your robot's laser beacon rangefinder gets covered in dust, making its measurement noise R ten times larger than usual. How does the Kalman filter respond?
Error-State EKFs (ES-EKF) and factor-graph smoothers are still workhorses in drones, legged robots, and autonomous cars whenever you need rock-solid 200+ Hz state estimates from IMU, encoders, and GPS/vision.
Hands-On Python Notebook
03 · Extended Kalman Filter (EKF) Sensor Fusion Lab
Code the EKF Predict/Update loop with motion and measurement Jacobians and plot 2σ covariance ellipses around landmark beacons.
Try this on your own inside the notebook
- Simulate a 10-step GPS/beacon blackout and watch covariance grow then snap back
- Compare numerical finite-difference Jacobians against analytical ones
In Google Colab, use File → Save a copy in Drive to keep your own edits and notes. Or download the files directly:
uvx marimo edit --sandbox notebooks/course-5/03_kalman_and_ekf_fusion.pyWrap up this module
Saved automatically in your browser profile so you can pick up right where you left off.