Kalman Filter, Live
Lesson 4 · Nonlinear sensors

Nonlinear sensors: when z = Hx breaks

Lesson 3 ended with the matrix Kalman filter tracking a rocket. Its GPS read the position through a matrix: z = Hx. Now swap the GPS for a radar. A radar only tells you how far away the robot is, like a dog on a 5 m leash: you know it is 5 m from the post, but not on which side. That distance, r = √(x² + y²), is a nonlinear sensor: a curve, not a matrix, so there is no H to plug in. Worse, a Gaussian pushed through that curve comes out bent, with its mean in the wrong place. This lesson shows how the filter copes.

Lesson 4 · slide 1Nonlinear sensors
GPS: z = H x (a matrix)    radar: r = √(x² + y²) (a curve)    mean of r ≠ r of the mean
Key ideas
  1. A linear sensor is a matrix: z = Hx. Doubling the state doubles the reading, and readings add.
  2. A range sensor (radar, sonar, ultrasound, radio beacon) measures distance r = √(x² + y²). That is nonlinear: no matrix H gives it.
  3. A Gaussian pushed through a curve is no longer a Gaussian: it bends and gets lopsided.
  4. Its mean shifts: the average distance is not the distance of the average position. The shift is worst close to the sensor, where the curve bends most.

A GPS reads position, a radar reads distance

In lesson 3 the sensor gave us the position directly. The matrix H picked the position out of the state: z = Hx. Every step of the matrix filter relied on that.

Now put a radar on a post at the origin. It sends out a pulse, times the echo and reports one number: the range r, the straight-line distance to the robot.

r = √(x² + y²)

It does not say where the robot is, only how far. All the points at the same distance form a circle around the radar, like the ground a dog on a leash can reach.

The radar's reading grows into a circle of radius 5 m. The robot is somewhere on it; the pale band is the radar's noise.
Robot at (3, 4): r = √(9 + 16) = √25 = 5 m
Robot at (5, 0): r = √(25 + 0) = 5 m    robot at (0, −5): r = 5 m

Three different places, one reading.

Why no matrix H can do this

A matrix sensor has two habits. Readings add: H(a + b) = Ha + Hb. And they scale: H(2a) = 2Ha, and H(−a) = −Ha. Distance breaks both.

r(3, 0) = 3,   r(0, 4) = 4,   but r(3, 4) = 5, not 3 + 4 = 7
r(−3, −4) = 5, never −5: a distance can't be negative

So there is no H. The square root makes the sensor nonlinear: plot r against x (with y held fixed) and you get a bend, not a straight line. Our filter equations, built on z = Hx, have nothing to plug in.

A Gaussian through a curve bends

The filter does not know the robot's position exactly. It holds a Gaussian: a best guess plus a cloud of possible positions around it. What does that cloud look like after the radar?

Take each possible position and work out its distance. Far from the radar, the cloud is small compared with the distance. Across the cloud, the circles of equal distance look almost like straight lines. So the distances come out close to a Gaussian, centred close to the distance of the best guess.

Far away: best guess (6, 8), 10 m from the radar, σ = 1 m. With many samples the distances form a bell centred at 10.05 m with σ ≈ 1 m (the lab's 400 samples give 10.07 m): almost exactly the straight-line guess, 10 m with σ = 1 m.

Close to the radar, the cloud reaches right past it. A straight-line sensor would say the reading drops 1 m for every metre you move toward the radar, and keeps dropping past it, below zero. The real radar can't: a point 0.5 m past the radar reads +0.5 m, not −0.5 m. Points off to the side also read farther than a straight line says, because the circles curve. All these errors go the same way, up. So the bell becomes lopsided, and its mean is pushed away from the radar.

Up close: best guess (0.6, 0.8), only 1 m away, σ = 1 m. The straight-line ("linear") guess even allows negative distances. With many samples the true distances sit about 0.55 m farther out (the lab's 400 samples: 1.59 m).

The mean shifts

This is the trap. The tempting shortcut is "the robot is probably at (x̂, ŷ) (the hat means "estimate"), so the radar should read about √(x̂² + ŷ²)". But the average distance is bigger than the distance of the average position. For a round cloud with standard deviation σ in x and in y, at distance r, the gap is about σ²/(2r) (a known approximation; no need to derive it). It is tiny far away and large up close.

σ = 1 m, r = 10 m: gap ≈ 1² / (2 · 10) = 0.05 m    average ≈ 10.05 m
σ = 1 m, r = 1 m: gap ≈ 1 / 2 = 0.5 m    average ≈ 1.5 m (with many samples: 1.55 m)

In the lab, 400 possible positions go through the radar. The "linear guess" is what a straight-line sensor would give: a bell at the shortcut distance with the same spread σ as the position. A round cloud with standard deviation σ in x and in y gives a range spread of about σ; slide 3 shows why. Far away, at (6, 8), the true distances and the linear guess almost match: the lab prints an average of 10.07 m against 10 m. Bring the robot to 1 m from the radar and they fall apart.

Keep reading with the full course

Finish lesson 4 and you will be able to: track a robot from range-only radars with an EKF.

Still locked here:

  • The rest of this explanation
  • 3 more examples with step-by-step solutions
  • Five extra members-only problems with worked solutions

$20 once, lifetime access. Lessons 1 and 2 stay free.

Examples

Example 1 · A GPS is linear

A GPS reads the position (x, y) with some noise. As a matrix: H = 1001.

Show solutionHide solution
Robot at (3, 4): Hx = (3, 4)
Robot at (6, 8): Hx = (6, 8), twice the reading for twice the position
Robot at (−3, −4): Hx = (−3, −4)

Readings double and flip sign exactly with the state. That is what "linear" means.

Example 2 · A radar is not

The radar at the origin reads r = √(x² + y²).

Show solutionHide solution
r(3, 0) = 3  and  r(0, 4) = 4
r(3, 4) = √(9 + 16) = √25 = 5, not 3 + 4 = 7
r(6, 8) = √100 = 10 (doubling happens to work along a line going out from the radar), but r(−3, −4) = 5, not −5

One failure is enough: no matrix H gives these readings.

Exercise Move the robot right next to the radar (set mx, my = 0.6, 0.8, which is 1 m away) and watch the true distances pull away from the linear guess. Edit the code and press Run.
slide_1.py Loading Python…
1
Output · Ctrl+Enter runs
Press Run to execute this slide's code. Ctrl+Enter works too.

Questions and comments

Stuck on something, or found a mistake? Ask here and I'll answer. You sign in with GitHub.

The full course

From noisy sensors to the EKF, by running it

Lessons 1 and 2 are free. Finish all four and you will be able to:

You get: all 4 lessons with Python labs · every worked example and solution · 5 extra problems per lesson · your progress tracked · Steppe, your AI tutor inside every lesson, day or night · every future update.

$20 once · lifetime access · 14-day money-back guarantee
Continue to checkout →

Already a member? Log in to the course