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.
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.
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.
| Effect | What it is | Fingerprint in the histogram | Can averaging remove it? |
|---|---|---|---|
| Bias | A 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 noise | Small unpredictable scatter from electronics, vibration and turbulence. | The width of the bell. | Yes, with the square-root law: n independent readings give σ/√n. |
| Quantization | The 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. |
| Outliers | Readings 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. |
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
- The true value of the quantity being measured.
- Bias
- The average error of the good readings: . It does not change from reading to reading.
- Noise
- The random part of the error, with mean zero and standard deviation .
- Quantization step
- The spacing between the values a sensor can report. Rounding to the nearest step is the operation .
- Outlier probability
- 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: . The typical distance from the median, computed without ever squaring.
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 . When the true value falls anywhere between two steps with no preference, the rounding error is uniform on .
A uniform density on an interval of length (the previous lesson).
The error is as likely to be positive as negative.
The variance is the average squared error. The integral of is .
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 , and the MAD is a fixed multiple of .
By definition of a median, half of the absolute deviations are below the MAD.
Standardize: is a standard normal, whose cumulative distribution is .
Solve for the ratio. The value is the 75th percentile of the standard normal (
gaussian_ppf(0.75)).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
Replace one reading by a wild value . The mean moves by and can be made as large as you like.
However large 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.
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.
- 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.
- Robust statistics. The median is 2.0117 m and mm. Both are close to the truth of the good readings (2.012 m and 8 mm).
- The naive rule fails. Flag readings more than 3 standard deviations from the mean. The threshold is 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.
- The robust rule works. Flag readings more than 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).
- 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.
- Quantization. A sensor that rounds to 1 cm adds an error with standard deviation 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
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
- 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.
- 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.
- Averaging reduces noise (σ/√n) but not bias, quantization of a steady value or outliers. Calibration removes bias; robust statistics deal with outliers.
- 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.
- 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.
Related content
Nothing below is required to finish this lesson.
- BeforeM2-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.
- LabM2-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:
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.