An IMU drifts without limit, and GNSS goes silent in a tunnel. Fused, each covers the other. On this toy drive the IMU alone is 155 m off at the end of a 30 s tunnel. The fused estimate leaves the tunnel 6.6 m off and is back within 2 m one second later.
Pick a navigator and set the tunnel length. Watch who stays on the road. Then we build it piece by piece, from where to tap the receiver to the failures.
You need the Kalman filter and strapdown navigation. We build the rest from zero.
Lesson 14 of 22 in Sensor Fusion: Classical to Modern. It follows IMU & Inertial Navigation and leads to Calibration and Time Sync.
Illustrative planar toy: one 147 s lap of a 380 m block at 10 m/s, the tunnel starting at 74 s. Phone-grade IMU at 50 Hz: gyro bias 36°/hr, accelerometer bias 0.05 m/s² (this folds in the gravity leak of a 0.3° tilt). GNSS at 1 Hz with 1.5 m noise per axis. The IMU alone starts perfectly aligned; the fused filter starts with a 3° heading doubt.
Chapter 0
Find the moment when the drifting IMU and the noisy GNSS fix swap places
Your car enters a tunnel. The GNSS receiver loses the sky and stops reporting. The IMU keeps going, a hundred times a second. Lesson 13 showed what it does alone: its error grows with time squared and never comes back.
GNSS, the Global Navigation Satellite System (GPS, Galileo, GLONASS and BeiDou), has the opposite flaw. Each fix is absolute, and its error does not grow. But a fix comes about once a second, scatters by a metre or two, and needs open sky.
So the two sensors fail on different time scales. The IMU is good for seconds and bad for minutes. One GNSS fix is poor, but GNSS over minutes is good. Find the time where they swap places, and you know whom to trust when.
Warm is the IMU's error since a perfect fix. Blue is the noise of one GNSS fix. Move the two sliders and watch where the curves cross.
Illustrative; exact for a constant bias and a perfect start: the IMU error is one half b-a t squared. Real IMUs add noise and a tilt leak, so treat the crossover as a scale, not a deadline.
Call the accelerometer bias b-a and the noise of one GNSS fix sigma. Since a perfect fix, the IMU's error grows as one half b-a t squared. Set that equal to sigma and solve for the time.
t-star equals the square root of two sigma over b-a.
Double the GNSS noise sigma. Divide by the bias b-a. Take the square root. Before t-star the IMU is the better sensor; after it, a fresh fix is.
With b-a = 0.05 m/s² and sigma = 1.5 m: 2 × 1.5 / 0.05 = 60, and its square root is 7.7 s. A tactical IMU with b-a = 0.002 m/s² holds out for 38.7 s.
An INS/GNSS filter uses both all the time. The IMU carries the motion between fixes, and each fix pulls the drift back. In a tunnel the IMU coasts alone. It coasts better because the fixes before the tunnel taught it its own biases.
Chapter 1
Feed the filter the finished fix or each raw pseudorange, and see what survives below four satellites
A GNSS receiver is a small pipeline. It times each satellite's signal and turns the delay into a distance, the pseudorange. Then it solves four or more pseudoranges for one position, velocity and time. You can feed the filter from the end of that pipeline or from its middle.
The distance is "pseudo" because the receiver clock is wrong. A cheap clock is off by some time, and light covers 300 m in one microsecond. Call the satellite's known position p-i, the receiver position p, the clock offset delta-t and the speed of light c.
rho-i equals the length of p-i minus p, plus c times delta-t.
Take the straight-line distance from the receiver p to satellite p-i. Add the clock offset delta-t, turned into metres by c. The sum is the pseudorange rho-i.
With made-up numbers: the true distance is 21,000,000 m and the clock is 1 microsecond fast. Then c times delta-t is 299.79 m, so rho-i = 21,000,299.79 m. Three position unknowns plus one clock unknown need four satellites.
Loosely coupled integration takes the receiver's finished position and velocity as the measurement: the fix should equal the INS position. Tightly coupled integration takes each pseudorange, and each Doppler (the range rate from the frequency shift), as its own measurement. It carries the clock bias and clock drift as two more states.
Left, the sky: blue satellites are visible. Right, the position doubt: dashed purple before the update, teal after. Choose a coupling and slide the satellite count down.
Illustrative geometry, exact linear algebra: INS position doubt 5 m per axis, pseudorange noise 2 m, and a receiver clock the filter does not know (a worst case). One update, no time correlation.
In open sky the two give the same answer. Below four satellites, loose coupling gets nothing, while tight coupling still shrinks the doubt along each line of sight. With an unknown clock the first satellite only pins the clock. Deeply coupled integration goes further. The INS tells the receiver's tracking loops how the antenna moves, so they hold the signal through hard motion and weak signals.
| Coupling | Measurement | Satellites | Cost |
|---|---|---|---|
| Loose | the position and velocity fix | 4 for any fix | simple; the receiver's own filter correlates its errors in time |
| Tight | each pseudorange and Doppler | fewer than 4 still help | raw data, clock states, GNSS error models |
| Deep | the INS aids the tracking loops | holds weak signals | needs access inside the receiver |
Chapter 2
Split the state into a nominal path and a small error, and rotate the attitude instead of adding to it
A Kalman filter on the full navigation state has a hard job. Position spans thousands of kilometres while corrections are centimetres. The strapdown equations curve and run at hundreds of hertz. Attitude is not a vector at all.
The error-state Kalman filter (ESKF) splits the job. The strapdown loop of Lesson 13 runs at full rate and produces the nominal state: position, velocity and attitude, nearly right and slowly drifting. The filter estimates only the error state: how far the truth is from the nominal. Call the true state x, the nominal x-hat and the error delta-x.
x equals x-hat, combined with delta-x.
Start from the nominal x-hat. Add delta-x to every part that is a plain vector. Rotate the attitude by the small angles in delta-x. The result is x.
With made-up numbers: the nominal east position is 412.30 m and the error is −1.73 m, so x is 410.57 m. The nominal heading is 30.0° and the heading error is 0.4°, so the true heading is 30.4°.
Why does this help? Small errors grow in a straight-line way. Any smooth curve looks straight when you zoom in. So the error follows a linear model: the Jacobian of the strapdown equations, built as in Lesson 7. A linear model with Gaussian noise is where the Kalman filter is optimal.
Attitude needs care. A quaternion q stores attitude as four numbers whose length is 1. Add a small vector to it and the length is no longer 1, so it is no longer a rotation. Its four numbers also hold only three degrees of freedom, so a 4 by 4 covariance would be singular. The filter keeps three small angles δθ instead and composes them as a rotation (Solà 2017):
q = q̂ ⊗ δq, δq ≈ [ 1, ½δθ ] · q-hat is the nominal attitude, ⊗ the quaternion product, δθ three small angles in radians
The circle holds every valid heading, the planar version of a unit quaternion. The filter wants to correct the nominal heading by an angle. Choose how, then raise the angle.
Illustrative planar picture, exact geometry. A heading is the point (cos ψ, sin ψ); adding the tangent step δψ gives length √(1 + δψ²). A quaternion breaks the same way, by √(1 + δθ²/4).
This is the multiplicative attitude error, the MEKF of spacecraft attitude work. The filter adds the position, velocity and bias corrections. It rotates the attitude, so the quaternion stays exactly length 1 and the filter's attitude doubt is a clean 3 by 3 block.
Chapter 3
Open the fifteen-number error state and push its covariance through a GNSS outage
The standard INS/GNSS error state has 15 numbers in five blocks of three (Groves 2013). Each error is the truth minus the nominal.
| Block | Symbol | What it is | Why it is there |
|---|---|---|---|
| Position error | δp (3) | metres north, east, down | what a GNSS fix sees |
| Velocity error | δv (3) | m/s on each axis | it feeds the position error |
| Attitude error | δθ (3) | three small angles | a tilt leaks gravity into acceleration |
| Accel bias | ba (3) | m/s² on each axis | the t² drift of Lesson 13 |
| Gyro bias | bg (3) | rad/s on each axis | it turns the attitude: the t³ drift |
A tightly coupled filter adds clock bias and clock drift, for 17. The planar devices on this page use the 2-D cut: two position, two velocity, one heading, two accel bias and one gyro bias, eight states.
The blocks feed each other. Gyro bias turns into attitude error, attitude error tilts gravity into a false acceleration, and that becomes velocity error and then position error. Call the doubt now P-k, the chain over one step Phi, and the new noise of the step Q.
P-k-plus-one equals Phi times P-k times Phi-transpose, plus Q.
Push the old doubt P-k through the error chain Phi on both sides. Add the fresh noise Q. Do it every IMU tick. Between fixes nothing shrinks P.
With made-up numbers for one axis: position sigma 1 m, velocity sigma 0.1 m/s, delta-t 1 s. So P-k = diag(1, 0.01) and Phi = [[1, 1], [0, 1]]. Phi P-k Phi-transpose = [[1.01, 0.01], [0.01, 0.01]]. The position variance grew from 1 to 1.01 because velocity doubt flowed into position.
The purple band is plus and minus two sigma from P. Each warm line is one possible true error. Choose whether fixes taught the filter its accel bias before the outage, then set the outage length.
Illustrative one-axis model: start sigma 1 m and 0.1 m/s; accel bias sigma 0.002 m/s² (learned) or 0.05 m/s² (unknown); white accel noise 0.002 m/s²/√Hz. The twelve paths come from seeded draws of the same model.
Over a whole outage the steps add up. For one axis the closed form is position variance = 1 + 0.01 t² + (bias sigma)² t⁴/4, plus a small noise term. With an unknown bias of sigma 0.05 m/s², the position sigma after 30 s is 22.7 m. If fixes taught the filter its bias to sigma 0.002 m/s², the same outage ends at 3.3 m. The bias states earn their place in the tunnel.
Chapter 4
Estimate the error from one GNSS fix, fold it into the nominal, and zero the error state
A fix arrives. The filter has just predicted, so the error state is zero on average and its doubt is P. Work one axis, east, where the fix measures the position error directly.
The nominal says 412.30 m. GNSS says 409.80 m. The innovation is the measured minus the predicted: −2.50 m. Call the prior variance P: 9 m², so sigma is 3 m. Call the fix noise variance R: 4 m², sigma 2 m. Call the fix z and the nominal x-hat.
K equals P over P plus R. Delta-x-hat equals K times, z minus x-hat.
Divide the IMU's doubt P by the total doubt P plus R. That is K. Multiply the innovation, z minus x-hat, by K. That is the estimated error delta-x-hat.
K = 9 / 13 = 0.692. The innovation is 409.80 − 412.30 = −2.50 m, so delta-x-hat = 0.692 × (−2.50) = −1.73 m. The nominal is about 1.73 m too far east.
Now use the estimate. The arrow ← means "becomes".
x-hat becomes x-hat plus delta-x-hat. P becomes one minus K, times P. Delta-x-hat becomes zero.
Inject: add the estimated error delta-x-hat to the nominal x-hat. Shrink the doubt P by one minus K. Reset: the nominal now holds the correction, so set delta-x-hat to zero and keep P.
x-hat = 412.30 − 1.73 = 410.57 m. P = 0.308 × 9 = 2.77 m², so sigma falls from 3 m to 1.66 m. That beats both inputs: 1 / (1/9 + 1/4) = 2.77.
Repeat this at every fix and the error draws a sawtooth: it climbs while the IMU coasts and drops at each fix. The device runs the same filter on one axis with three error states: position, velocity and accel bias.
Teal is the true error of the fused estimate; purple is plus and minus two sigma; blue ticks are fixes. Drag the interval and watch the teeth grow.
Illustrative one-axis ESKF: true accel bias 0.05 m/s², accel noise 0.002 m/s²/√Hz, fixes with 1.5 m noise, 10 Hz IMU ticks, seeded. The filter starts not knowing the bias.
Chapter 5
Drive straight, then turn, and watch the heading doubt collapse only when the car accelerates
A GNSS position fix sees position directly. It sees velocity through how position changes. Everything else it sees only through the chain of Chapter 3, and some links in that chain switch off.
Heading is the classic case. A heading error turns the acceleration the INS adds up. If the car speeds up, brakes or turns, the wrong heading points that acceleration the wrong way, velocity drifts, and the fixes notice. Call the heading error delta-psi and the horizontal acceleration a.
delta-v-dot equals delta-psi cross a.
Multiply the heading error delta-psi by the acceleration a. The velocity error grows at that rate, at a right angle to a. With a = 0 it does not grow at all.
delta-psi = 2° = 0.035 rad. In a turn with a = 2.5 m/s², delta-v-dot = 0.087 m/s². Held for 10 s, that is 4.4 m of position error, which GNSS sees. On a straight at constant speed, a = 0, and the heading error stays hidden.
Purple is the filter's heading sigma; pink is the true heading error. GNSS fixes arrive every second in both drives. Choose a route.
Illustrative toy: the showcase's 8-state planar ESKF with a tactical IMU at 10 m/s. The turn is 90° with a 30 m radius. GNSS at 1 Hz with 1.5 m noise; starting heading doubt 3°. Seeded; the numbers in the text are this run's.
Driving straight for 120 s, the heading sigma stays at 3.0° through 120 fixes. With one turn at 20 s, it falls to 0.81° by 30 s and 0.21° by 120 s.
The same story hides the accel bias inside the tilt. A tilt error leaks g times the angle of gravity sideways, and a bias adds the same false push. A bias of 0.05 m/s² looks exactly like a 0.29° tilt. Only rotation tells them apart, because the bias turns with the body and the leak does not. So aircraft fly turns while they align, and a second antenna or a magnetometer gives heading without motion.
Chapter 6
Predict where the antenna is, and catch the offset that turns with the car
The filter tracks the IMU, bolted near the middle of the car. GNSS measures the antenna, often on the roof, a metre or two away. The fixed offset from IMU to antenna, measured once in body axes, is the lever arm r. Call the IMU position p, its velocity v, the body-to-world rotation C and the gyro turn rate omega.
p-ant equals p plus C times r. v-ant equals v plus C times, omega cross r.
Rotate the lever arm r into world axes with C and add it to the IMU position p. For velocity, cross the turn rate omega with r, rotate the result, and add it to v.
r = 1.5 m forward, 0.6 m right. Facing north, the antenna sits 1.5 m north and 0.6 m east of the IMU. Facing east, it sits 0.6 m south and 1.5 m east. Turning at omega = 0.2 rad/s (11.5°/s), omega cross r = 0.12 m/s backward and 0.30 m/s right: 0.32 m/s.
Warm is the IMU, yellow is the lever arm and antenna, blue is where the fix lands. Turn the car and switch the lever-arm term off.
Illustrative car, exact geometry. North is up, heading is clockwise from north, r = 1.5 m forward and 0.6 m right, the same lever arm as the Code Lab.
Leave r out and every fix disagrees with the filter by 1.62 m. The offset points wherever the car points, so no constant can cancel it. The filter then bends its bias and attitude estimates to explain geometry.
Chapter 7
Run the whole 8-state filter around a city block, then take away the bias states and watch it lie
Here is the whole filter on one lap of a city block. It has eight error states, an IMU at 50 Hz, GNSS at 1 Hz, and a tunnel on the third side. Every piece from Chapters 2 to 5 runs inside it: strapdown, propagate P, update, inject, reset.
The map shows the truth (dashed), the fixes (blue), the IMU alone (warm) and the fused path (teal) with its 1-sigma ellipse drawn 10 times larger. Below, the fused error against its own two-sigma band. Choose the IMU and the bias states, set the tunnel, and drive.
Illustrative planar toy, seeded, the same drive as the hero. Phone: gyro bias 36°/hr, accel bias 0.05 m/s². Tactical: 1°/hr, 0.002 m/s². "Bias states off" drops the three bias states and keeps everything else.
Start with the defaults: phone grade, bias states on, a 30 s tunnel. The fused estimate leaves the tunnel 6.6 m off, inside its own sigma of 7.5 m. The IMU alone is 155 m off by then. A tactical IMU coasts the same tunnel to 1.6 m.
Now turn the bias states off. The same tunnel ends 33.8 m off while the filter claims 1.7 m. Even with GNSS live its RMS error is 9.1 m, because the bias it cannot name pulls it away between fixes.
Chapter 8
Score every fix against the filter's own doubt, and name the fault from its shape
Every fix gives a free health check. The filter predicted the fix and how much it might miss. Call the innovation y and its predicted covariance S, which is H P H-transpose plus R.
N-I-S equals y-transpose times S-inverse times y.
Square the innovation y and divide by its predicted variance S. For one axis that is y squared over S. A healthy filter averages 1 per axis; a fix far above the gate is suspect.
With made-up numbers: predicted sigma 1 m and R = 2.25 m² give S = 3.25 m². A multipath fix 30 m off gives NIS = 900 / 3.25 = 277, far above the 99% gate of 6.63 for one axis. Without the gate the estimate would jump 30 / 3.25 = 9.2 m.
Top: the fused error and its two-sigma band. Bottom: the NIS of each fix against the gate line; red bars mark rejected fixes. Choose a fault, then switch the gate.
Illustrative one-axis filter at 30 m/s, fixes at 1 Hz with 1.5 m noise, gate 6.63 (chi-square, 1 axis, 99%). Multipath: one fix 30 m off at 40 s. Long outage: no fixes from 30 s to 70 s, an accel bias of 0.02 m/s² that appears in the tunnel (a temperature step), and a Q too small to cover it. Time offset: fixes stamped 0.1 s late.
| Symptom | Cause | Fix |
|---|---|---|
| One wild jump after a fix | multipath or spoofing | gate each fix on its NIS |
| Good fixes rejected after an outage | P grew too little (Q too small) | honest Q; relax the gate after long gaps |
| Error grows with speed | a time offset between IMU and GNSS | one clock (the receiver's PPS pulse); apply each fix at its own time |
| Offset that turns with heading | the lever arm | add C r and C(ω × r) |
| Heading will not settle | unobservable on straights | turn, or add a heading sensor |
| NIS average far from 1 | Q or R wrong | tune on logs (Lesson 21) |
A time offset is easy to compute: 20 ms at 30 m/s puts every fix 0.6 m behind.
Before buying a better IMU, use free measurements. A zero-velocity update (ZUPT) tells the filter the speed is zero at a stop. A non-holonomic constraint (NHC) tells it a car does not slide sideways or jump up.
Better GNSS slots in the same way. RTK (carrier phase plus a base station) reaches centimetres. PPP (precise orbits and clocks) reaches decimetres after it converges. Only R changes.
Chapter 9
Keep the equations, the numbers, the checklist and the code in one place
The strapdown loop runs the IMU at full rate and drifts. An error-state Kalman filter carries the doubt of that drift, estimates the error at every GNSS fix, injects it, and resets. Biases are states. The filter corrects attitude by rotation, predicts the antenna through the lever arm, and checks every fix against its own doubt.
| Quantity | Formula | Numbers from this page |
|---|---|---|
| Crossover | t* = √(2σ / ba) | 0.05 m/s², 1.5 m: 7.7 s |
| Pseudorange | ρi = ‖pi − p‖ + cδt | 1 µs of clock = 299.79 m |
| Error state | x = x̂ ⊕ δx | 412.30 − 1.73 = 410.57 m |
| Propagate | Pk+1 = ΦPkΦT + Q | 30 s outage: 22.7 m (bias unknown), 3.3 m (learned) |
| Update | K = P/(P+R), δx̂ = K(z − x̂) | K = 0.692, δx̂ = −1.73 m |
| Inject, reset | x̂ ← x̂ + δx̂, P ← (1−K)P, δx̂ ← 0 | P from 9 to 2.77 m² |
| Heading seen | δv̇ = δψ × a | 2°, 2.5 m/s²: 0.087 m/s² |
| Lever arm | pant = p + Cr | |r| = 1.62 m, turning with heading |
| Gate | NIS = yTS−1y | 99% gates: 6.63 (1 axis), 9.21 (2), 11.34 (3) |
pythonimport numpy as np def eskf_fix(nom, P, z, R, r_lever, gate=11.34): # error state (15): dp dv dth ba bg; nom holds p, v, C (3x3), ba, bg p_pred = nom['p'] + nom['C'] @ r_lever # predict the ANTENNA y = z - p_pred # innovation (3,) H = np.zeros((3, 15)); H[:, 0:3] = np.eye(3) # the fix sees dp (lever-arm attitude term left out) S = H @ P @ H.T + R if y @ np.linalg.solve(S, y) > gate: # NIS gate, 3 axes, 99% return nom, P, False # coast on the IMU K = P @ H.T @ np.linalg.inv(S) dx = K @ y # the estimated error I_KH = np.eye(15) - K @ H P = I_KH @ P @ I_KH.T + K @ R @ K.T # Joseph form: stays symmetric nom['p'] += dx[0:3]; nom['v'] += dx[3:6] # inject: add nom['C'] = nom['C'] @ rot(dx[6:9]) # inject: rotate (local error, as in Sola) nom['ba'] += dx[9:12]; nom['bg'] += dx[12:15] return nom, P, True # reset: the error mean is zero again def rot(th): # small rotation, Rodrigues formula a = np.linalg.norm(th); K = np.array([[0, -th[2], th[1]], [th[2], 0, -th[0]], [-th[1], th[0], 0]]) if a < 1e-12: return np.eye(3) + K return np.eye(3) + np.sin(a) / a * K + (1 - np.cos(a)) / a**2 * K @ K
| System | IMU | Aiding |
|---|---|---|
| Phones | consumer MEMS | GNSS, Wi-Fi, step detection |
| Cars | MEMS to automotive grade | GNSS, wheel speed, NHC |
| Drones | MEMS | GNSS, barometer, magnetometer |
| Mapping vans and survey aircraft | tactical to navigation grade | RTK GNSS, often tightly coupled |
| Airliners and ships | navigation grade | GNSS |
The ESKF is the complementary filter of Lesson 6 with its gain computed from the doubts. It trusts the IMU over short times and GNSS over long ones, and it moves the crossover by itself as P changes.
Now press Present or Teach and derive it from memory. Cover the crossover, loose against tight, the error state, propagate, one fix by hand, what a fix can see and the lever arm. Then go back to the tunnel and say why the fused car comes out close.
Lesson 14 of 22 in Sensor Fusion: Classical to Modern on Engineermaxxing. The structure follows Groves (2013) and Solà (2017). Every toy number on this page carries the word illustrative.