Sensor fusion and the Kalman filter lesson plan
The math behind fusing sensors, honest about its limits: noise as variance, the EMA, the complementary filter derived, the Kalman filter from one state to two, GPS fused with a compass, and an attitude display that learns its gyro biases.
Objectives and materials
By the end, students can
- Variance, the square-root law, and the noise and lag of the two everyday smoothing filters.
- The complementary filter derived, then the scalar Kalman filter worked to its steady state.
- Angle and bias in a two-state filter, and a GPS fused with a compass, wrong compass included.
- An artificial horizon that learns its gyro biases and holds steady through a shake.
Materials for the whole unit
- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3
- GPS module, NEO-6M
- Half breadboard
- LED x 2
- Nine-axis IMU, MPU-9250
- OLED display, 128x64
- Resistor x 2
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Noise, measured
Variance, the square-root law, and the noise and lag of the two everyday smoothing filters.
| Lesson | Time | What students do |
|---|---|---|
| Noise, measuredEvery filter starts from a number for the noise. Measure a noisy pitch in windows of 200: mean, standard deviation, variance and the 68-95 rule, then see averaging cut the noise by the square root of the count. | 55 min |
|
| Moving average and EMATwo smoothing filters on the same noise: a moving average of 8 and an exponential moving average. Predict how much noise each removes and how long each lags, measure both with a step test, and trade one for the other. | 55 min |
|
Materials
- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3
Check for understanding
Each student finishes "Moving average and EMA" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "When averages fail".
From fusion to Kalman
The complementary filter derived, then the scalar Kalman filter worked to its steady state.
| Lesson | Time | What students do |
|---|---|---|
| The complementary filter, derivedThe filter you tuned by hand, done properly: alpha from tau and dt, the crossover frequency where gyro hands over to gravity, the steady error a bias leaves (bias x tau), and the accelerometer noise that gets through, each predicted and then measured. | 55 min |
|
| The 1D Kalman filterOne state, four lines: predict, gain, update, shrink. Work the first steps by hand, watch the gain settle to the steady state Q and R set, catch a move with the innovation test, and see what a wrong R does. | 55 min |
|
Materials
- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3
Check for understanding
Each student finishes "The 1D Kalman filter" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Lie about R".
Kalman for real
Angle and bias in a two-state filter, and a GPS fused with a compass, wrong compass included.
| Lesson | Time | What students do |
|---|---|---|
| Kalman for tiltThe gallery’s Kalman filter tilt angle: an MPU6050 through TKJ Electronics’ two-state filter, angle and gyro bias, plotted beside the accelerometer, the gyro alone and a complementary filter. Read the 2 x 2 matrices, follow a tilt, and tighten the level. | 55 min |
|
| GPS plus IMUA NEO-6M GPS and an MPU-9250 compass fused into one position: dead reckoning from speed and heading between fixes, a gain that weighs each fix, the error measured against the truth, a GPS outage, and a compass that is 10 degrees wrong. | 65 min |
|
Materials
- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3
- GPS module, NEO-6M
- Half breadboard
- LED x 2
- Nine-axis IMU, MPU-9250
- Resistor x 2
Check for understanding
Each student finishes "GPS plus IMU" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "What a real INS adds".
Boss build
An artificial horizon that learns its gyro biases and holds steady through a shake.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a steady attitude displayAn artificial horizon on an SSD1306 OLED, driven by two two-state Kalman filters written out in the sketch: they learn each gyro’s bias while they run, follow a tilt, and hold steady through a shake by trusting the gyro while the accelerometer lies. | 65 min |
|
Materials
- Accelerometer and gyroscope, MPU6050
- Arduino Uno R3
- OLED display, 128x64
Check for understanding
Each student finishes "Boss: a steady attitude display" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.