Kalman Filter, Live
Lesson 4 · The Jacobian

The Jacobian: the slopes of a curve, seen up close

Slide 1 left us stuck: a radar's reading is a curve, and the filter needs a matrix. Here is the way out. The Earth is a ball, yet a football field looks flat. Zoom in close on any smooth curve and it looks like a straight line too, and a straight line does have a matrix. All we need is its slope: how much the reading changes for each metre the robot moves. The radar's reading depends on x and on y, so there are two slopes, one per direction. Put them in a row and you get the Jacobian, the stand-in for H. At (3, 4) the two slopes are 0.6 and 0.8.

Lesson 4 · slide 2The Jacobian
HJ = [ ∂r/∂x,  ∂r/∂y,  ∂r/∂vx,  ∂r/∂vy ] = [ x/r,  y/r,  0,  0 ]
Key ideas
  1. Reading the banner: HJ is one symbol (the Jacobian standing in for H), not H times J. The curly ∂ means "slope in one direction": ∂r/∂x is the slope of r in the x direction. vx and vy are the velocities in x and y. Linearise: near the current estimate, replace the curve by its tangent, the straight line that touches it there.
  2. A partial derivative ∂r/∂x is a slope: how much r changes per metre of x, with everything else held still.
  3. The Jacobian HJ is the row of all those slopes. It plays the role of H.
  4. For range: ∂r/∂x = x/r and ∂r/∂y = y/r. Velocity is not in the formula, so its slopes are 0.
  5. The tangent is only good nearby: halve the distance from the estimate and its error drops about four times.

What a slope is

Walk up a ramp. For every 1 m you go forward, you rise 0.1 m. That ramp has a slope of 0.1. A straight line has the same slope everywhere.

A curve's slope changes as you walk along it. To get the slope at one point, zoom in on that point until the curve looks straight, and read the slope of that straight line. That line is the tangent: the straight line that touches the curve at that point. Its slope is called the derivative.

You can measure it without any formula: nudge the input a tiny bit and see how much the output changes. Take f(x) = x² at x = 3:

f(3) = 9,   f(3.01) = 9.0601  →  change 0.0601 for a step of 0.01
slope ≈ 0.0601 / 0.01 = 6.01 ≈ 6

Zoom in on the radar's curve

Now the radar. Hold the robot at y = 4 and slide it along x. The range is r = √(x² + 16), a curve. Zoom in at x = 3, where r = 5, and the curve straightens out.

The range r as the robot slides along x, with y held at 4. We zoom in 10 times around the point (3, 5). The curve (solid) bends less and less until it lies on the dashed tangent. Its slope is 0.6.

The extended Kalman filter (EKF) uses exactly this. At the current best estimate, it replaces the radar's curve with its tangent. A straight line is linear, so it has a matrix, and the matrix filter works again. This step is called linearising.

Slopes, one direction at a time

The radar reading depends on two numbers, x and y. Think of standing on a hillside. Walking east you may climb steeply; walking north the ground may be nearly flat. Each direction has its own slope.

So we ask two questions. Nudge the robot a little in x and keep y fixed: how much does r change per metre? That slope is the partial derivative ∂r/∂x. The curly ∂ just means "in one direction, with the other number held still"; read it as "the slope of r in the x direction". Then do the same for y.

At (3, 4), r = 5. Nudge x to 3.01: r = √(3.01² + 4²) = 5.00601  →  slope ≈ 0.00601 / 0.01 ≈ 0.6
Nudge y to 4.01 instead: r = √(3² + 4.01²) = 5.00800  →  slope ≈ 0.008 / 0.01 ≈ 0.8
The other direction: hold x at 3 and slide y. Zoomed in at y = 4, the tangent has slope 0.8. The range reacts more to y than to x here.

The exact slopes, with school algebra

The nudges suggest a pattern: 0.6 = 3/5 and 0.8 = 4/5. Here is why. Square the range: r² = x² + y². Nudge x by a tiny step Δx, and let Δr be the change in r (Δ, the Greek letter "delta", means "change in"):

(r + Δr)² = (x + Δx)² + y²
r² + 2r·Δr + Δr² = x² + 2x·Δx + Δx² + y²
r² = x² + y² cancels on both sides:   2r·Δr + Δr² = 2x·Δx + Δx²
Δx and Δr are tiny, so Δx² and Δr² are tinier still. Drop them:   2r·Δr ≈ 2x·Δx
Δr / Δx ≈ x / r    so   ∂r/∂x = x / r,   and in the same way   ∂r/∂y = y / r

At (3, 4): ∂r/∂x = 3/5 = 0.6 and ∂r/∂y = 4/5 = 0.8. The nudges agree.

What does 0.6 mean? A 1 m error in x causes only a 0.6 m error in the distance, because the robot does not sit straight along the x axis from the radar. Only the part of the move that points along the line to the radar changes the range. In fact (x/r, y/r) is the unit vector (an arrow of length 1) from the radar to the robot: 0.6² + 0.8² = 0.36 + 0.64 = 1.

The Jacobian is the new H

Our state from lesson 3 is (x, y, vx, vy): position and velocity. Velocity does not appear in r = √(x² + y²), so its slopes are 0. Put all four slopes in a row and you have the Jacobian HJ.

HJ = x̂/r̂ŷ/r̂00    worked out at the estimate, with r̂ = √(x̂² + ŷ²)
At (3, 4):   HJ = 0.60.800

If the radar sits at (a, b) instead of the origin, measure from the radar: ∂r/∂x = (x − a)/r and ∂r/∂y = (y − b)/r, with r the distance to the radar. The Jacobian changes as the robot moves, so the filter recomputes it at every step.

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 · The (3, 4) point

Robot estimate (3, 4), radar at the origin.

Show solutionHide solution
r = √(9 + 16) = 5
∂r/∂x = 3/5 = 0.6,   ∂r/∂y = 4/5 = 0.8
HJ = [0.6, 0.8, 0, 0]
Check by nudging: (√(3.01² + 16) − 5) / 0.01 = 0.6006 ≈ 0.6

Example 2 · A radar that is not at the origin

Radar at (1, 1), robot estimate (4, 5).

Show solutionHide solution
Offsets from the radar: 4 − 1 = 3 and 5 − 1 = 4, so r = 5
∂r/∂x = 3/5 = 0.6,   ∂r/∂y = 4/5 = 0.8
HJ = [0.6, 0.8, 0, 0]

Same slopes as the (3, 4) point above: what matters is where the robot sits relative to the radar.

Exercise Zoom in: change the window half-width w from 3.0 to 0.3 and watch the tangent's error against the true curve drop below 0.01 m. Edit the code and press Run.
slide_2.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