Before we can estimate anything, we need to understand what a sensor actually hands us: the truth, plus an error we can describe but never see directly.
Use the arrow keys or the buttons below to move. Press N for instructor notes.
“How much should I trust this new measurement, compared with what I already believe?”
The answer is always a number between 0 and 1. We will call it the gain, K.
In Module 2 you choose K by hand and watch what happens.
By Module 7 the filter computes K itself, at every step, from how uncertain it is. That is the Kalman filter.
An instrumented sled runs along a straight test track. We want to know where it is, how fast it is going, and how hard it is accelerating.
The color code on this picture is used in every figure of the course: blue is the truth, red is what a sensor reports, and green will be our estimate.
The sled starts at rest, then goes through a series of pushes, coasts and one hard brake over 60 seconds.

m01_solution.m. Dotted lines mark the phases.Five times a second the sensor reports a position. It is never exactly right.

Over the whole run the readings look perfect, because a few meters of error is invisible beside 575 m of travel. Zoom in and each reading misses by a different amount. That scatter is what this module is about.
Park the sled at 0 m and ask the sensor where it is. Then ask again.
You cannot predict the next reading. But take many, and a stable pattern appears: most land near the truth, a few land far away.
A quantity like this, unpredictable one at a time but with a predictable pattern, is called a random variable.
Try it: take a few single readings first, then add a hundred at a time.
The bell-shaped pattern is the normal (or Gaussian) distribution. Two numbers describe it completely:
The rule worth memorizing: about 68% of draws fall within ±1σ, 95% within ±2σ, and 99.7% within ±3σ.
Drag the slider. The curve gets wider and lower, but the area under it stays 1 and the percentages never change.
We write “the noise n is normally distributed with mean 0 and variance σ²” as
and the height of the bell curve at an error x is the probability density
Same units as the measurement (meters). This is the number people quote and plot.
Units squared (m²). This is the number the mathematics prefers, because variances of independent errors simply add.
At each sample time k the sensor reports
measurement = true position + a fresh noise draw.
The noise does not care what the sled is doing. It is the same size at rest as at full speed.
Raise σ and watch the bottom panel. Press “New draw”: the truth stays put, the noise changes completely.
Noise is white when each sample is independent of every other sample. Knowing this reading’s error tells you nothing about the next one.
Both traces on the right have the same σ. The lower one is not white: its errors linger, so it wanders.
Until Module 6, our position sensor has white Gaussian noise and nothing else.
In a strapdown system the sensors are bolted directly to the vehicle. They feel what the vehicle feels.
Our sled is the one-dimensional version: later, one accelerometer along the track; for now, one position sensor.
An accelerometer does not measure position. Position comes from integrating acceleration twice.
Integration never forgets. Every small sensor error is added in and carried forward, so an inertial solution on its own slowly drifts away from the truth.
Use the fast inertial sensors to follow the motion and the slow position sensor to pull the drift back. Deciding how hard to pull is the Kalman filter’s job.
| Sensor | Measures | Typical rate | Main weaknesses |
|---|---|---|---|
| Accelerometer | Specific force along its axis (acceleration, plus the reaction to gravity) | 100 to 1000 Hz | Bias, scale factor, noise. Errors grow when integrated. |
| Gyroscope | Rotation rate about its axis | 100 to 1000 Hz | Bias and its slow drift, scale factor, noise. Heading error grows with time. |
| GNSS receiver | Position and velocity from satellite signals | 1 to 10 Hz | Meter-level noise, dropouts, reflections off buildings, delay. |
| Barometer | Air pressure, converted to altitude | 10 to 50 Hz | Slow drift with weather, sensitivity to airflow. |
| Magnetometer | Direction of the local magnetic field (heading) | 10 to 100 Hz | Disturbed by nearby iron and electric currents. |
| Odometer / wheel encoder | Distance traveled or wheel speed | 10 to 100 Hz | Wheel slip, tire-size (scale) error, quantization. |
Rates and error sizes vary enormously with the grade of the device. The pattern to notice: sensors that are fast and smooth tend to drift, and sensors that do not drift tend to be slow and noisy.
Blue is the true signal, red is what the sensor reports.
Our position sensor has white Gaussian noise with σ = 2 m. It reports
What do we know about the true position?

For the first 5 seconds the sled is parked at 0 m. The sensor gives us 25 readings of the same position.
One reading is off by about 2 m. But the errors are independent, so highs and lows tend to cancel. The average closes in on the truth.
In our run the average of all 25 readings is −0.12 m, against a truth of 0.

Averaging N independent readings, each with noise σ, gives an estimate with noise
Why: variances of independent errors add, so the sum of N readings has variance Nσ². Dividing by N divides the variance by N², leaving σ²/N.
For us: 2 m / √25 = 0.40 m. Repeating the experiment 2000 times in MATLAB gave 0.42 m.
Diminishing returns: to halve the error you need four times the readings.
Open m01_student.m and press Run. It works as it is, with a perfect sensor. Then fill in three short blocks:
Run again after each one. The Command Window prints PASS or FAIL for each TODO.
%% TODO 1 (student): write the noise generator % Goal: makeNoise(sigma, n) returns an n-by-1 % column of white Gaussian noise with % mean 0 and standard deviation sigma. % Hint: randn(n, 1) returns n samples with % standard deviation 1. % >>> YOUR CODE STARTS HERE makeNoise = @(sigma, n) zeros(n, 1); % <<< YOUR CODE ENDS HERE
| Kinematics | Position, velocity, acceleration: truth and sensor |
| Errors | Error over time, and its histogram |
| Averaging at rest | Running average; one reading vs the average |
| Playground | Slide the noise σ and watch everything change |
| Scoreboard | The course-long error chart |


They differ slightly from 2.00 because 301 samples is a finite sample. That is expected, not a bug.

Every module ends by adding a bar to this chart: the RMS position error of the best technique we have so far, on this same run.
Bar one is doing nothing at all, just believing the sensor. Averaged over 100 different noise draws it scores 2.00 m, which is the sensor’s σ, as it should be.
About 5% of the time, or one reading in twenty. 4 m is 2σ, and about 95% of draws fall within ±2σ. At 5 Hz that is roughly one such reading every four seconds.
400. The error falls with the square root of the number of readings, so a 4× improvement costs 16× the readings. At 5 Hz that is 80 seconds of sitting still.
No. Averaging only cancels errors that are independent from sample to sample. A constant offset (a bias) is in every reading, so it is in the average too. You would get a very steady, very confident, wrong answer.

Averaging the latest 25 readings was a great idea at rest. Once the sled moves, those readings are of 25 different positions. The average lags behind by up to 54 m, and its RMS error over the run is 29.5 m: far worse than the raw sensor’s 2.00 m.