An IMU never measures where you are. It measures change, and you add the change up. Sit a phone-grade IMU still for one minute and the sum says it moved 64 m. A navigation-grade IMU says 0.45 m.
Pick an IMU grade and watch a drone that never moves walk away from its pad. Then we build, piece by piece, what the sensor reads, the frames, the three strapdown stages, the drift laws, the noise, and the first cure.
You need integration as adding up and a little arithmetic. We build the rest from zero.
Lesson 13 of 22 in Sensor Fusion: Classical to Modern. It follows Data Association and leads to INS/GNSS Coupling.
Illustrative, order of magnitude: constant biases only, no noise. Phone: gyro 36°/hr, accel 0.01 m/s². Tactical: 1°/hr, 0.001 m/s². Navigation: 0.01°/hr, 0.00025 m/s². The accel error runs north, the gyro error east.
Chapter 0
Add up a still sensor's readings and watch the position walk away
A drone hovers over its landing pad, perfectly still. A small chip on its back reads motion a thousand times a second. You add up the motion it reports to track the drone. After ten seconds the sum says the drone is half a metre off the pad. It has not moved.
The chip is an inertial measurement unit (IMU): three accelerometers and three gyroscopes, the same parts as in your phone. Nothing is broken. An IMU measures change, never position. To get position you add the change up twice, and you add up its small errors too.
The drone is still, so the true position is the dashed zero line. The accelerometer adds a small constant error. Set it, press Run, and watch the blue estimate.
Illustrative: a 100 Hz accelerometer with the bias you set plus small white noise, integrated twice with simple sums.
A constant error of 0.01 m/s² is one thousandth of gravity. After 60 s it becomes 18 m of position error. The curve is a parabola: the error does not only grow, it grows faster and faster.
Adding up your own motion from a known start is called dead reckoning. Sailors did it with a compass and a speed log. They fixed the growing error with a star or a lighthouse. Modern systems do the same with GPS, a camera, or a moment when they know they are still.
Chapter 1
Read turn rate from the gyro, and learn why the accelerometer reads up when it sits still
The gyroscope measures angular rate: how fast the sensor turns about each of its three axes, in degrees or radians per second. Spin it at a steady 90°/s and it reads 90°/s the whole time. It gives rate, not angle. To know which way you point, you add the rate up over time.
The accelerometer is the trap. Inside it, think of a small proof mass on a spring. The chip reports how far the spring stretches. Gravity pulls on the mass and on the case equally, so gravity alone does not stretch the spring. Only a push on the case does.
Choose a situation. Watch the spring and the three arrows: true acceleration a in yellow, gravity g in pink, the reading f in blue.
Exact physics in one dimension, up is positive, g = −9.81 m/s². The lift moves up and speeds up or slows at 2 m/s².
So the accelerometer reads the push that stops you falling. Call that push per kilogram the specific force f. Call your true acceleration through space a, and the gravity vector g. With up as positive, g is −9.81 m/s².
f equals a minus g.
Take the true acceleration a and remove gravity g. What is left is the reading f. To recover a, add g back: a = f + g.
On a table, a = 0, so f = 0 − (−9.81) = +9.81 m/s², pointing up. In free fall a = g, so f = 0. In a lift speeding up at 2 m/s², f = 2 + 9.81 = 11.81 m/s²: you feel heavier.
Adding g back is easy only if you know which way down is. Down comes from the attitude, and the attitude comes from the drifting gyro. If the attitude is off by 0.1°, a slice of gravity leaks sideways: 9.81 × sin 0.1° = 0.017 m/s². That leak is larger than a good accelerometer's whole bias.
So an IMU gives six numbers, hundreds of times a second: three angular rates ω and three specific forces f, both in the sensor's own axes. Orientation, velocity and position are not in that list. You build them.
Chapter 2
Move readings from the tumbling sensor into the steady world, and catch the sign bug
The IMU reports everything along its own axes. Those axes roll and pitch with the vehicle. You want answers along fixed world directions: north, east, down. A frame is a set of three axes, and inertial navigation uses three of them.
| Frame | Fixed to | Axes | Used for |
|---|---|---|---|
| Body (b) | the sensor | x forward, y right, z down (aerospace) | the raw ω and f |
| Navigation (n) | a point on Earth | NED: north, east, down. Or ENU: east, north, up | velocity and position you report |
| Earth (e, ECEF) | Earth's centre, turning with it | x through 0° latitude and longitude, z through the pole | GPS coordinates, long flights |
The attitude is the rotation from the body frame to the navigation frame. Store it as a 3 by 3 rotation matrix C or as a four-number quaternion. Most strapdown code uses the quaternion, because it stays clean when renormalised. Multiply a body vector by C and you get the same arrow in world axes.
The vehicle sits still. The blue arrow is its reading, always 9.81 m/s² up. Tilt it and watch the reading split across the body axes. Then feed it to code that expects the other z sign.
Exact geometry in the pitch plane. "z axis flipped" feeds a z-up body frame (ROS style) into code written for z-down.
At 20° of pitch the reading splits into 3.36 m/s² along the nose and 9.22 m/s² along the body z axis. Rotate it back with the right attitude, add gravity, and the vertical acceleration is zero. The vehicle is still, and the numbers agree.
Now the most common frame bug. A z-up IMU reports +9.81 on z at rest. Code written for z-down treats that as 9.81 downward and adds gravity, another 9.81 downward. It computes 19.62 m/s²: twice gravity. After 2 s the altitude estimate has dropped 39 m.
Chapter 3
Run the three stages every tick, attitude first, and watch one gyro error flow through all three
Old systems held the sensors level on gimbals. Modern systems bolt them to the vehicle and level them in software. That is strapdown mechanization: three stages, run every IMU tick, in a fixed order.
Stage 2 needs to know where down is, so stage 1 must come first. Work in the pitch plane to keep it small. Call the pitch angle at tick k theta-k, the gyro rate omega-k, and the time between ticks delta-t.
theta-k-plus-one equals theta-k plus omega-k times delta-t.
Multiply the gyro rate omega-k by the tick length delta-t. Add that small turn to the old angle theta-k.
theta-k = 10°, omega-k = 30°/s, delta-t = 0.005 s. The turn is 0.15°, so theta-k-plus-one = 10.15°. A bias of 0.01°/s adds 0.00005° per tick: 0.6° after 12,000 ticks, one minute.
In 3-D the same step multiplies C by a small rotation, (I + ΩΔt), where Ω holds the three gyro rates. Next, call the reading in body axes f-b, the attitude rotation C, gravity in world axes g-n, and the world acceleration a-n.
a-n equals C times f-b, plus g-n.
Turn the reading f-b into world axes with C. Add gravity g-n back. The result a-n is the acceleration you can add up.
A level car speeds up at 2 m/s². It reads 2 forward and 9.81 up. Rotate with the true attitude, add gravity: a-n is 2 forward, 0 vertical. With C off by 0.6°, a-n is 2.103 forward: 0.103 m/s² of phantom push, all from gravity.
Last, call the velocity at tick k v-k and the position p-k. Two sums finish the loop.
v-k-plus-one equals v-k plus a-n times delta-t. p-k-plus-one equals p-k plus v-k times delta-t.
Add a-n times delta-t to the velocity. Add the old velocity v-k times delta-t to the position. Repeat every tick.
v-k = 3 m/s, a-n = 2 m/s², delta-t = 0.01 s. v-k-plus-one = 3.02 m/s and the position moves 3 × 0.01 = 0.03 m.
The vehicle sits still. The gyro has a bias you set. Press Step to run one second of ticks and watch the error pass through the three stages.
Illustrative: a bias far larger than a real gyro's, so the chain shows in seconds. 100 Hz ticks, pitch plane, exact sine of the attitude error.
The failure to watch for is fast motion. If the vehicle vibrates faster than the tick rate can follow, the simple sums under-rotate (coning) and invent velocity (sculling). Production code adds correction terms and runs at kilohertz on a drone with propeller vibration.
Chapter 4
Derive both drift laws from the three stages and see why the gyro wins the race to ruin
Two small constant errors start everything. The accelerometer reads too much by the same amount every tick. The gyro reads a turn that is not there. Follow each one through the strapdown loop.
Call the accelerometer's constant error the accel bias b-a, and the time since the start t. Stage 3 adds it up once into a velocity error b-a times t. It adds that up again into position.
delta-p equals one half times b-a times t squared.
Square the time t. Multiply by the bias b-a and halve it. That is how far the estimate has walked.
b-a = 0.01 m/s². At t = 10 s, delta-p = 0.5 × 0.01 × 100 = 0.5 m. At 60 s, 18 m. At 300 s, 450 m. The phantom speed at 60 s is 0.01 × 60 = 0.6 m/s.
Now the gyro. Call its constant error the gyro bias b-g, in radians per second, and gravity's size g. Stage 1 turns it into an attitude error b-g times t. Stage 2 then tilts gravity by that angle, so a slice g times b-g times t leaks sideways. That leak already grows with time, and stage 3 adds it up twice.
delta-p equals one sixth times g times b-g times t cubed.
Convert b-g to radians per second. Multiply by gravity g and by t cubed, then divide by 6. The gyro path has one more sum than the accel path, so it gets one more power of t.
b-g = 0.01°/s = 0.0001745 rad/s. At 60 s the attitude error is 0.6°, and delta-p = 9.81 × 0.0001745 × 216,000 / 6 = 61.6 m. At 10 s it is only 0.29 m.
Blue is the accel-bias parabola, warm is the gyro-bias cubic, the thin line is their sum, the worst case where both push the same way. Drag the two biases and find where the cubic takes over.
Exact closed forms, constant biases only, short times. Past about 10 minutes gravity starts to pull a tilted estimate back (the Schuler effect), and these laws overstate the error.
Set the two curves equal and solve for t: the cubic passes the parabola at t = 3 b-a / (g b-g). With the default numbers that is 17.5 s. After that, gyro quality decides your error, which is why a navigation-grade IMU spends most of its cost on the gyros.
Chapter 5
Tell the error types apart, and read them all off one curve on a datasheet
One constant bias was a simplification. A real IMU axis has several errors, each with its own cure.
| Error | What it is | Cure |
|---|---|---|
| Turn-on bias | an offset that changes at each power-up | average at rest, subtract |
| In-run bias | the bias wandering slowly while you run | estimate it online, as a filter state |
| Scale factor | the reading off by a percentage: 0.1% of a 100°/s turn is 0.1°/s | calibrate on a rate table |
| Misalignment | axes not square, so x motion leaks into y | calibrate a 3 by 3 correction |
| White noise | a fresh random error on every sample, average zero | nothing removes it; model it |
White noise averages to zero, but its sum does not stay at zero. It wanders like a drunk walker, and the spread grows as the square root of time. For a gyro, the sum is an angle, and this wander is the angle random walk (ARW). Call the datasheet's ARW number N and the time t.
sigma-theta equals N times the square root of t.
Write the time t in hours. Take its square root. Multiply by N. Four times the time gives only twice the error.
N = 0.3°/√hr. After 10 minutes, t = 1/6 hr and √t = 0.408, so sigma-theta = 0.12°. After 1 hour, 0.3°. After 4 hours, 0.6°.
The accelerometer has the same law for velocity, the velocity random walk (VRW), in m/s per root-hour. To measure all of these, log the IMU at rest for hours. Cut the log into bins of length tau, average each bin, and measure how much neighbouring averages differ. That spread against tau is the Allan deviation.
The purple curve is the Allan deviation of a gyro. Each dashed line is one error. Drag the three knobs and read the noise at tau = 1 s and the floor.
The standard three-term model (IEEE Std 952): N²/tau, plus 0.44 B², plus K² tau / 3, under a square root. Knob values are illustrative, MEMS-like.
| Part of the curve | Slope on log axes | Error it shows |
|---|---|---|
| Left, short tau | falls, −1/2 | white noise: read ARW at tau = 1 s |
| Bottom | flat, 0 | bias instability: the floor is about 0.66 B |
| Right, long tau | rises, +1/2 | bias random walk: averaging longer now hurts |
Chapter 6
Turn the cube law around to find how long each grade of IMU stays useful alone
A car enters a tunnel and loses GPS. How long can its IMU navigate alone before the error passes 10 m? The answer depends on the IMU's grade: the class it belongs to, set mostly by its gyro bias.
| Grade | Gyro bias (rough) | Where you find it |
|---|---|---|
| Consumer MEMS | 10 to 100°/hr, and worse | phones, drones, headsets |
| Tactical | 1 to 10°/hr | UAVs, robots, guided munitions |
| Navigation | about 0.01°/hr | airliners, ships, submarines |
| Strategic | below 0.001°/hr | strategic submarines, ballistic missiles |
Call the error you can accept the budget D, in metres. Set the gyro's cube law equal to D and solve for the time. Call that time the coast time, t-c.
t-c equals the cube root of six D over g times b-g.
Multiply the budget D by 6. Divide by gravity g times the gyro bias b-g. Take the cube root. That is how long you can coast.
D = 10 m. A tactical gyro of 1°/hr is 0.00000485 rad/s. 60 / (9.81 × 0.00000485) = 1,262,000, and its cube root is t-c = 108 s. A phone gyro of 36°/hr gives 33 s.
Each bar is how long one grade coasts before its gyro error reaches the budget. Drag the budget and watch the bars move by only a cube root.
Illustrative: the gyro term only, constant bias. Phone 36°/hr, tactical 1°/hr, navigation 0.01°/hr, strategic 0.001°/hr. Past about 10 minutes the Schuler effect bounds the error, so the cube law is only a guide there.
The cube root is brutal. To coast twice as long at the same budget, you need a gyro eight times better. That is why each step up the ladder costs an order of magnitude more.
Chapter 7
Drive a loop on a biased IMU, then use each stop to reset the velocity and learn the bias
A walker's foot is flat on the ground for a moment in every stride. A car stops at a light. At that moment the true velocity is exactly zero, and you know it without any other sensor.
A zero-velocity update (ZUPT) uses that fact. At each known stop it does two things:
The dashed loop is the true path; the vehicle stops at each corner. Warm is pure dead reckoning. Turn ZUPT on for the teal estimate, then raise the biases.
Illustrative toy: a 20 m by 12 m loop at 2 m/s with a 3 s stop at each corner. The 100 Hz IMU has the biases you set plus small noise. ZUPT here resets velocity and learns the accel bias; it does not touch heading. On a loop the accel bias turns with the vehicle and partly cancels; on a straight road it would not.
With the default biases, pure dead reckoning ends 19 m off after three laps (144 s). With ZUPT it ends about 3 m off. The error that remains is heading: a stop tells you the speed is zero, not which way you face.
Walking trackers with an IMU on the foot run a ZUPT at every step. That alone turns hopeless MEMS drift into metre-level tracking over hundreds of metres, with no GPS. Many also add a zero angular rate update at rest, which learns the gyro bias the same way.
Chapter 8
Calibrate at rest, then name a bug from the shape of its error
The cheapest calibration is free. Before you move, hold the IMU still for a few seconds and average each axis. The gyro should read zero, so its average is the turn-on gyro bias. The accelerometer should read gravity's 9.81 m/s² upward, so its average minus that is the accel bias.
pythonimport numpy as np def calibrate_at_rest(gyro, accel, g=9.81): # gyro, accel: arrays (n, 3) logged while the IMU sits still and level, z axis down gyro_bias = gyro.mean(axis=0) # should read 0, so the mean IS the bias accel_bias = accel.mean(axis=0) - np.array([0, 0, -g]) # should read -g on z (support force up) if abs(accel_bias[2]) > g: # a "bias" near 2g is a frame bug, not a bias raise ValueError("z bias near 2g: check the z sign convention") return gyro_bias, accel_bias # every live sample: gyro_c = gyro - gyro_bias ; accel_c = accel - accel_bias
This removes only the turn-on bias. The in-run bias keeps wandering, so a good fuser keeps estimating it as a filter state. After calibration, the shape of any remaining error names its cause.
Each choice plants one fault in a 30 s log of a still IMU. Read which trace bends and how. Then calibrate at rest and see which faults survive.
Illustrative faults: accel bias 0.02 m/s², gyro bias 0.05°/s, a flipped z axis. The warm-up bias grows from 0 to 0.03 m/s². Calibration averages the first 2 s.
A straight velocity ramp at rest is an accel bias, and its slope is the bias itself.
slope = δv / t = ba · a ramp of 0.6 m/s over 30 s means ba = 0.02 m/s²
| Symptom | Cause | Fix |
|---|---|---|
| Velocity ramps at rest | accel bias | calibrate at rest; the slope is the bias |
| Heading ramps, path curves | gyro bias | average the gyro at rest |
| Vertical runs away at 2g | frame or gravity sign | check the z convention and the sign of g |
| Bias tracks chip temperature | thermal drift | warm up first, or apply the temperature curve |
| Acceleration flat-tops in hard moves | clipping at full scale | raise the range, such as ±16 g |
| Fused error grows with speed | time offset between sensors | hardware timestamps, or estimate the offset |
Chapter 9
Keep the equations, the numbers, the checklist and the code in one place
An IMU reads turn rate and specific force in its own axes. Strapdown adds the gyro up into attitude, uses it to rotate the reading and add gravity back, and adds the result up twice. Every constant error rides those sums into t² or t³ growth, so an IMU predicts and something absolute corrects.
| Quantity | Formula | Numbers from this page |
|---|---|---|
| Specific force | f = a − g | at rest +9.81 up; free fall 0; lift 11.81 |
| Attitude stage | θk+1 = θk + ωkΔt | 10° + 30°/s × 0.005 s = 10.15° |
| Acceleration stage | an = C fb + gn | 0.6° off: 0.103 m/s² phantom push |
| Integration stage | vk+1 = vk + aΔt, pk+1 = pk + vkΔt | 3 m/s to 3.02 m/s, +0.03 m |
| Accel bias drift | δp = ½ ba t² | 0.01 m/s²: 18 m at 60 s |
| Gyro bias drift | δp = (1/6) g bg t³ | 0.01°/s: 61.6 m at 60 s; crossover 17.5 s |
| Angle random walk | σθ = N √t | 0.3°/√hr: 0.12° in 10 min |
| Coast time | tc = ∛(6D / (g bg)) | 10 m budget: phone 33 s, tactical 108 s |
pythonimport numpy as np def strapdown_step(theta, v, p, gyro, f_body, dt, g=9.81): # pitch plane, world axes (x forward, z down); f_body = (f_x, f_z) in body axes theta = theta + gyro * dt # 1. attitude: add up the turn rate c, s = np.cos(theta), np.sin(theta) C = np.array([[c, s], [-s, c]]) # body -> world rotation for pitch theta a = C @ f_body + np.array([0.0, g]) # 2. rotate, then add gravity back (+g on down) p = p + v * dt # 3. position from the OLD velocity v = v + a * dt # velocity from the acceleration return theta, v, p # still and level: f_body = (0, -g) -> a = (0, 0). A biased gyro tilts C and leaks g into a[0].
| System | Grade | What corrects it |
|---|---|---|
| Phones, AR and VR headsets | consumer MEMS | camera, magnetometer, GPS, many times a second |
| Drones | consumer MEMS, gyro read at kilohertz | GPS, barometer, camera |
| Cars and robots | automotive to tactical | GNSS, wheel odometry, lidar, camera |
| Walking trackers | MEMS on the foot | a ZUPT at every step |
| Airliners, ships, submarines | navigation | occasional GNSS or a surfacing fix |
In every row the IMU does one job: it predicts motion fast and smoothly between slow absolute fixes. Only the grade and the correcting sensor change. That split is the predict and update steps of the Kalman filter.
Now press Present or Teach and derive it from memory: specific force, the three stages, both drift laws, the random walk and the coast time. Then go back to the pad and say why the phone-grade drone curves away.
Lesson 13 of 22 in Sensor Fusion: Classical to Modern on Engineermaxxing. The derivations follow Groves (2013) and Titterton and Weston (2004). Every toy number on this page carries the word illustrative.