Extended Kalman filter: the Kalman filter on a curved world
扩展卡尔曼滤波
Extend the Kalman filter to nonlinear models by linearising about the current estimate, see exactly what that approximation drops, compare one correction with the true posterior and the iterated EKF, and watch the filter recover, or fail, on a synthetic two-beacon tracking problem.
extended-kalman-filterStraight lines on a curved world
The extended Kalman filter (EKF) is the Kalman filter adapted to systems whose motion or sensors are nonlinear, meaning their output does not change in straight-line proportion to the state. At every step it replaces each curved function by its tangent line at the current estimate, then runs the ordinary Kalman filter equations. For example, a sensor that measures the distance to a beacon is nonlinear in position. The EKF handles it by pretending, for one step, that distance changes linearly with position. Linearise about the estimate
The linear Kalman filter is exact only when every model is linear and every noise is Gaussian. Real robots break this almost at once. Distance depends on position via a square root, and a bearing (direction angle) depends on it via an arctangent. A turning vehicle moves along an arc. For such models the exact belief is no longer a Gaussian (bell-shaped) distribution, and no finite set of numbers describes it in general. Why the KF is not enough
The EKF keeps the Kalman filter’s shape anyway. It still stores one mean (the best guess) and one covariance (how uncertain the guess is). To pass them through a curved function, it uses a first-order Taylor expansion (the tangent-line approximation from calculus); see Taylor expansion. The slopes of that tangent are collected in a Jacobian matrix, see Jacobian. Taylor linearisation
This is cheap and often works well. Barfoot notes that the EKF is still the mainstay of estimation and data fusion in many circles, and Labbe calls it the most common nonlinear technique. It also comes with no guarantee. Because the tangent is taken at the estimate rather than at the truth, a bad estimate gives a bad tangent, and the filter can become overconfident or drift away. Mainstay Most common technique No guarantee
This article shows what the approximation drops, how the iterated EKF improves the correction step, and which failures no amount of linearisation can fix. It assumes the linear Kalman filter and the Bayes filter of state estimation.
Linearise, then run the Kalman filter
This section writes the nonlinear model, shows what happens to a Gaussian pushed through a curve, gives the EKF equations, and then describes the iterated and second-order variants.
The nonlinear model
Särkkä writes the additive-noise model like this. Model, eq. (5.24)
In words: the new state is a function of the old state plus Gaussian process noise . The measurement is a function of the state plus Gaussian measurement noise . Compared with the linear model, the matrices and have become arbitrary functions and . In a more general form the noise sits inside the functions, and . Non-additive model, eq. (5.37) Noise inside the nonlinearity This article uses the additive form. The general form only adds two extra noise Jacobians to the covariance lines. Noise Jacobians W and V
A Gaussian through a curve
Start with one step: is Gaussian with mean and covariance , and . For any nonlinear , the exact distribution of is not Gaussian. Non-Gaussian output The first-order approximation replaces by its tangent at : First-order approximation, eqs. (5.3)–(5.10)
In words: the output mean is approximated by the function evaluated at the input mean. The output covariance is the input covariance stretched by the slope matrix , the Jacobian of at . This is exact for a straight line and approximate for anything curved. Welch and Bishop call this the EKF’s fundamental flaw: after a nonlinear transformation the variables are no longer normal, and the EKF only approximates the optimality of Bayes’ rule. Fundamental flaw
The EKF equations
First, the two Jacobians, each taken at the latest estimate: Algorithm 5.4
In words: is the slope of the motion model at the last filtered mean, and is the slope of the measurement model at the new predicted mean.
In words: the predicted mean comes from the true nonlinear motion model, while the predicted covariance uses its slope.
In words: the innovation (measurement minus expected measurement) uses the true measurement function, while the innovation covariance and gain use its slope. The last line is exactly the Kalman filter update. Algorithm 5.4, eqs. (5.26)–(5.27)
Barfoot names the two differences from the linear filter. The nonlinear models themselves move the mean, and Jacobians appear inside the effective noise covariances. Two differences Labbe gives the practical reason for using and for the mean: propagating the mean through the tangent line would add linearisation error for nothing. Use f and h for the mean Särkkä’s derivation simply repeats the Kalman filter derivation with Taylor-based Gaussian approximations in place of the exact joint Gaussians. Derivation, eqs. (5.28)–(5.36)
Range measurements, the running example
The example below measures distances to known beacons. For a beacon at position and a 2-D position :
In words: the measurement is the straight-line distance. Its Jacobian is the unit vector pointing from the beacon to the estimate. A range reading therefore corrects the estimate only along the line of sight. Sideways errors are invisible to it. Welch and Bishop make the same point in general: the Jacobian passes on only the part of the innovation that actually affects the measurement. Only the relevant component
The iterated EKF
The EKF takes the slope of at the predicted mean. After the update, a better estimate exists, so why not take the slope there and update again? This is the iterated EKF (IEKF). Barfoot linearises about an operating point . Choosing gives the ordinary EKF. Iterating to the latest posterior mean until it stops changing, then computing the covariance once at the end, gives the IEKF. IEKF, eqs. (4.40)–(4.46) Written in this article’s notation:
In words: take the slope at the current operating point, compute the gain, and update starting from the prediction. The last bracket corrects the innovation because the tangent was taken somewhere else. On the first pass , the bracket’s last term vanishes and this is the EKF.
Barfoot shows that the IEKF mean corresponds to a local maximum of the posterior, that is, a maximum a posteriori (MAP) estimate, see MAP estimation. This holds for the correction step at a single time step, and only for a local maximum. The plain EKF can be far from any local maximum, and little can be said about how it relates to the full posterior. IEKF is MAP, footnote 6 In general, neither is the posterior mean. In Barfoot’s stereo-camera illustration the IEKF matches the MAP point while the EKF does not, and neither equals the mean. Fig. 4.7
Second-order and other variants
A second-order EKF keeps the next Taylor term, built from the Hessian (the matrix of second derivatives). That adds a curvature correction to the predicted mean and a matching term to the covariance. Algorithms 5.3 and 5.6 Other ways to push a distribution through a curve include brute-force Monte Carlo sampling and the sigma-point, or unscented, transformation. Three ways Särkkä groups Gaussian filters into Taylor-series EKFs, statistically linearised filters and unscented Kalman filters (UKF), and notes the UKF converges to the EKF in a suitable parameter limit. Gaussian filter families Welch and Bishop point to Julier and colleagues’ unscented approach as a response to the EKF’s flaw. Julier et al. The UKF is not taught here.
Three synthetic experiments with range sensors
This section measures the linearisation error directly, compares one EKF correction with the exact posterior, and runs a tracking problem where the EKF first recovers and then fails. The program is an original synthetic simulation, numpy only, with fixed seeds. All measurements are ranges, distances to known beacons plus noise, and all positions are in arbitrary units.
import numpy as np
# Synthetic range measurements: r = |p - b| + noise, with b a known beacon position.
def ranges(p, beacons):
d = p[..., None, :2] - beacons
return np.hypot(d[..., 0], d[..., 1])
def range_jacobian(p, beacons, n):
d = p[..., None, :2] - beacons
r = np.hypot(d[..., 0], d[..., 1])
H = np.zeros(p.shape[:-1] + (len(beacons), n))
H[..., :, :2] = d / r[..., None]
return H
print("1) passing a Gaussian through r = |p| (sensor at origin, prior mean (3, 4), covariance s^2 I)")
rng = np.random.default_rng(5)
origin = np.zeros((1, 2))
for s in (0.1, 1.0, 3.0):
samples = np.array([3.0, 4.0]) + s * rng.standard_normal((400000, 2))
r = ranges(samples, origin)[:, 0]
print(" s = %.1f: linearised mean 5.0000 std %.4f | Monte Carlo mean %.4f std %.4f" % (s, s, r.mean(), r.std()))
print("2) one EKF update vs the exact posterior (prior N((3,4), diag(4,1)), one range y = 7, R = 0.01)")
m = np.array([3.0, 4.0])
P = np.diag([4.0, 1.0])
Rr = 0.01
y = 7.0
def update(xop):
H = range_jacobian(xop, origin, 2)
S = H @ P @ H.T + Rr
Kg = P @ H.T / S[0, 0]
v = y - ranges(xop, origin)[0] - H @ (m - xop)
return m + Kg @ v, P - Kg @ S @ Kg.T, H, S[0, 0], Kg[:, 0]
m_ekf, P_ekf, H, S, Kg = update(m)
print(" H = %s, S = %.4f, K = %s" % (np.round(H[0], 4).tolist(), S, np.round(Kg, 4).tolist()))
print(" EKF mean %s (range %.4f), covariance %s" % (np.round(m_ekf, 4).tolist(), np.hypot(*m_ekf), np.round(P_ekf, 4).tolist()))
xop = m.copy()
for it in range(50):
new = update(xop)[0]
if np.abs(new - xop).max() < 1e-12:
break
xop = new
m_iekf = update(xop)[0]
print(" IEKF mean %s (range %.4f) after %d relinearisations" % (np.round(m_iekf, 4).tolist(), np.hypot(*m_iekf), it))
g = np.linspace(-2.0, 9.0, 1101)
GX, GY = np.meshgrid(g, g, indexing="ij")
Pi = np.linalg.inv(P)
ex, ey = GX - m[0], GY - m[1]
logp = -0.5 * (Pi[0, 0] * ex * ex + 2 * Pi[0, 1] * ex * ey + Pi[1, 1] * ey * ey) - 0.5 * (y - np.hypot(GX, GY)) ** 2 / Rr
w = np.exp(logp - logp.max())
w /= w.sum()
mean = np.array([(w * GX).sum(), (w * GY).sum()])
dx, dy = GX - mean[0], GY - mean[1]
cov = np.array([[(w * dx * dx).sum(), (w * dx * dy).sum()], [(w * dx * dy).sum(), (w * dy * dy).sum()]])
i, j = np.unravel_index(np.argmax(logp), logp.shape)
print(" grid posterior: MAP (%.2f, %.2f), mean %s, covariance %s" % (g[i], g[j], np.round(mean, 4).tolist(), np.round(cov, 4).tolist()))
print("3) tracking with two range beacons at (-10, 0) and (10, 0): 500 Monte Carlo runs x 40 steps")
A = np.eye(4)
A[0, 2] = A[1, 3] = 1.0
q = 1e-5
Q1 = q * np.array([[1 / 3, 1 / 2], [1 / 2, 1.0]])
Q = np.zeros((4, 4))
Q[np.ix_([0, 2], [0, 2])] = Q1
Q[np.ix_([1, 3], [1, 3])] = Q1
B = np.array([[-10.0, 0.0], [10.0, 0.0]])
sr = 0.1
R = sr ** 2 * np.eye(2)
m0 = np.array([-8.0, 6.0, 0.4, 0.0])
P0 = np.diag([1.0, 1.0, 1e-4, 1e-4])
rng = np.random.default_rng(16)
x = rng.multivariate_normal(m0, P0, 500)
L = np.linalg.cholesky(Q)
X, Y = [], []
for k in range(40):
x = x @ A.T + rng.standard_normal((500, 4)) @ L.T
X.append(x)
Y.append(ranges(x, B) + sr * rng.standard_normal((500, 2)))
X, Y = np.stack(X, 1), np.stack(Y, 1)
def ekf(mstart, Pstart, iters):
mm = np.broadcast_to(mstart, (500, 4)).copy()
PP = np.broadcast_to(Pstart, (500, 4, 4)).copy()
ms, Ps = [], []
for k in range(40):
mm = mm @ A.T
PP = A @ PP @ A.T + Q
xo = mm.copy()
for _ in range(iters):
H = range_jacobian(xo, B, 4)
Ht = np.swapaxes(H, -1, -2)
S = H @ PP @ Ht + R
Kg = PP @ Ht @ np.linalg.inv(S)
v = Y[:, k] - ranges(xo, B) - np.einsum("mij,mj->mi", H, mm - xo)
xo = mm + np.einsum("mij,mj->mi", Kg, v)
mm = xo
PP = PP - Kg @ S @ np.swapaxes(Kg, -1, -2)
ms.append(mm)
Ps.append(PP)
return np.stack(ms, 1), np.stack(Ps, 1)
print(" (state dimension 4: a consistent filter has mean NEES 4; P(NEES > 9.488) = 5%)")
runs = [("good start: true prior", m0, P0, 1),
("start y = 1, P0 y-var 16, EKF", np.array([-8.0, 1.0, 0.4, 0.0]), np.diag([1.0, 16.0, 1e-4, 1e-4]), 1),
("start y = 1, P0 y-var 16, IEKF", np.array([-8.0, 1.0, 0.4, 0.0]), np.diag([1.0, 16.0, 1e-4, 1e-4]), 10),
("mirror start y = -6, EKF", np.array([-8.0, -6.0, 0.4, 0.0]), P0, 1),
("mirror start y = -6, IEKF", np.array([-8.0, -6.0, 0.4, 0.0]), P0, 10)]
for name, ms0, Ps0, iters in runs:
ms, Ps = ekf(ms0, Ps0, iters)
e = X - ms
nees = np.einsum("rki,rkij,rkj->rk", e, np.linalg.inv(Ps), e)
final = np.hypot(e[:, -1, 0], e[:, -1, 1])
claimed = np.sqrt(Ps[:, -1, 0, 0] + Ps[:, -1, 1, 1])
print(" %s" % name)
print(" mean NEES %.2f (k = 1: %.2f, k = 40: %.2f), share > 9.488 %.1f%%, final error median %.3f, claimed std %.3f" % (nees.mean(), nees[:, 0].mean(), nees[:, -1].mean(), 100 * np.mean(nees > 9.488), np.median(final), np.median(claimed)))
The program prints:
1) passing a Gaussian through r = |p| (sensor at origin, prior mean (3, 4), covariance s^2 I)
s = 0.1: linearised mean 5.0000 std 0.1000 | Monte Carlo mean 5.0011 std 0.1000
s = 1.0: linearised mean 5.0000 std 1.0000 | Monte Carlo mean 5.1020 std 0.9894
s = 3.0: linearised mean 5.0000 std 3.0000 | Monte Carlo mean 5.9964 std 2.6395
2) one EKF update vs the exact posterior (prior N((3,4), diag(4,1)), one range y = 7, R = 0.01)
H = [0.6, 0.8], S = 2.0900, K = [1.1483, 0.3828]
EKF mean [5.2967, 4.7656] (range 7.1250), covariance [[1.244, -0.9187], [-0.9187, 0.6938]]
IEKF mean [5.3566, 4.4943] (range 6.9923) after 16 relinearisations
grid posterior: MAP (5.36, 4.49), mean [5.0397, 4.6168], covariance [[1.1463, -1.013], [-1.013, 1.0354]]
3) tracking with two range beacons at (-10, 0) and (10, 0): 500 Monte Carlo runs x 40 steps
(state dimension 4: a consistent filter has mean NEES 4; P(NEES > 9.488) = 5%)
good start: true prior
mean NEES 4.16 (k = 1: 5.84, k = 40: 3.99), share > 9.488 6.0%, final error median 0.054, claimed std 0.067
start y = 1, P0 y-var 16, EKF
mean NEES 34.59 (k = 1: 490.24, k = 40: 4.04), share > 9.488 42.6%, final error median 0.054, claimed std 0.067
start y = 1, P0 y-var 16, IEKF
mean NEES 3.96 (k = 1: 3.96, k = 40: 3.99), share > 9.488 4.9%, final error median 0.054, claimed std 0.067
mirror start y = -6, EKF
mean NEES 82490.76 (k = 1: 14209.39, k = 40: 111129.89), share > 9.488 100.0%, final error median 11.800, claimed std 0.067
mirror start y = -6, IEKF
mean NEES 82428.81 (k = 1: 14048.76, k = 40: 111140.76), share > 9.488 100.0%, final error median 11.799, claimed std 0.067
Part 1: what the tangent line drops
A sensor at the origin measures the range of a point. The point’s position is Gaussian with mean and covariance . The range at the mean is exactly 5. The linearised answer is mean 5.0000 and standard deviation for every . With 400,000 Monte Carlo samples:
| s | linearised mean / std | Monte Carlo mean / std |
|---|---|---|
| 0.1 | 5.0000 / 0.1000 | 5.0011 / 0.1000 |
| 1.0 | 5.0000 / 1.0000 | 5.1020 / 0.9894 |
| 3.0 | 5.0000 / 3.0000 | 5.9964 / 2.6395 |
When the spread is small compared with the distance (s = 0.1), the tangent is excellent. As the spread grows, the true mean range rises above 5 and the linearised spread is too large (3.0000 against 2.6395 at s = 3). The reason is curvature: points to the side of the mean are farther away than the tangent predicts. Our own second-order calculation uses Särkkä’s quadratic approximation and the Hessian of the distance. It predicts a shift of about , so 5.1 at s = 1 and 5.9 at s = 3 (exercise 2). The EKF ignores this shift.
Part 2: one correction against the truth
Now take the prior mean with covariance , one range measurement , and measurement variance . The measurement says the point lies on a thin ring of radius 7. The EKF linearises at : , , . Its updated mean is . But that point is at range 7.1250, outside the ring, and 1.25 measurement standard deviations away from the reading of 7. The straight-line update overshoots the curve.
The IEKF relinearises 16 times and reaches , at range 6.9923. To check, the program evaluates the exact posterior on a grid of 1101 × 1101 points with spacing 0.01. The grid MAP point is , which matches the IEKF to grid resolution, as Barfoot’s result predicts. The exact posterior mean is , different from both. The true posterior is a curved banana along the ring. Its covariance differs from the EKF’s , most visibly in a larger second variance.
Part 3: two beacons, three starting points
A target moves at nearly constant velocity in 2-D, with state (x, y, x-velocity, y-velocity). Two beacons at and measure its range with noise standard deviation 0.1. The process noise is tiny (). The truth starts near with velocity , so the target passes above the beacons at height about 6. We run 500 Monte Carlo runs of 40 steps. The state has dimension 4, so a consistent filter has mean NEES (normalised estimation error squared, defined in Kalman filter) near 4, with about 5% of values above 9.488. That threshold is our own calculation: with 4 degrees of freedom, the chance of exceeding is , which is 0.05 at .
| filter start | mean NEES | NEES at k = 1 | NEES at k = 40 | share > 9.488 | final error (median) | claimed std (median) |
|---|---|---|---|---|---|---|
| true prior, EKF | 4.16 | 5.84 | 3.99 | 6.0% | 0.054 | 0.067 |
| y = 1, y-variance 16, EKF | 34.59 | 490.24 | 4.04 | 42.6% | 0.054 | 0.067 |
| same start, IEKF (10 iterations) | 3.96 | 3.96 | 3.99 | 4.9% | 0.054 | 0.067 |
| mirror start y = −6, EKF | 82490.76 | 14209.39 | 111129.89 | 100.0% | 11.800 | 0.067 |
| mirror start y = −6, IEKF | 82428.81 | 14048.76 | 111140.76 | 100.0% | 11.799 | 0.067 |
Good start. Started from the true prior, the EKF is close to consistent: mean NEES 4.16, slightly overconfident at the first step (5.84 against 4).
Wrong but honest start. The filter starts 5 units too low (y = 1) but says so honestly, with a y-variance of 16. The first corrections linearise at a poor point, and the filter becomes badly overconfident: mean NEES 490.24 at . It recovers by (4.04), and the final errors match the good start. The IEKF, which relinearises at its improving estimate, removes the problem from the first step (3.96).
Mirror start. Two ranges cannot tell a point from its reflection across the line through the beacons: both give the same distances. Started at , the mirror image of the truth, both the EKF and the IEKF lock onto the mirror track. Their final error is about 11.8 while they claim a standard deviation of 0.067. This is not a linearisation failure, and iterating does not help. The true posterior has two peaks, and a single Gaussian can hold only one. It is a case of the measurement mapping not being one-to-one. Welch and Bishop warn that the filter then diverges quickly, and call the process unobservable in that case. Not one-to-one
When the tangent line misleads
This section collects the EKF’s known weaknesses and what to do about them.
No guarantee. Barfoot states plainly that there is no guarantee the EKF will perform adequately on a general nonlinear system. The main problem is that it linearises at the estimate, not at the true state. It can diverge wildly, or, more often, be biased, inconsistent or both. No guarantee Part 3’s second row shows the inconsistent case. Särkkä’s pendulum example, where an EKF reached an angle RMSE of 0.12 against a measurement-noise standard deviation of 0.32, shows it can also work well; both are single examples. Pendulum example
Strong nonlinearity and non-Gaussian noise. Särkkä lists the disadvantages. The EKF fails when nonlinearities are considerable. It allows only Gaussian noise, so it cannot handle discrete-valued variables or strongly non-Gaussian models. It needs differentiable models. Its Jacobians may be impossible to compute, or error-prone to program and debug. Advantages and disadvantages A wrong Jacobian gives no error message, only a worse filter. Our own advice, not taken from these sources, is to check it against finite differences.
One Gaussian, one hypothesis. A Gaussian has one peak. Symmetric layouts, like the mirror start in Part 3, or ambiguous landmarks, produce posteriors with several peaks. Then neither the EKF, the IEKF nor any other single-Gaussian filter is enough. One needs information that breaks the tie, such as a better prior or another sensor, or a multi-peak method such as the particle filter. Labbe’s landmark demo shows a related effect: with only two landmarks the estimate diverges after passing them, and with one the result is very bad. Fewer landmarks
Angles wrap around. A bearing of 1° against a predicted 359° gives a naive innovation of −358°, when the real difference is 2°. Labbe stresses that the bearing residual needs code that computes the difference correctly. Angle wrapping A common fix, our example rather than Labbe’s, is to wrap the innovation into one turn, such as the interval from −180° to 180°. Forgetting this corrupts the update without any warning.
Inconsistency is common to Gaussian filters. Särkkä warns that both EKFs and sigma-point filters can report error estimates that do not match the real errors. He adds that more complicated filters are not guaranteed to do better. Practical advice Labbe shows, in one cubic example, the EKF’s transformed mean being markedly inaccurate where the UKF’s is not. UKF comparison That is one example, not a ranking.
The example is a toy. The beacons, noise levels and starting points were chosen to make each effect visible. The NEES of 490.24, for instance, belongs to this setup and does not generalise.
Exercises
These exercises cover what is approximated, two hand calculations, a counterexample about iteration, and method choice.
-
The EKF moves the mean with and computes the innovation with , but moves the covariance with Jacobians. Why not use and for the mean too? What is still approximated?
Answer: and evaluate the model exactly at the estimate. and would add linearisation error to the mean (Labbe; Barfoot lists this as a difference from the linear filter). The covariance has no exact closed form for a nonlinear map, so it is approximated with Jacobians. Still approximated: (i) is in general not the mean of ; in Part 1 at s = 1, the true mean range is 5.1020, not 5.0000. (ii) The Gaussian shape itself, Welch and Bishop’s “fundamental flaw”. (iii) The slope is taken at the estimate, not at the truth (Barfoot).
-
(a) Verify Part 2’s correction by hand: prior , , , sensor at the origin. (b) Estimate the mean range for to second order and compare with the Monte Carlo values 5.1020 (s = 1) and 5.9964 (s = 3).
Answer: (a) , so . . , so . The innovation is , so . For : , , . Check: the new mean has range 7.1250, not 7; the straight-line update overshoots the ring. (b) This is our own calculation. The Hessian of at is with . Half its trace times is . So the second-order mean is about : 5.1 at s = 1 (Monte Carlo 5.1020) and 5.9 at s = 3 (Monte Carlo 5.9964). The second-order term captures most of the shift; the first-order EKF says 5 in both cases.
-
“If the EKF goes wrong, iterate the update and it will be fixed.” Give one case from Part 3 where iteration fixes the problem and one where it cannot. Explain the difference.
Answer: Fixed: the start at y = 1 with an honest wide prior. The EKF has mean NEES 34.59 (490.24 at , 42.6% above 9.488); the IEKF has 3.96 with 4.9%. The trouble was a poor linearisation point, and relinearising at the improving estimate removes it. Not fixed: the mirror start. Two range beacons give the same ranges for a point and its reflection, so the posterior has two peaks. The IEKF finds only a local MAP point (Barfoot), which here is the wrong peak: final error 11.799 against a claimed standard deviation of 0.067. Any single-Gaussian filter fails here. It needs a prior that rules out the mirror, a sensor that breaks the symmetry, or a multi-peak representation such as a particle filter.
-
Choose a method for each case and justify it. (a) A mildly nonlinear vehicle model with Gaussian noise and analytic Jacobians. (b) A model whose Jacobian is unavailable or very error-prone to derive. (c) A robot that must keep several distinct position hypotheses, for example in a symmetric building. (d) A range-and-bearing sensor whose bearing passes through ±180°.
Answer: (a) Start with the EKF, as Särkkä advises, and check consistency with NEES in simulation; try the IEKF if the measurement nonlinearity is strong. (b) A sigma-point (unscented) filter, which needs only and (Labbe; Barfoot), or, as our own suggestion, Jacobians checked numerically. (c) A Gaussian filter cannot hold several peaks (Part 3); use a particle filter or another multi-peak method, as Särkkä advises when Gaussian approximations fail. (d) The EKF can work, but the bearing innovation must be wrapped into one turn (Labbe’s 1° against 359° case). Otherwise a tiny real innovation appears as nearly ±360° and wrecks the update.
History and further reading
This section gives the EKF’s origin as Barfoot tells it and suggests further reading.
In Barfoot’s account, shortly after Kalman’s 1960 paper, Stanley F. Schmidt of NASA Ames Research Center and his team adapted the filter for spacecraft navigation. They extended it to nonlinear motion and observation models, linearised about the best current estimate, and recast it as separate prediction and correction steps. Barfoot says the EKF became a key tool for estimating spacecraft trajectories in the Apollo program. History He cites McGee and Schmidt (1985) for this history; we did not read that paper, so these statements are his.
Barfoot adds that the EKF was sometimes called the Schmidt–Kalman filter. That name fell out of use because it was confused with a later Schmidt method for unobservable biases. He also credits Schmidt with work on square-root forms, and says Schmidt’s popularisation inspired Charlotte Striebel’s work toward the Rauch–Tung–Striebel smoother. Schmidt–Kalman name The word “extended” simply means the extension of the Kalman filter to nonlinear systems. Footnote 5
For advice on choosing, Särkkä’s summary is clear. Among Gaussian approximations, start with the EKF and its smoother, which have been used for over half a century. Move to sigma-point methods if the EKF does not work. Go to particle methods if theoretical exactness is required or Gaussian approximations fail. Choosing a filter His Chapter 5 derives the EKF and its variants. Barfoot’s Section 4.2 covers the EKF, the IEKF and the sigma-point alternatives from the robotics side. Chapter 5 Section 4.2 Welch and Bishop give a short self-contained derivation. Section 2 Labbe’s open book has a hands-on chapter with a radar example and robot localisation using landmarks. Chapter 11 The EKF is widely used in robot localization, SLAM and sensor fusion, which are separate topics.
Make a prediction, then check
A target is tracked with two range beacons, and the filter starts at the mirror image of the target across the beacon baseline. Both the EKF and the iterated EKF converge to the mirror track, about 11.8 units wrong while claiming a 0.067 standard deviation. What is the most appropriate remedy?
Learning objectives
- Write the EKF prediction and update equations with their Jacobians, compute one range-measurement correction by hand, and state what is approximated: only the first-order term when a Gaussian is pushed through a nonlinearity.
- Recognise EKF failure modes (overconfidence from a poor linearisation point, divergence, multimodal ambiguity, unwrapped angles) and decide when to use the iterated EKF, a sigma-point filter or a particle filter.
Prerequisites & connections
Explore related knowledge →References
- Bayesian Filtering and Smoothing — scoped
Simo Särkkä · 2013 - State Estimation for Robotics — scoped
Timothy D. Barfoot · 2017 - An Introduction to the Kalman Filter (TR 95-041) — scoped
Greg Welch; Gary Bishop · 2004 - Kalman and Bayesian Filters in Python
Roger R. Labbe · 2024
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Claude · 2026-12-03 · Independent AI check (Claude subagent, not the author; not a human or expert review). Research was done by a separate research subagent (facts.md) and the prose by a writer subagent; style-only edits suggested by the Gemini app were applied to the intuition section before this check. I compared all eight logged edits for this topic (gemini-edits-016a.json) old against new and reverted one zh edit that misstated the maths. I then made D012 readability edits: the intuition section's citations were moved to paragraph ends. I checked the other openings and the plain readings after the display equations, and they were already compliant. Then I checked the edited text. I ran example.py with the pinned interpreter (numpy 1.26.4). Its output is byte-identical to example.stdout.txt, both python blocks are byte-identical to example.py, and every number in the prose, tables, exercises and quiz matches the output. I re-derived the Part 2 correction by hand (H = [0.6, 0.8], S = 2.09, K = [1.1483, 0.3828], P entries, range 7.1250 = 1.25 sigma), the second-order shift s^2/10 from the Hessian of the norm, the IEKF update form against Barfoot eq. (4.45c), and the 9.488 threshold (e^{-c/2}(1+c/2) = 0.0500 at c = 9.488). I fetched the sources myself. Barfoot (barfoot_ser17.pdf, pdftotext): pp. 100-101 (mainstay, Schmidt, NASA Ames, Apollo, Schmidt-Kalman name), p. 103 (no guarantee, diverge wildly), §4.2.5-§4.2.6 pp. 105-107 (IEKF iteration, local MAP, footnote 6, Fig. 4.7 labels). Särkkä (pdftotext): p. 64 (EKF/SLF/UKF families; UKF converges to EKF in a parameter limit), p. 72 (disadvantages), pp. 74-75 (pendulum RMSE 0.12 against noise std 0.32), §13.1 pp. 204-205. Welch & Bishop TR 95-041: p. 8 (fundamental flaw, ad hoc, Julier) and p. 11 (relevant component, not one-to-one, diverges quickly, unobservable). Labbe at commit 04b2bea8, notebook 11: markdown cells 4, 7, 46 (only the 1 vs 359 degree case, no interval), 53-57 (two landmarks diverge, one very bad), 60 and 62. Not re-read: Särkkä Algorithms 5.3-5.6 equation by equation, and McGee & Schmidt 1985 (never read, which the article says).
- Example rerun with pinned numpy 1.26.4 matches example.stdout.txt byte for byte; both code blocks equal example.py; all quoted numbers match the output, and positions are consistently in arbitrary units.
- Re-derived: the Part 2 correction by hand, the s^2/10 second-order shift, the IEKF update matching Barfoot eq. (4.45c), and the 9.488 threshold (4 degrees of freedom; our own calculation, now stated in the text).
- Barfoot: the IEKF is a local MAP only for the single-timestep correction (footnote 6); the EKF has no guarantee and can diverge wildly; the Schmidt/Apollo history is attributed to Barfoot.
- Labbe cell 46 gives only the 1 vs 359 degree case; the -180 to 180 degree interval is now labelled as our example. Checking Jacobians against finite differences is now labelled as our own advice.
- Quiz: for the mirror start the correct option is information that breaks the symmetry or a multimodal filter; 'about 11.8 units' matches the output (11.800/11.799) and the arbitrary-units statement.
- zh and en compared section by section: claims, numbers, exercises and hedges agree; display equations and source sets are identical; MDX is safe; unwritten topics stay inline code, and the published finite-differences topic is now linked.
Source locations checked:
- Bayesian Filtering and Smoothing — scoped · pdftotext, printed pages. p. 64 (Ch. 5 opening: EKF, SLF, UKF; UKF converges to EKF in a parameter limit; §5.1 eqs. 5.1–5.2); p. 65 (non-Gaussian for all but linear g; Taylor expansion eqs. 5.3–5.7); p. 66 (covariance eq. 5.8, augmented transform eqs. 5.9–5.11); p. 67 (Algorithm 5.1 eqs. 5.12–5.14; non-additive transform eqs. 5.15–5.16); p. 68 (Algorithms 5.2–5.3 eqs. 5.17–5.22); p. 69 (Hessian eq. 5.23; §5.2 opening, eqs. 5.24–5.25, Algorithm 5.4 prediction eq. 5.26); p. 70 (update eq. 5.27, derivation eqs. 5.28–5.31); p. 71 (eqs. 5.32–5.36, non-additive model eq. 5.37, Algorithm 5.5 eqs. 5.38–5.39); p. 72 (Jacobians eqs. 5.40–5.43; advantages/disadvantages paragraph); p. 73 (Algorithm 5.6 second-order EKF eqs. 5.44–5.47); p. 74 (Fig. 5.1 caption RMSE 0.12; Example 5.1 eq. 5.48); p. 75 (eqs. 5.49–5.50; RMSE 0.12 vs noise std 0.32; §5.3 opening); pp. 76–77 skimmed (Algorithms 5.7–5.8). pp. 204–205 (§13.1). NOT read: §5.4–5.6, Ch. 6–12.
- State Estimation for Robotics — scoped · pdftotext, printed pages. p. 100 (end of §4.2.2; §4.2.3 opening: Gaussian belief + Gaussian noise + linearisation → EKF; mainstay for mildly nonlinear systems; Schmidt/NASA Ames/Apollo history, McGee and Schmidt 1985, Schmidt–Kalman name, square-root work; footnote 5 'extended'); p. 101 (Striebel/RTS; eqs. 4.21–4.26; noise inside the nonlinearity); p. 102 (eqs. 4.27–4.30); p. 103 (eq. 4.31, classic EKF eqs. 4.32, two differences from the KF, 'no guarantee ... diverge wildly ... biased or inconsistent or both', start of §4.2.4); p. 105 (end of §4.2.4; §4.2.5 IEKF eqs. 4.38–4.43); p. 106 (eqs. 4.44–4.46, iteration rule; §4.2.6 IEKF is MAP, footnote 6 single timestep); p. 107 (Fig. 4.7 stereo example x_true = 26 m; mean of IEKF = mode not mean; §4.2.7 opening, footnote 7). NOT read: p. 104, §4.2.7 body pp. 108–116, §4.2.8–4.2.9, §4.3 onward.
- An Introduction to the Kalman Filter (TR 95-041) — scoped · pdftotext of 95-041.pdf. §2 pp. 7–11: p. 7 (EKF = KF that linearises about current mean and covariance; eqs. 2.1–2.4); p. 8 ('fundamental flaw': distributions no longer normal; EKF ad hoc, approximates optimality of Bayes' rule by linearisation; Julier et al.; eqs. 2.5–2.6 and Jacobians A, W, H, V); p. 9 (error process eqs. 2.7–2.13, hypothetical second KF); p. 10 (Tables 2-1/2-2, eqs. 2.14–2.18); p. 11 (Fig. 2-1; Jacobian H magnifies only the relevant residual component; non-one-to-one mapping over all measurements → filter diverges quickly, process unobservable).
- Kalman and Bayesian Filters in Python · 11-Extended-Kalman-Filters.ipynb at commit 04b2bea802321086effbd99402fc13c893d11110, markdown cells only: 4 (EKF linearises at current estimate; most common technique; author avoids it where possible), 5 (two kinds of nonlinearity; passing a Gaussian through a nonlinearity is not Gaussian), 7 (Jacobians F, H; KF vs EKF table; propagate with f and compute residual with h), 8–11 (radar example set-up), 38–44 (range-bearing landmark measurement model, R), 46 (bearing residual wrapping, 1° vs 359°), 48–59 (simulation notes; fewer landmarks → divergence; discussion of model simplifications and SLAM), 60–64 (UKF vs EKF: no Jacobians, 2n+1 sigma points, x³ example). NOT read: code cells, other chapters' EKF material, filterpy source.
Related topics