algorithms
How the Kalman Filter Lands Mars Rovers When Every Sensor Lies
You are driving through a long tunnel. GPS loses the sky and guesses your speed is seventy. The speedometer, bouncing over a pothole, says eighty-three. Two sensors, two numbers, zero truth. Average them and you get seventy-six point five: a number that is confidently, precisely, hilariously wrong. This is the exact problem NASA faced when trying to navigate Apollo to the Moon. The fix was not a better sensor. It was a formula that could listen to two liars and figure out which one was lying less.
01 / 07
The danger of a simple average
Picture a Mars rover dropping through the atmosphere. The onboard radar reads 100 mph. An optical camera tracking the ground says 105 mph. Both sensors are getting hammered by radiation and violent vibration. The data is a mess.
If the flight computer averages them, it gets (100 + 105) ÷ 2 = 102.5 mph. Looks reasonable. It is not. A simple average assumes both sensors are equally broken, which is almost never true. The radar is bouncing a clean signal off solid rock. The camera is temporarily blinded by a Martian dust cloud. One sensor is nearly right. The other is nearly useless. And the average cheerfully splits the difference, dragging the answer away from the good sensor toward the broken one.
Now try it with weights. Give the radar a confidence weight of 9 and the camera a weight of 1. Weighted result: (100 × 9 + 105 × 1) ÷ 10 = 100.5 mph. That is two full miles per hour closer to truth, from one line of arithmetic. The difference between 102.5 and 100.5 does not sound dramatic until your landing sequence depends on it.
02 / 07
Enter the Kalman Filter
Around 1960, a Hungarian-American mathematician named Rudolf E. Kálmán published a paper in the ASME Journal of Basic Engineering that solved this problem more generally than anyone had before. His key insight sounds almost too simple: you do not just have noisy sensor data. You also have the laws of physics.
A spacecraft does not randomly teleport. It has mass and momentum. Gravity pulls on it with a force you can calculate to several decimal places. Kálmán realised that physics itself is a sensor. The most reliable one you will ever have. His algorithm weighs what the physical sensors say against what physics says should be happening, and it does this in real time, constantly. Within two years, MIT's Instrumentation Laboratory adopted it for the Apollo program. The Apollo Guidance Computer used it to blend noisy radar readings with star sightings into a single precise position. That is how they navigated to the Moon with roughly 72 kilobytes of memory.
03 / 07
Predict first, look second
The filter runs as a loop with two steps. Step one is pure prediction. Before the flight computer even glances at the radar or camera, it does its own math.
It takes the last known speed: 100 mph. It adds the thrust from the retro-rockets: +3 mph. It subtracts the pull of Martian gravity: -1 mph. Predicted speed: 100 + 3 - 1 = 102 mph.
But here is where it gets clever. The filter does not just produce a number. It produces a number with a confidence grade attached. It marks its own exam. How long since the last reliable reading? Only 0.1 seconds. Are the physics equations well understood? Extremely. So the filter grades its own prediction at 9 out of 10. It is very sure of the physics, because gravity does not glitch. Gravity does not have a bad day.
04 / 07
Then check the hardware
Now the filter finally looks at the actual hardware. The radar says the speed is 98 mph.
It does not blindly accept this. It measures the static in the radar signal, the physical vibration shaking the antenna. The radar is struggling. The filter grades that reading at just 1 out of 10.
Two competing numbers, each with a grade. Prediction: 102 mph, weight 9. Sensor: 98 mph, weight 1. Blend them: (102 × 9 + 98 × 1) ÷ 10 = 101.6 mph. The answer pulled heavily toward the prediction, because the prediction earned the higher grade. The filter trusted its own math over the shaking antenna. And the result, 101.6 mph, is now more accurate than either number it started with.
05 / 07
The loop that eats noise
One calculation is useful. Running it hundreds of times a second is what makes it feel like magic. The filter takes that blended 101.6 mph and feeds it right back into the loop as the new baseline. Predict, grade, measure, grade, blend. Repeat.
Watch what happens over five cycles when the true speed is 101 mph the whole time. The confidence weights shift each cycle based on how noisy the last reading was, so the math is not a fixed 9-to-1 every time.
Cycle 1: sensor spikes to 115 from a vibration hit. The filter knows a heavy rover cannot accelerate 14 mph in a millisecond. Estimate: 101.8. Cycle 2: sensor reads a calmer 100. Estimate drifts to 101.4. Cycle 3: sensor reads 101. Estimate: 101.2. Cycle 4: another spike, sensor says 108. The filter shrugs. Estimate: 101.3. Cycle 5: sensor reads 101 again. Estimate: 101.1.
The sensor readings bounced all over: 115, 100, 101, 108, 101. The filter's output barely flinched: 101.8, 101.4, 101.2, 101.3, 101.1. It found the true speed without ever getting a single perfectly clean reading. The random spikes cancelled themselves out against the steady pull of physics. The noise ate itself.
06 / 07
Your phone is doing this right now
You rely on this loop every day and have probably never noticed, because it is doing its job.
Your phone's GPS signal bounces off a glass building, and for one frame the satellite thinks you teleported fifty feet into a Starbucks across the street. You are not in a Starbucks. The Kalman Filter inside your phone knows this, because the accelerometer measured two small steps forward, not a fifty-foot leap through a brick wall. It ignores the bad GPS ping and your blue dot stays put.
Self-driving cars use the same loop to track lane lines when rain turns the camera into a blur. Drones use it to hover in crosswinds that should be shoving them sideways. Submarine inertial navigation systems use it to hold course for weeks without surfacing. Commercial autopilots use it to land a 200-ton aircraft through turbulence, blending altimeter, GPS, and inertial readings that all disagree. Same two-step loop every time: predict from physics, measure from hardware, blend toward whichever earned the higher grade.
07 / 07
The 1960 math that still flies
Kálmán published his paper in 1960. By 1962 it was running inside the Apollo Guidance Computer at MIT's Instrumentation Laboratory, a machine with roughly 72 kilobytes of memory and a clock speed slower than a modern musical greeting card. That computer navigated three human beings a quarter of a million miles to the Moon and back.
The lesson has not changed in sixty-six years. When every physical sensor is feeding you garbage, your first instinct is to buy a more expensive sensor. The Kalman Filter says no. Keep your broken sensors. Build a loop that knows how to weigh confidence, and let the math filter the noise into truth.
The short version
- A simple average of noisy sensors is often worse than either sensor alone: (100 + 105) ÷ 2 = 102.5, but weighting by confidence gives (100 × 9 + 105 × 1) ÷ 10 = 100.5, two mph closer to truth.
- The Kalman Filter treats the laws of physics as a sensor, and weights it against hardware readings based on confidence.
- The predict step uses last known state plus physics (thrust, gravity) to estimate the current state and grade its own confidence.
- The update step reads the physical sensor, grades its noise level, and blends the two numbers toward whichever earned the higher grade.
- Running this loop hundreds of times a second causes random spikes to cancel out, producing an estimate more accurate than any single sensor on board.
- Published in 1960, adopted by Apollo in 1962, it powers everything from phone GPS to self-driving cars to submarine navigation today.