Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 38 ยท Sensors and Perception

Sensors and Noise

Learn how robot sensors work and why their data is imperfect: sensor types, accuracy versus precision, noise, bias, quantization, filtering and calibration in Python.

A sensor is the robot's connection to reality, and it is never a perfect one. A distance sensor says "0.52 m" when the wall is at 0.50 m, an encoder counts ticks in steps, a gyroscope slowly creeps even when still. Before you can build perception you must understand how sensors are wrong. This lesson classifies sensors, defines the vocabulary of measurement quality, and shows the basic tools to deal with errors: averaging, filtering and calibration.

Kinds of sensors

Category Examples Measures
Position and motion encoders, potentiometers, hall sensors joint angle, wheel rotation
Inertial accelerometer, gyroscope, magnetometer acceleration, rotation rate, magnetic heading
Range ultrasonic, infrared, time-of-flight, lidar distance to obstacles
Vision cameras, depth cameras images, color, 3D structure
Contact and force bumpers, force/torque sensors, tactile skin touch, forces
Environment temperature, gas, light surrounding conditions
Global GPS position on Earth

Each is described in later lessons: distance sensors, IMUs and cameras. A sensor may be active (sends out energy, like sonar or lidar) or passive (only listens, like a camera or microphone), and its output is analog (a voltage, read through an ADC) or digital (numbers over a bus such as I2C).

The vocabulary of measurement quality

  • Accuracy: how close the average reading is to the true value. Poor accuracy means a bias or systematic offset.
  • Precision (repeatability): how close repeated readings are to each other. Poor precision means large random noise.
  • Resolution: the smallest change the sensor can report (for example 0.1 degree). A 10-bit ADC splits its range into 1024 steps; this is quantization.
  • Range: the smallest and largest values it can measure.
  • Sampling rate and latency: how often it reports and how stale the data is.
  • Drift: a slow change of bias over time or with temperature.

A sensor can be precise but inaccurate (tight cluster in the wrong place) or accurate but imprecise (scattered around the right value). You need both, and you fix them differently: calibration fixes bias, averaging and filtering reduce noise.

Python Accuracy versus precision

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The red line is the true value. Precision shows as the width of the histogram; accuracy as how centered it is on the line.

Noise and averaging

Most random noise can be modeled as Gaussian: each reading is the true value plus a random error with standard deviation ฯƒ. Averaging n independent readings reduces the noise by 1/sqrt(n): 100 readings make the error ten times smaller. The price is time (and delay), and averaging cannot remove bias or follow a changing signal quickly.

For a changing signal use a moving average or an exponential filter (low-pass filter):

y_k = ฮฑ x_k + (1 - ฮฑ) y_{k-1}

A small ฮฑ smooths strongly but reacts slowly; a large ฮฑ follows fast but passes more noise. Choosing it is always a trade-off between noise and lag.

Python Smoothing a noisy distance signal

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the stronger filter (alpha=0.1) is calmer but lags behind the step at 5 s. A robot braking for that wall would react late. The filter you choose must match how fast the quantity can really change.

Outliers

Sensors sometimes give a plain wrong value: an ultrasonic sensor hears an echo from another robot, a camera is blinded by the sun. A mean is dragged along by a single outlier; the median is not. Median filters over the last 3 to 7 readings are a cheap first defense for range sensors.

Python Median filter versus mean

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Quantization and calibration

Digital sensors report in steps. A 10-bit ADC on a 3.3 V range has steps of about 3.2 mV; if the sensor changes less than that between samples, you see no change. Resolution limits how well you can estimate small differences (and derivatives, like speed from position, are especially noisy).

Calibration estimates and removes systematic errors. For a simple sensor, you collect pairs of (reading, true value) and fit a line:

true = gain * reading + offset

For an IMU or magnetometer, calibration also removes axis misalignment. Calibrate in conditions like the working ones, and repeat when temperature or mounting changes.

Python Calibrating a sensor with a straight-line fit

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Choosing a sensor

Ask these questions in order: what exactly do I need to measure, how accurately, how fast, over what range, and in what conditions (sun, dust, water, other robots)? Then consider cost, size, power and software support. Often the right answer is two cheap, different sensors whose errors differ, combined as in sensor fusion.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A sensor always reads 5 cm too high but repeats very consistently. How would you describe it?

    Consistent readings mean high precision; the constant offset is a bias, fixed by calibration.
  2. 2. By what factor does averaging 100 independent noisy readings reduce the noise standard deviation?

    Noise shrinks with the square root of the number of samples: sqrt(100) = 10.
  3. 3. What is the main cost of a strong low-pass filter (small alpha)?

    Smoothing and lag are a trade-off.
  4. 4. Which filter best removes isolated spurious spikes from a range sensor?

    A median ignores a single extreme value; a mean is pulled by it.
  5. 5. What does calibration remove?

    Calibration estimates and corrects bias, scale and misalignment; random noise needs filtering.

Summary

  • Sensors are described by accuracy (bias), precision (noise), resolution, range, rate and drift.
  • Averaging cuts random noise by the square root of the sample count but adds delay.
  • Low-pass and median filters trade noise against lag and robustness to outliers.
  • Calibration fixes systematic errors; do it against a trusted reference.

Next: Distance Sensors