# C202 Lesson 2: Measuring IMU Noise with the Allan Deviation

> The second lesson of the C202 IMU course: how a long static log and its Allan deviation give the white noise and bias random walk of each sensor, where on the plot to read them, how long to record, how the values go into Kalibr's imu.yaml with the right units, and why static values are inflated before use.

Page: https://egocam.ai/university/c202/lesson-2-measuring-imu-noise/

A visual-inertial estimator weighs every IMU sample by how noisy it believes the sensor to be. Those beliefs are four numbers in Kalibr's `imu.yaml`. This lesson shows where they come from: a long recording of the IMU sitting still, and its Allan deviation. The full treatment is on [IMU Noise Models and Allan Variance](https://egocam.ai/calibration/imu-noise-and-allan-variance/); every field of the file is on the [Kalibr File Reference](https://egocam.ai/kalibr/kalibr-file-reference/#imuyaml-the-input-file).

## Terms used in this lesson

See also the [glossary's calibration section](https://egocam.ai/reference/glossary/#calibration).

| Term | Meaning |
|---|---|
| Averaging time τ | The length of the window a still IMU's output is averaged over |
| Allan deviation σ(τ) | How much the average over a window of length τ differs from the next window's, plotted against τ on log-log axes |
| Angle random walk (ARW), velocity random walk (VRW) | Datasheet names for gyroscope and accelerometer white noise, because integrated white noise becomes a random walk in angle or velocity |
| Bias instability | The flat bottom of the Allan deviation curve, the low-frequency wander of the bias |
| Rate random walk | A bias that wanders as a random walk; Kalibr's `*_random_walk` fields |
| Continuous-time noise density | Noise strength per root hertz, independent of the sample rate; what Kalibr's file holds |

## How the Allan deviation separates the noise

Take a long recording of the IMU sitting still. For each averaging time τ, cut the record into windows of that length, average each one, and measure how much neighbouring averages differ. Because the method uses differences, any constant cancels: the fixed bias, and gravity on an accelerometer axis. That is why a still IMU in any orientation can be used ([How the Allan variance is computed](https://egocam.ai/calibration/imu-noise-and-allan-variance/#how-the-allan-variance-is-computed)).

Each noise process dominates a different stretch of τ and has its own slope on the log-log plot. Kalibr's [noise model page](https://github.com/ethz-asl/kalibr/wiki/IMU-Noise-Model) calls this "probably the most common and standardized procedure", and models two of the processes:

| Process | Slope | Read it | Kalibr field |
|---|---|---|---|
| White noise (ARW, VRW) | −½ | on the curve at τ = 1 s | `gyroscope_noise_density`, `accelerometer_noise_density` |
| Bias instability | 0 | the flat minimum | none |
| Rate random walk | +½ | on the fitted +½ line at τ = 3 s | `gyroscope_random_walk`, `accelerometer_random_walk` |

> **Diagram:** An Allan deviation plot from hours of a stationary IMU. White noise is read on the falling line at τ = 1 s (Kalibr's noise density) and rate random walk on the rising line at τ = 3 s (Kalibr's random walk). The flat minimum is what Woodman and allan_variance_ros report as bias instability; by the IEEE 952 derivation the coefficient B is that minimum divided by 0.664.

The reading points are not arbitrary. White noise gives σ(τ) = N / √τ, which equals N at τ = 1 s; a rate random walk gives σ(τ) = K · √(τ / 3), which equals K at τ = 3 s. Each point is where the curve's value is the coefficient itself. The field guide's [table of the five noise terms](https://egocam.ai/calibration/imu-noise-and-allan-variance/#the-five-noise-terms-and-how-to-read-them) adds quantization noise (slope −1) and a drift rate ramp (slope +1). Two cautions from that page: a slope does not name a process for certain, and the ramp is not noise but a trend, such as a bias still settling.

**Bias instability has two conventions.** Woodman, and allan_variance_ros's `analysis.py`, report the curve's minimum. By the IEEE 952 derivation, the coefficient B is that minimum divided by 0.664, about 1.5 times larger. Find out which one a datasheet means before comparing ([Bias instability: two conventions](https://egocam.ai/calibration/imu-noise-and-allan-variance/#bias-instability-two-conventions)).

## How long to record

The right end of the plot rests on few windows, so it is uncertain. From the field guide's [confidence table](https://egocam.ai/calibration/imu-noise-and-allan-variance/#how-long-to-record-confidence-against-record-length), computed with Hou's formula:

| Record length | Error at τ = 1 s | Error at τ = 1,000 s | Error at τ = 6,000 s |
|---|---|---|---|
| 3 h | 0.7% | 22.6% | 79.1% |
| 15 h | 0.3% | 9.7% | 25.0% |
| 24 h | 0.2% | 7.7% | 19.3% |

The white noise at 1 s is well determined by any of them; the random walk, read from the long-τ end, is not. That is why the two tools ask for different lengths. The allan_variance_ros [README](https://github.com/ori-drs/allan_variance_ros) says "You must record at least 3 hours of data. The longer the sequence, the more accurate the results." The Kalibr wiki recommends running it on a "~15-24 hour dataset recording of the IMU being stationary".

How to record, from the same sources:

- **Still and damped.** "Place your IMU on some damped surface and record your IMU data to a rosbag." The Allan deviation is computed from whatever the sensor outputs, so vibration in the log is counted as sensor noise.
- **Timestamps in order.** The README recommends reorganising the bag's messages by timestamp first, with its `cookbag.py`. The method averages runs of consecutive samples, so samples stored out of order land in the wrong windows ([Temperature and the limits of a static plot](https://egocam.ai/calibration/imu-noise-and-allan-variance/#temperature-and-the-limits-of-a-static-plot)).
- **At a steady temperature.** An Allan plot describes one temperature. To the best of our knowledge, it is best to start the log once the rig has reached its working temperature, or cut the warm-up, because a settling bias shows up as a trend ([Temperature and the limits of a static plot](https://egocam.ai/calibration/imu-noise-and-allan-variance/#temperature-and-the-limits-of-a-static-plot)).
- **At the rate you will use.** Kalibr's [noise model page](https://github.com/ethz-asl/kalibr/wiki/IMU-Noise-Model) notes that its rate scaling assumes the sensor's own low-pass filter did the decimation, and that data simply subsampled to a lower rate may not be scaled that way ([continuous and discrete time](https://egocam.ai/kalibr/kalibr-file-reference/#continuous-time-and-discrete-time)).

## From the plot to imu.yaml

Kalibr's input file has four noise values, the IMU's rate and its topic ([YAML formats](https://github.com/ethz-asl/kalibr/wiki/Yaml-formats)):

| Key | Units | Meaning |
|---|---|---|
| `accelerometer_noise_density` | m/s² · 1/√Hz | accelerometer white noise, continuous time |
| `accelerometer_random_walk` | m/s³ · 1/√Hz | how fast the accelerometer bias wanders |
| `gyroscope_noise_density` | rad/s · 1/√Hz | gyroscope white noise, continuous time |
| `gyroscope_random_walk` | rad/s² · 1/√Hz | how fast the gyroscope bias wanders |
| `update_rate` | Hz | the IMU's sample rate in the bag |
| `rostopic` | – | the IMU topic in the bag |

Three things go wrong here more than anywhere else ([Kalibr File Reference](https://egocam.ai/kalibr/kalibr-file-reference/#imuyaml-the-input-file)):

- **Degrees for radians.** Gyroscope values are in rad/s, not °/s. allan_variance_ros prints its gyroscope results in degrees and converts them to radians when it writes `imu.yaml`.
- **A wrong `update_rate`.** Kalibr turns the continuous-time noise into a per-sample noise with it, σd = σ · √(update_rate); a wrong rate gives the IMU the wrong weight.
- **One value for three axes.** Kalibr uses the same value for all three axes of a sensor. The D435i example in the allan_variance_ros README has a Y-axis velocity random walk three times its X axis's (0.01079 against 0.00333 m/s/√s), which one number hides. Which axis the tool writes is covered in the [lab](https://egocam.ai/university/c202/lab/#a6-read-the-plots-and-the-numbers).

Without a long static log, the white-noise values can come from the datasheet, after unit conversion; the bias random walk is "rarely directly specified in the datasheet" ([Getting the values from a datasheet](https://egocam.ai/kalibr/kalibr-file-reference/#getting-the-values-from-a-datasheet)).

## Inflate the static values

A still IMU on a bench is a best case. The Kalibr wiki says the model "is derived from a sensor which does not undergo motion, and at constant temperature", so used as they are, the static values mean that "Kalibr will tend to trust your IMU measurements too much". Its advice: "From our experience, for lowest-cost sensors, increasing the noise model parameters by a factor of 10x or more may be necessary."

The TUM VI benchmark ran its VIO evaluations with "Noise parameters are set to inflated values from the Allan plots", "to account for unmodeled noise and vibrations", without giving the factor ([From the plot to the estimator](https://egocam.ai/calibration/imu-noise-and-allan-variance/#from-the-plot-to-the-estimator)). No source gives a universal factor. Lesson 3 shows how the residual plots in Kalibr's report tell you whether the values you chose fit the data. Keep the raw Allan values and the inflated values side by side, and write down the factor.

## Self-check

1. Where on the Allan deviation plot do you read Kalibr's `gyroscope_noise_density`, and where its `gyroscope_random_walk`?
2. Your log is 3 hours long. Which of the four noise values do you trust least, and why?
3. A datasheet gives bias stability as 3 °/h, and your measured curve minimum is 2 °/h. Can you say the part beats its datasheet?
4. Your `imu.yaml` says `update_rate: 100.0`, but the IMU runs at 400 Hz in the bag. What goes wrong?
5. Why does the Kalibr wiki say to raise the static noise values for low-cost sensors?

### Answers

1. The noise density on the −½ slope at τ = 1 s; the random walk on the fitted +½ line at τ = 3 s.
2. The random walks. They come from the long-τ end of the curve, where a 3-hour record has few windows; at τ = 6,000 s the error is about 79%.
3. Not yet. Check which convention the datasheet uses: the curve minimum, or the coefficient B, which is the minimum divided by 0.664.
4. Kalibr converts the continuous-time noise to a per-sample noise with the rate, so it assumes the wrong noise per sample and gives the IMU the wrong weight.
5. The values come from a still sensor at constant temperature, so they are optimistic; used directly, Kalibr trusts the IMU too much.

## Sources

- Field guide: [IMU Noise Models and Allan Variance](https://egocam.ai/calibration/imu-noise-and-allan-variance/), [Kalibr File Reference](https://egocam.ai/kalibr/kalibr-file-reference/), [IMU Calibration for Camera Rigs](https://egocam.ai/calibration/imu-calibration/), [glossary](https://egocam.ai/reference/glossary/#calibration).
- Kalibr wiki, ETH Zurich ASL: [IMU noise model](https://github.com/ethz-asl/kalibr/wiki/IMU-Noise-Model) and [YAML formats](https://github.com/ethz-asl/kalibr/wiki/Yaml-formats).
- Buchanan, R. [allan_variance_ros](https://github.com/ori-drs/allan_variance_ros), Oxford Robotics Institute (README and `scripts/analysis.py`, commit `1d54b60`).
- Schubert, D. et al. (2018). [The TUM VI benchmark for evaluating visual-inertial odometry](https://arxiv.org/abs/1804.06120). *IEEE/RSJ IROS*.
- Woodman, O. J. (2007). [An introduction to inertial navigation](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-696.pdf). Technical Report UCAM-CL-TR-696, University of Cambridge.
- Hou, H. (2004). [Modeling inertial sensors errors using Allan variance](https://www.ucalgary.ca/engo_webdocs/NES/04.20201.HaiyingHou.pdf). MSc thesis, University of Calgary.
