Kalman Filter, Live
Lesson 4 · Range-only tracking

Range-only tracking with two radars

Slide 4 built the EKF and ran it with one radar on a rail. Out in the open, one radar is not enough: it leaves the robot anywhere on a circle. Think of a friend on the phone: "I'm 5 km from the train station." They could be anywhere on a 5 km circle. "And 3 km from the stadium." Now only two spots fit, where the circles cross, and knowing they were heading north picks one. That is range-only tracking: each radar is one phone call, and the filter's prediction is "heading north". Here two radars and the EKF track a robot across a 900 m yard and stay within about 13 m of the truth.

Lesson 4 · slide 5Two radars
z = [r₁, r₂]    HJ = (x − a₁)/r₁(y − b₁)/r₁(x − a₂)/r₂(y − b₂)/r₂    R = σ² I
Key ideas
  1. One range puts the robot somewhere on a circle. One radar can't tell where on the circle.
  2. Two radars give two circles. They cross in two mirror-image points, and the prediction picks the right one.
  3. Stack both readings: z has 2 entries, HJ has 2 rows (one per radar), R is 2 × 2.
  4. The encoder drives the predict step; the radars correct it. Dead reckoning (adding up encoder steps with no radar) alone drifts by tens of metres.
  5. R must match the real radar noise. An overconfident filter chases every noisy reading.
  6. The EKF fails when its tangent is a bad stand-in for the curve. The unscented Kalman filter (UKF) is the usual next step.

One radar is ambiguous

A radar at the origin reads 5 m. The robot could be at (3, 4), (5, 0), (0, −5) or any other point on that circle. In EKF terms, the Jacobian has one row, x/ry/r. It tells the filter how the range changes along the line of sight, and nothing about moving around the circle. The position has two unknowns, x and y, and one radar gives one equation.

(3, 4): √(9 + 16) = 5 ✓   (−4, 3): √(16 + 9) = 5 ✓   (0, −5): 5 ✓

A filter with one radar is not useless: as the robot drives, the direction to the radar changes, and the motion model links the readings over time. That is how the rail robot on slide 4 managed. But in the open it is slow to settle and easy to fool.

Two radars pin the position

Add a second radar somewhere else. Now there are two equations for two unknowns. The circles cross in two points, mirror images across the line joining the radars. The prediction sits near one of them, so the EKF lands on the right one.

Two radars, both reading 5 m. Their circles cross at (3, 4) and at its mirror image (3, −4) below the line joining the radars.
x² + y² = 25  and  (x − 6)² + y² = 25
Subtract: x² − (x − 6)² = 0  →  12x − 36 = 0  →  x = 3,   then y² = 16, so y = 4 or y = −4

Stacking works like in lesson 3. The reading becomes z = (r₁, r₂), the predicted reading h(s⁻) = (r̂₁, r̂₂), and the Jacobian gets one row per radar, as in slide 2's bigger example. The radars' noise is independent, so R = σ² I is diagonal. Then the same five update lines run unchanged.

The simulation

The radars stand at (790, 95) and (110, 55), with range noise σ = 15 m. The robot starts at (70, 455) moving about 8.8 m/s (one step is 1 s) and turns gently. The state here is just the position (x, y), with no velocity in it. The encoder supplies the motion instead, as the input u. Here u is the encoder's measured step (metres moved this step), added straight onto the position. Each step:

  • Predict. The encoder reads the velocity with σ = 6 m/s of noise, so each step u is off by σ = 6 m. The filter moves its estimate by that step: s⁻ = s + u, so F = I. (In lesson 3 the input matrix B carried u into the state; here B = I.) It grows P by the encoder's variance (6² = 36 m²) plus Q = 2 m² (q in the code), so P grows by 38 m² on the diagonal each step (the input u is noisy, so its variance adds to our doubt, as in lesson 2's dead reckoning).
  • Measure. Both radars report a noisy range.
  • Update. ① predicted ranges from the real distance formula, ② a 2 × 2 Jacobian at s⁻, then K, s and P as always.

The lab's map shows the truth (dashed), dead reckoning (the encoder alone) and the EKF, with its 2σ ellipse every 10 steps. With this particular random run, dead reckoning is 87 m off on average over the run. The honest EKF stays about 13 m from the truth, better than the 15 m noise of either radar. These are RMS errors (root-mean-square of the distance to the truth, over every step). The lab prints them, and the readout under the map shows the same numbers.

The same run as the lab, seen as the robot's y position over time. Dead reckoning wanders off by tens of metres. The EKF follows the dashed truth inside its ± 2σ band (about ± 17 m).

The exercise: tell the filter the truth about R

The starter code tells the filter its radars are accurate to 1 m (sig_R = 1), while they really have 15 m of noise. Now the filter believes every reading almost completely. Its gain along each line of sight is close to 1, so the estimate jumps to each new noisy fix and the track zigzags. Its error, about 21 m, is roughly what you get from the raw radar fixes alone. All the smoothing the prediction could give is thrown away.

In the simulation, after a few steps HJ P⁻ HJᵀ settles near 39 m² for each radar in the overconfident filter, and near 113 m² in the honest one
Believes R = 1:   K ≈ 39 / (39 + 1) = 0.98    honest R = 15² = 225:   K ≈ 113 / (113 + 225) = 0.33
The overconfident filter (believes σ = 1 m) jumps to every noisy fix and zigzags. The honest filter (σ = 15 m) is smooth and closer to the truth.

Set sig_R = 15 and the filter weighs the prediction and the radars fairly. Try 60 too: now it trusts the radars too little, leans on the drifting encoder, and the error climbs back to about 25 m.

When the EKF fails

The EKF's whole bet is that the curve is nearly straight across the region where the robot might be. That bet loses when:

  • the uncertainty is large compared with the curve's bend: right after start-up, after losing the radars for a while, or close to a radar (slides 1 and 3);
  • the estimate starts on the wrong mirror-image side, or far away, so the Jacobian points the wrong way;
  • the geometry is weak: a robot on the line between the two radars has two parallel Jacobian rows (rows pointing the same or opposite way), so its sideways position is invisible to both;
  • the filter is overconfident. Small P or small R means it stops listening, and linearisation errors pile up until it diverges: the estimate wanders off while P claims it is fine.

The common fix is the unscented Kalman filter (UKF). Instead of one tangent line, it picks a handful of carefully placed "sigma points" (sample positions around the estimate), pushes each one through the real h(s), and rebuilds the mean and covariance from the results. That is the sample experiment from slide 3, done with very few, well-chosen samples. It catches the mean shift the EKF misses, and needs no Jacobians at all.

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 · One radar, many answers

A radar at the origin reads 5 m.

Show solutionHide solution
(3, 4): √(9 + 16) = 5 ✓   (5, 0): 5 ✓   (−4, 3): √(16 + 9) = 5 ✓
HJ at (3, 4) = [0.6, 0.8]: one row, one direction

Every point on the circle fits. A single range only fixes the distance.

Example 2 · Two radars, two mirror points

Radars at (0, 0) and (6, 0). Both read 5 m.

Show solutionHide solution
x² + y² = 25 and (x − 6)² + y² = 25
Subtract: x² − (x − 6)² = 0  →  12x − 36 = 0  →  x = 3
Then y² = 25 − 9 = 16  →  y = 4 or y = −4

Two points, mirrored across the line joining the radars. A prediction near (3, 4) settles it.

Exercise The filter thinks the radars are accurate to 1 m, but they are really 15 m. Tell it the truth: set sig_R = 15.0 on the marked line and get the EKF error below 16 m. Edit the code and press Run.
slide_5.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