Skip to the lesson
FixTheRobot Explore Robotics / Probability for Robotics / M2 Random Variables and Probability Distributions / M2-T4

Probability for Robotics · Theory · M2

M2-T4 — Distributions of Real Sensor Noise

A reading is the truth with four things done to it. Each leaves a different fingerprint in a histogram, and each needs a different fix.

  • Lesson 4 of 4
  • Beginner
  • Module 2: Random Variables and Probability Distributions
  • Theory
  • About 16 minutes to read

The Gaussian of the last lesson is a good description of the scatter of a healthy sensor, and a poor description of the sensor as a whole. Real readings are also shifted, rounded onto a grid, and occasionally just wrong. This lesson separates the four effects, shows how to recognise each in data, and introduces the estimators (median and MAD) that keep working when a few readings are very wrong.

Learning objectives

After this lesson, you should be able to:

  • Separate bias, random noise, quantization and outliers in a set of readings, and name the fingerprint of each in a histogram.
  • Write the mixture model of good readings plus outliers, and say what its parameters mean.
  • Derive the variance of quantization noise, Δ²/12, and the constant 1.4826 that turns the median absolute deviation into a standard deviation.
  • Explain why the mean and standard deviation fail with a few outliers while the median and MAD do not, and use them to flag outliers.

The intuition

Rover points a range sensor at a wall 2.000 m away and records 2000 readings. The histogram has two very different parts. Almost all the readings form a narrow bell near 2 m. A thin floor of other readings is spread over the whole range, from 0.2 m to 4 m.

One sensor, two views of the same 2000 readingsLeft: a histogram of all 2000 readings between 0 and 4 metres. A flat floor of a few readings per bin is spread over the whole range, and one tall bar near 2 metres, cut off at the top of the plot, holds almost everything. Right: a close-up of 1.96 to 2.06 metres with 2 millimetre bins. The readings form a bell shape centred at 2.012 metres, 12 millimetres to the right of the true distance of 2.000 metres, which is marked with a dashed line. An orange Gaussian curve fits the bell.0123405101520reading (m)readings per 0.1 m bin bar cut off: 1754 readingsoutliers: a flat floor 1.961.9822.022.042.06050100150200reading (m)readings per 2 mm bin true 2.000 mcentre 2.012 m
The same 2000 readings seen two ways. Left: the whole range, where a few readings per bin form a floor of outliers. Right: a close-up of the bell, whose centre (2.012 m) is 12 mm away from the true distance (2.000 m).

Read it the way a doctor reads a blood test. The close-up says two things: the scatter of the good readings is about 8 mm, and their centre is 12 mm too far. The wide view says that about one reading in 18 has nothing to do with the wall at all: it is a reflection, a person passing through the beam, a dropped echo. Four separate effects are in the data.

The four effects in sensor readings
EffectWhat it isFingerprint in the histogramCan averaging remove it?
BiasA systematic shift, the same every time: a wrong scale factor, a mounting offset, temperature drift.The centre of the bell is off the true value.No. Every reading is shifted the same way. Only calibration against a known reference removes it.
Random noiseSmall unpredictable scatter from electronics, vibration and turbulence.The width of the bell.Yes, with the square-root law: n independent readings give σ/√n.
QuantizationThe sensor reports a whole number of steps: encoder ticks, converter counts, a distance rounded to a centimetre.Isolated spikes at multiples of the step instead of a smooth curve.Only if other noise is at least about half a step wide; otherwise every reading rounds the same way.
OutliersReadings unrelated to the quantity: reflections, glass, other people, bad matches, dropped packets, maximum-range misses.A floor or isolated spikes far from the bell.No. A single wild reading drags the average arbitrarily far.
Four fingerprints in the distribution of a sensor’s readingsFour small panels. Bias: a bell curve whose centre sits to the right of the dashed line that marks the truth. Noise: a narrow and a wide bell centred on the same point. Quantization: instead of a smooth curve, a few vertical spikes at multiples of the step, the biggest at zero. Outliers: a logarithmic plot of the density in which a tall narrow peak sits on a long low flat floor.Biasthe centre is off the truthtruth Noisethe spread of the bell Quantizationonly multiples of the step Outlierslog density: a peak on a floorgood readingsoutlier floor
The four fingerprints. Each panel shows what one effect does to the distribution of readings. In real data they are all present at once.

Why does the distinction matter? Because the cures differ, and applying the wrong one can make things worse. Averaging more readings attacks noise and does nothing about bias or outliers. A calibration run attacks bias and does nothing about outliers. A filter that removes outliers needs a spread estimate that the outliers themselves have not already destroyed, and that is the idea behind the median and the median absolute deviation below.

Before choosing a filter, look at a histogram of the raw readings from a stationary sensor. It shows the bias, the noise, the quantization and the outliers at a glance, and it takes ten lines of code.

Definitions

Truth xx
The true value of the quantity being measured.
Bias bb
The average error of the good readings: E[z]−x\mathbb{E}[z] - x. It does not change from reading to reading.
Noise vv
The random part of the error, with mean zero and standard deviation σ\sigma.
Quantization step Δ\Delta
The spacing between the values a sensor can report. Rounding to the nearest step is the operation q(z)=Δ⋅round(z/Δ)q(z) = \Delta \cdot \mathrm{round}(z/\Delta).
Outlier probability ε\varepsilon
The share of readings that are unrelated to the truth.
Median
The middle value: half of the readings are below it and half above.
MAD
The median absolute deviation: MAD=mediani ∣zi−median(z)∣\mathrm{MAD} = \mathrm{median}_i\,|z_i - \mathrm{median}(z)|. The typical distance from the median, computed without ever squaring.
Reading model without outliers
z=x+b+v(a good reading)z = x + b + v \qquad\text{(a good reading)}
v∼N(0,σ2)v \sim \mathcal{N}(0, \sigma^2). With quantization the reported value is q(z)q(z), which adds a rounding error of its own.
Mixture of good readings and outliers
p(z)=(1−ε)  N(z;  x+b,  σ2)  +  ε  U(z;  zmin⁡,zmax⁡)p(z) = (1 - \varepsilon)\; \mathcal{N}(z;\; x + b,\; \sigma^2) \;+\; \varepsilon\; \mathcal{U}(z;\; z_{\min}, z_{\max})
With probability 1−ε1-\varepsilon the reading is a Gaussian good reading; with probability ε\varepsilon it is drawn from a flat distribution over the sensor’s range. The two weights sum to 1, so the density still has area 1.
Robust spread and an outlier rule
σ^=1.4826⋅MAD,flag zi if ∣zi−median(z)∣>k σ^\hat{\sigma} = 1.4826 \cdot \mathrm{MAD}, \qquad \text{flag } z_i \text{ if } |z_i - \mathrm{median}(z)| > k\,\hat{\sigma}
The constant 1.4826 makes σ^\hat\sigma equal the standard deviation when the readings are Gaussian (derived below). A threshold kk of 3 to 4 is typical.

The mixture in the second equation is a model with a long history in robotics: the range-sensor model of M5-T3: Range, Bearing and Beam Observation Models is the same idea with four components (a hit, an unexpected short reading, a maximum-range miss, a random reading).

Derivation: quantization noise and the robust spread

The variance of a rounding error

A sensor reports the nearest multiple of Δ\Delta. When the true value falls anywhere between two steps with no preference, the rounding error ee is uniform on [−Δ/2, Δ/2][-\Delta/2,\, \Delta/2].

  1. f(e)=1Δfor ∣e∣≤Δ2f(e) = \dfrac{1}{\Delta} \quad\text{for } |e| \le \dfrac{\Delta}{2}

    A uniform density on an interval of length Δ\Delta (the previous lesson).

  2. E[e]=∫−Δ/2Δ/2e 1Δ de=0\mathbb{E}[e] = \int_{-\Delta/2}^{\Delta/2} e\,\dfrac{1}{\Delta}\,de = 0

    The error is as likely to be positive as negative.

  3. Var(e)=∫−Δ/2Δ/2e2 1Δ de=1Δ⋅23(Δ2)3=Δ212\mathrm{Var}(e) = \int_{-\Delta/2}^{\Delta/2} e^2\,\dfrac{1}{\Delta}\,de = \dfrac{1}{\Delta}\cdot\dfrac{2}{3}\left(\dfrac{\Delta}{2}\right)^{3} = \dfrac{\Delta^2}{12}

    The variance is the average squared error. The integral of e2e^2 is e3/3e^3/3.

  4. σq=Δ12≈0.289 Δ\sigma_q = \dfrac{\Delta}{\sqrt{12}} \approx 0.289\,\Delta

    Rounding to a step adds a noise of about 29% of the step, however fine the sensor is otherwise. It combines with the other noise in quadrature (last lesson).

Why the constant is 1.4826

For Gaussian readings the median equals the mean μ\mu, and the MAD is a fixed multiple of σ\sigma.

  1. MAD=median ∣X−μ∣    ⇒    P(∣X−μ∣≤MAD)=0.5\mathrm{MAD} = \mathrm{median}\,|X - \mu| \;\;\Rightarrow\;\; P\bigl(|X - \mu| \le \mathrm{MAD}\bigr) = 0.5

    By definition of a median, half of the absolute deviations are below the MAD.

  2. P(∣Z∣≤MAD/σ)=2 Φ(MAD/σ)−1=0.5P\bigl(|Z| \le \mathrm{MAD}/\sigma\bigr) = 2\,\Phi(\mathrm{MAD}/\sigma) - 1 = 0.5

    Standardize: Z=(X−μ)/σZ = (X-\mu)/\sigma is a standard normal, whose cumulative distribution is Φ\Phi.

  3. Φ(MAD/σ)=0.75    ⇒    MADσ=Φ−1(0.75)=0.6745\Phi(\mathrm{MAD}/\sigma) = 0.75 \;\;\Rightarrow\;\; \dfrac{\mathrm{MAD}}{\sigma} = \Phi^{-1}(0.75) = 0.6745

    Solve for the ratio. The value 0.67450.6745 is the 75th percentile of the standard normal (gaussian_ppf(0.75)).

  4. σ=MAD0.6745=1.4826 MAD\sigma = \dfrac{\mathrm{MAD}}{0.6745} = 1.4826\,\mathrm{MAD}

    Invert. Multiplying a MAD by 1.4826 gives an estimate of the standard deviation that is correct for Gaussian data.

Why a single bad reading ruins the mean but not the median

  1. zˉ(M)=1n(∑i=1n−1zi+M)    ⇒    dzˉdM=1n\bar{z}(M) = \dfrac{1}{n}\Bigl(\sum_{i=1}^{n-1} z_i + M\Bigr) \;\;\Rightarrow\;\; \dfrac{d\bar{z}}{dM} = \dfrac{1}{n}

    Replace one reading by a wild value MM. The mean moves by M/nM/n and can be made as large as you like.

  2. median(z1,…,zn−1,M)∈[ z(k),  z(k+1) ]\mathrm{median}(z_1, \dots, z_{n-1}, M) \in \bigl[\,z_{(k)},\; z_{(k+1)}\,\bigr]

    However large MM is, it is still one value on one side of the middle. The median becomes a neighbour of the old one among the good readings.

  3. the median stays among good readings while fewer than half are bad\text{the median stays among good readings while fewer than half are bad}

    The share of bad readings an estimator survives is its breakdown point: 0 for the mean (one reading is enough) and 50% for the median and the MAD.

The mean and the standard deviation are the right tools for clean Gaussian data and the wrong tools for data that may contain outliers: the outliers inflate the standard deviation, which then fails to flag them. Use the median and the MAD to find the outliers first.

A worked example

Rover reads a wall at 2.000 m. The sensor has a bias of +12 mm, Gaussian noise of 8 mm, and returns a reading uniformly spread over 0.2 to 4.0 m, whatever the wall, with probability 6%. The program simulates 2000 readings (so the truth is known) and treats them as unknown data.

  1. Naive statistics. The mean is 2.0056 m and the standard deviation is 0.2461 m. The standard deviation is thirty times the 8 mm noise: the outliers account for almost all of it. It would be wrong to quote “σ = 25 cm” for this sensor.
  2. Robust statistics. The median is 2.0117 m and 1.4826×MAD=9.01.4826 \times \mathrm{MAD} = 9.0 mm. Both are close to the truth of the good readings (2.012 m and 8 mm).
  3. The naive rule fails. Flag readings more than 3 standard deviations from the mean. The threshold is 3×0.2461=0.743 \times 0.2461 = 0.74 m, so any outlier within 74 cm of the centre passes, 39% of them if they are uniform over 3.8 m. Of 106 real outliers the rule catches only 62.
  4. The robust rule works. Flag readings more than 4σ^=364\hat\sigma = 36 mm from the median. It catches 103 of the 106 and raises no false alarms (three outliers happened to fall inside the bell and cannot be told apart from good readings).
  5. Estimate the bias. After removal the mean is 2.0119 m and the standard deviation 8.3 mm: a bias of 11.9 mm against the true 12 mm. This estimate used the known truth; on a real robot the truth comes from a calibration fixture or a second, better sensor.
  6. Quantization. A sensor that rounds to 1 cm adds an error with standard deviation 0.01/12=2.890.01/\sqrt{12} = 2.89 mm. A simulation of 20 000 roundings gives 2.9 mm.
from robotprob import Rng, mean, std, median

rng = Rng(8)
true_d, bias, sigma, p_out = 2.000, 0.012, 0.008, 0.06
z, is_out = [], []
for _ in range(2000):
    out = rng.bernoulli(p_out)                       # the truth about each reading, known in simulation only
    is_out.append(out)
    z.append(rng.uniform(0.2, 4.0) if out else true_d + bias + rng.gauss(0.0, sigma))

print('mean   =', round(mean(z), 4), ' std        =', round(std(z), 4))
med = median(z)
mad = median([abs(v - med) for v in z])
s_rob = 1.4826 * mad
print('median =', round(med, 4), ' robust std =', round(s_rob, 4))

m0, s0 = mean(z), std(z)
n_true = sum(is_out)
naive = sum(1 for v, o in zip(z, is_out) if o and abs(v - m0) > 3 * s0)
print('true outliers          =', n_true)
print('naive 3-sigma rule     =', naive, 'caught')

flag = [abs(v - med) > 4 * s_rob for v in z]
caught = sum(1 for f, o in zip(flag, is_out) if f and o)
false_alarm = sum(1 for f, o in zip(flag, is_out) if f and not o)
print('robust 4-sigma rule    =', caught, 'caught,', false_alarm, 'false alarms')

good = [v for v, f in zip(z, flag) if not f]
print('after removal: mean =', round(mean(good), 4), ' std =', round(std(good), 4))
print('estimated bias         =', round(mean(good) - true_d, 4), 'm  (true 0.012)')

u = [rng.uniform(1.0, 2.0) for _ in range(20000)]    # rounding to 1 cm
qerr = [round(v / 0.01) * 0.01 - v for v in u]
print('rounding to 1 cm: error std =', round(std(qerr), 5), ' formula =', round(0.01 / 12 ** 0.5, 5))
mean   = 2.0056  std        = 0.2461
median = 2.0117  robust std = 0.009
true outliers          = 106
naive 3-sigma rule     = 62 caught
robust 4-sigma rule    = 103 caught, 0 false alarms
after removal: mean = 2.0119  std = 0.0083
estimated bias         = 0.0119 m  (true 0.012)
rounding to 1 cm: error std = 0.0029  formula = 0.00289
The simulation labels every reading as good or outlier so the two rules can be scored; real data have no such labels, which is why a rule must be justified by its model, not by its score on one log.

In robotics

Range sensors are mixtures

A lidar beam can hit the wall, hit a person who stepped in front of it, pass through glass and hit something behind, or return nothing at all (reported as the maximum range). Each case is a component with its own probability. The beam model in M5-T3: Range, Bearing and Beam Observation Models is this mixture with four components, and its weights are estimated from logged data in M5-T4: Identifying Noise Parameters from Data. A localizer that evaluates only the Gaussian “hit” component will be destroyed by the first person to walk through the scan.

Calibration is bias removal

Mounting offsets, scale factors and zero points are biases. They are measured against a reference: a surveyed wall, a turntable, a motion-capture system, or the static averages of an IMU on a level table. The UAV course shows the procedure for inertial sensors in IMU noise and bias modelling, including the fact that gyroscope bias drifts slowly, so it is a state to estimate and not a constant to subtract once.

Quantization limits resolution

Wheel encoders, joint encoders, ADCs and timestamps are quantized. The step sets a floor on resolution: an encoder with 4096 counts per revolution has a step of 0.088°, and the rounding noise of its angle is 0.025°. At low speed, when the step is large compared with the motion between samples, velocity estimates computed by differencing are dominated by it.

Outlier handling in estimation pipelines

Every robust method in robotics uses the idea of this lesson: separate readings that fit the model from those that do not, using a spread that the bad readings did not corrupt. RANSAC does it by voting (Robust Estimation and RANSAC), Kalman-filter gating by testing the innovation against its own covariance (M8-T2: EKF Localization with Landmarks), and robust loss functions in factor graphs by down-weighting large residuals (M11-T4: Nonlinear Least Squares and Pose Graph Optimization).

Outliers can be the signal

A reading that is flagged once is probably an outlier. A reading that is flagged for thirty frames in a row is not: the wall has moved, the door is open or the robot has been carried. A rule that discards every flagged reading forever has turned a map error into a locked-in belief. Count flagged readings over time, and treat a persistent run as evidence about the world, not as noise.

Common misconceptions

“Averaging more readings always improves the estimate.”

It reduces random noise by 1/√n. It leaves bias exactly as it was, lets a single outlier move the answer by M/n, and cannot recover resolution below a quantization step when the true value is constant. First find out which of the four effects dominates.

“Remove everything beyond 3σ, computed from the data.”

If the data contain outliers, the standard deviation includes them. In the example it was 0.246 m instead of 0.008 m, and the “3σ” rule kept 42% of the outliers. Estimate the spread robustly (median and MAD), or from a calibration run on clean data.

“Median and MAD are always better than mean and standard deviation.”

For clean Gaussian data the mean is the more precise estimator: its standard error is about 20% smaller than the median’s. Robust statistics buy safety against outliers at a small price in efficiency. Use the mean on data you have cleaned, or when outliers are impossible.

“Quantization is just another noise that averages out.”

Not when the underlying value is steady and the other noise is much smaller than the step: every reading rounds the same way, the rounding error is the same each time, and the average has the same error as one reading. It averages away only when some other noise (or deliberate dither) moves the value across step boundaries.

Key takeaways

  1. A reading is the truth plus a bias, plus random noise, then possibly rounded to a step, and with some probability replaced by an outlier.
  2. Each effect has its own fingerprint: a shifted centre, a wide bell, spikes at multiples of the step, a floor far from the bell. Look at a histogram of stationary readings first.
  3. Averaging reduces noise (σ/√n) but not bias, quantization of a steady value or outliers. Calibration removes bias; robust statistics deal with outliers.
  4. Rounding to a step Δ adds a noise of Δ/√12. The mixture model (1 − ε) Gaussian + ε uniform describes good readings and outliers; the median and 1.4826 × MAD estimate its centre and spread without being fooled.
  5. One bad value can move the mean without limit; the median survives until half of the readings are bad. Persistent outliers are evidence about the world, not noise.

References and further reading

Each source is marked free or paid. Free to read does not mean free to reuse: the course resources page lists every source with its licence.

  • C. Stachniss, “Observation Models” (video lecture) , the range-sensor mixture. Free to watch.
  • S. Thrun, W. Burgard and D. Fox, Probabilistic Robotics, MIT Press, 2005, section 6.3 (beam models of range finders). Paid book.
  • T. D. Barfoot, State Estimation for Robotics, 2nd edition, Cambridge University Press, 2024 , chapter “Handling Nonidealities in Estimation” (bias, outliers, robust estimation). Free to read as the author’s PDF; the book is copyrighted.
  • P. J. Rousseeuw and C. Croux, “Alternatives to the median absolute deviation”, Journal of the American Statistical Association 88 (424), 1993. The scale estimators of this lesson and their constants. Paid journal article.
  • P. J. Huber and E. M. Ronchetti, Robust Statistics, 2nd edition, Wiley, 2009, chapter 1 (breakdown point). Paid book.

Knowledge check

Three questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

A lidar measures a wall at 1.50 m. Of 100 readings, 97 are near 1.50 m with a standard deviation of 1 cm and 3 are the maximum range, 9.99 m. Estimate the mean and the median, and say which you would report.

Explanation

Mean ≈ (97 × 1.50 + 3 × 9.99) / 100 = (145.5 + 29.97) / 100 ≈ 1.755 m: 25 cm too large, from three wrong readings, and the standard deviation would be about 1.5 m. The median is the 50th and 51st values among 97 good readings below the three large ones, so it is about 1.50 m. Report the median (or remove the maximum-range returns, which are known to mean “no echo”, and then average). The mean is the wrong estimator whenever a few readings can be arbitrarily wrong.

Question 2

A position sensor reports in steps of 5 cm. What is the standard deviation of its rounding error? A robot is stationary and its true noise standard deviation is 1 cm. Will averaging 100 readings give an estimate good to 1 mm?

Explanation

The rounding noise has standard deviation Δ/√12 = 5/3.46 = 1.44 cm. With a true noise of only 1 cm, much smaller than the step, almost every reading rounds to the same multiple of 5 cm, so the 100 readings are almost identical and their average is no better than one reading: the error stays up to ±2.5 cm. Averaging helps only if the noise (or an intentional dither) is large enough, about half a step or more, to move the true value across rounding boundaries. Here a finer sensor, not more averaging, is needed.

Question 3

A cleaning robot flags any range reading more than 4σ from its prediction as an outlier and discards it. After a chair is moved against a wall, the readings in that direction jump from 2.00 m to 1.60 m and stay there. What happens, and how would you change the rule?

Explanation

Every new reading is about 40 cm (many σ) from the prediction, so each is flagged and discarded, and the robot keeps believing that the wall is at 2.00 m although the sensor has told it otherwise thirty times in a row. The rule treats a persistent change as a string of independent outliers. Better: remember how many consecutive (or recent) readings were flagged and, when the count passes a threshold, treat the readings as evidence about the world, for example by updating the map or inflating the uncertainty so the filter can accept the new measurements. An outlier is isolated; a run of consistent “outliers” is a change.

What’s next

Module 2 gave you random variables, their distributions and the model of a real sensor. Module 3 turns to the question those models exist to answer: given a reading, what should the robot believe? That is Bayes’ rule.

Practice this lesson

Sensor Noise Explorer

A range sensor reads a wall at a fixed distance and the readings scatter. Build the histogram, estimate bias and spread, and find the outliers a Gaussian cannot explain.

Next lesson

M3-T1 — Joint, Marginal and Conditional Probability

Build a joint table for two variables, marginalize it, condition on an observation and use the product rule and the law of total probability.

Nothing below is required to finish this lesson.

  • Before
    M2-T3: The Gaussian Distribution

    Read the mean and standard deviation of a Gaussian, use the 68-95-99.7 rule and the standard normal, and say when the Gaussian is a poor model.

  • Lab
    M2-L1: Sensor Noise Explorer

    A range sensor reads a wall at a fixed distance and the readings scatter. Build the histogram, estimate bias and spread, and find the outliers a Gaussian cannot explain.

Other courses on this site treat neighbouring topics from their own angle: