Chapter 7: Sensors in Robotics

Lesson 5: Noise, Resolution, Sampling Rate, and Drift

Real robot sensors do not measure physical quantities perfectly. This lesson builds a rigorous, quantitative understanding of four core limitations: (i) stochastic noise, (ii) finite resolution (quantization), (iii) sampling rate and aliasing, and (iv) drift/bias instability. We derive key formulas, prove fundamental bounds, and show how to model these effects in code.

1. Measurement Model and Big Picture

Many sensors can be abstracted by a continuous-time measurement model

\[ y(t) = x(t) + n(t) + b(t), \]

where \(x(t)\) is the true physical signal (position, angular rate, range, etc.), \(n(t)\) is zero-mean noise, and \(b(t)\) is a slowly varying bias (drift). The electronics then map \(y(t)\) into a digitized sequence \(y[k]\).

flowchart TD
  P["Physical quantity x(t)"] --> S["Sensing element"]
  S --> A["Analog signal y(t) = x(t) + n(t) + b(t)"]
  A --> F["Analog filtering"]
  F --> Q["Quantizer (finite resolution)"]
  Q --> D["Sampler -> y[k]"]
  D --> R["Robot software uses y[k]"]
        

Our goal is to characterize the statistics and distortions introduced by each block.

2. Noise as a Random Process

Noise \(n(t)\) is modeled as a random process. In robotics, a common first-order model is additive, stationary, zero-mean noise:

\[ \mathbb{E}[n(t)] = 0, \qquad R_n(\tau) = \mathbb{E}[n(t)n(t+\tau)], \]

where \(R_n(\tau)\) is the autocorrelation. The power spectral density (PSD) \(S_n(\omega)\) is the Fourier transform of \(R_n(\tau)\):

\[ S_n(\omega) = \int_{-\infty}^{\infty} R_n(\tau)\, e^{-j\omega \tau}\, d\tau . \]

Two important idealizations:

  • White noise: \(R_n(\tau)=\sigma^2\delta(\tau)\), hence \(S_n(\omega)=\sigma^2\) (flat spectrum).
  • Colored noise: PSD is frequency-dependent, e.g. \(S_n(\omega)\propto 1/\omega\) in low-frequency “flicker” regimes.

When sampling at period \(T_s\), the discrete-time noise sequence \(n[k]=n(kT_s)\) has variance \(\mathbb{E}[n[k]^2]=\sigma^2\) and discrete PSD that is periodic in frequency.

Signal-to-noise ratio (SNR). For a deterministic signal \(x(t)\) with average power \(P_x\), SNR is

\[ \mathrm{SNR} = \frac{P_x}{P_n}, \quad P_n = \mathbb{E}[n^2(t)] = \sigma^2 . \]

High SNR implies reliable sensing; low SNR implies measurements dominated by randomness.

3. Resolution and Quantization

The analog signal after conditioning is digitized by an ADC with \(B\) bits and full-scale range \([y_{\min},y_{\max}]\). The quantization step is

\[ \Delta = \frac{y_{\max}-y_{\min}}{2^{B}} . \]

Let \(\tilde{y}\) be the quantized value:

\[ \tilde{y} = Q(y) = \Delta\cdot \mathrm{round}\!\left(\frac{y}{\Delta}\right). \]

The quantization error is \(e_q = \tilde{y}-y\), bounded by \(-\Delta/2 \le e_q < \Delta/2\).

Uniform quantization noise model. If \(y\) is sufficiently “busy” over many levels, \(e_q\) is approximated as uniform on \([-\Delta/2,\Delta/2]\). Then:

\[ \mathbb{E}[e_q]=0, \qquad \mathrm{Var}(e_q)=\frac{\Delta^2}{12}. \]

Proof. For uniform density \(f(e)=1/\Delta\) on the interval:

\[ \mathbb{E}[e_q]=\int_{-\Delta/2}^{\Delta/2} e\frac{1}{\Delta}de = 0, \]

\[ \mathrm{Var}(e_q)=\mathbb{E}[e_q^2] =\int_{-\Delta/2}^{\Delta/2} e^2\frac{1}{\Delta}de =\frac{1}{\Delta}\left[\frac{e^3}{3}\right]_{-\Delta/2}^{\Delta/2} =\frac{\Delta^2}{12}. \]

Thus, quantization acts like an additional zero-mean noise term whose variance decreases quadratically with bit depth.

4. Sampling Rate and Aliasing

Sampling converts \(y(t)\) into \(y[k]=y(kT_s)\), where \(f_s=1/T_s\) is the sampling rate. If the underlying signal is band-limited to \(|\omega| \le \omega_{\max}\), we need a sufficiently large \(f_s\) to avoid aliasing.

Nyquist–Shannon condition. Perfect reconstruction from samples is possible if

\[ f_s > 2 f_{\max}, \qquad f_{\max}=\frac{\omega_{\max}}{2\pi}. \]

Sketch of proof (frequency-domain).

Sampling multiplies \(y(t)\) by an impulse train \(\sum_{k\in\mathbb{Z}}\delta(t-kT_s)\). In frequency, multiplication becomes convolution, yielding replicated spectra:

\[ Y_s(\omega) = \frac{1}{T_s}\sum_{m\in\mathbb{Z}} Y(\omega - m\omega_s), \quad \omega_s = \frac{2\pi}{T_s}. \]

If \(Y(\omega)=0\) for \(|\omega| > \omega_{\max}\) and \(\omega_s > 2\omega_{\max}\), the shifted copies do not overlap. Then applying an ideal low-pass filter that passes \(|\omega|\le\omega_{\max}\) extracts the original spectrum exactly, proving perfect reconstruction. If \(\omega_s \le 2\omega_{\max}\), overlap causes aliasing: distinct high-frequency components fold into low frequencies, creating irreversible error.

In practice, analog anti-aliasing filters are used before sampling to enforce band-limiting.

5. Drift and Bias Instability

Drift is a slow, often stochastic, variation in sensor bias. A common discrete-time model is

\[ b[k+1] = b[k] + w_b[k], \qquad w_b[k]\sim \mathcal{N}(0,\sigma_b^2), \]

i.e., bias follows a random walk. Then

\[ \mathbb{E}[b[k]] = b[0], \qquad \mathrm{Var}(b[k]) = k\sigma_b^2 . \]

So bias uncertainty grows unbounded with time unless corrected.

Effect on integrated quantities. Suppose a gyroscope measures angular rate \(\omega\):

\[ y[k]=\omega[k] + b[k] + n[k]. \]

Integrating to get angle \(\theta[k]=\sum_{i=0}^{k-1} T_s\, y[i]\) yields a bias-induced error

\[ \theta_{\text{bias}}[k] = \sum_{i=0}^{k-1} T_s\, b[i]. \]

If \(b[i]\approx b\) is approximately constant over the interval, then

\[ \theta_{\text{bias}}[k] \approx kT_s\, b = t\, b, \]

i.e., angle error grows linearly with elapsed time \(t\). This is why inertial sensors need frequent bias calibration.

6. Practical Combined Error Budget

With quantization, noise, and slowly varying bias, a discrete measurement is

\[ \tilde{y}[k] = x[k] + n[k] + b[k] + e_q[k]. \]

Assuming independence of \(n[k]\) and \(e_q[k]\), the instantaneous variance in the zero-mean disturbance is

\[ \mathrm{Var}(n[k]+e_q[k]) = \sigma^2 + \frac{\Delta^2}{12}. \]

Bias adds a non-zero mean term that must be estimated or bounded separately.

7. Python Lab — Simulating Noise, Quantization, Sampling, and Drift


import numpy as np

# Continuous-time "true" signal sampled very finely for simulation
fs_true = 5000.0
T_true = 1.0 / fs_true
t = np.arange(0, 2.0, T_true)
x = np.sin(2*np.pi*3*t) + 0.4*np.sin(2*np.pi*40*t)  # low + high freq content

# Sensor noise and drift models
sigma_n = 0.05
sigma_b = 1e-4
n = np.random.normal(0, sigma_n, size=t.size)

b = np.zeros_like(t)
for k in range(1, t.size):
    b[k] = b[k-1] + np.random.normal(0, sigma_b)

y_analog = x + n + b

# Sampling
fs = 100.0
Ts = 1.0 / fs
idx = (t / Ts).astype(int)
idx = np.unique(idx)
t_s = t[idx]
y_s = y_analog[idx]

# Quantization (B bits on range [-2,2])
B = 10
ymin, ymax = -2.0, 2.0
Delta = (ymax - ymin) / (2**B)
y_q = Delta * np.round(y_s / Delta)

print("Quantization step Delta:", Delta)
print("Measured variance (noise+quant):", np.var(y_q - np.sin(2*np.pi*3*t_s)))

# Simple bias estimation by averaging over a known "static" interval
# Here we pretend first 0.2s is static so x≈0 there.
static_mask = t_s < 0.2
b_hat = np.mean(y_q[static_mask])
y_comp = y_q - b_hat
print("Estimated bias:", b_hat)
      

This lab shows: (i) aliasing if \(f_s\) is too low compared to the 40 Hz term, (ii) quantization noise governed by \(\Delta^2/12\), and (iii) a crude bias calibration via mean subtraction.

8. C++ Lab — Embedded-Style Simulation


#include <iostream>
#include <vector>
#include <random>
#include <cmath>

int main() {
    double fs = 100.0, Ts = 1.0/fs;
    int N = 200;
    std::vector<double> x(N), b(N), y(N), yq(N), t(N);

    // Random generators
    std::mt19937 gen(0);
    std::normal_distribution<double> noise(0.0, 0.05);
    std::normal_distribution<double> drift(0.0, 1e-4);

    // Quantizer parameters
    int B = 10;
    double ymin = -2.0, ymax = 2.0;
    double Delta = (ymax - ymin) / std::pow(2.0, B);

    // Simulate
    for(int k=0; k<N; ++k){
        t[k] = k*Ts;
        x[k] = std::sin(2*M_PI*3*t[k]);               // assume band-limited here
        if(k==0) b[k] = 0.0; else b[k] = b[k-1] + drift(gen);
        y[k] = x[k] + b[k] + noise(gen);

        // Quantize
        yq[k] = Delta * std::round(y[k]/Delta);
    }

    // Estimate bias from first 20 samples
    double b_hat = 0.0;
    for(int k=0; k<20; ++k) b_hat += yq[k];
    b_hat /= 20.0;

    std::cout << "Delta=" << Delta << ", b_hat=" << b_hat << std::endl;
    return 0;
}
      

This compact pattern is close to what runs in microcontroller drivers: add noise/bias models, then quantize and optionally calibrate bias.

9. Java Lab — Quantization and Bias Random Walk


import java.util.Random;

public class SensorModel {
    public static void main(String[] args){
        double fs = 100.0, Ts = 1.0/fs;
        int N = 200;
        double[] x = new double[N];
        double[] b = new double[N];
        double[] yq = new double[N];

        Random rng = new Random(0);

        double sigmaN = 0.05;
        double sigmaB = 1e-4;

        int Bbits = 10;
        double ymin = -2.0, ymax = 2.0;
        double Delta = (ymax - ymin) / (1 << Bbits);

        for(int k=0; k<N; k++){
            double t = k*Ts;
            x[k] = Math.sin(2*Math.PI*3*t);
            if(k==0) b[k]=0; 
            else b[k] = b[k-1] + sigmaB*rng.nextGaussian();

            double y = x[k] + b[k] + sigmaN*rng.nextGaussian();
            yq[k] = Delta * Math.round(y/Delta);
        }

        // Bias estimate from initial window
        double bHat = 0;
        for(int k=0; k<20; k++) bHat += yq[k];
        bHat /= 20.0;

        System.out.println("Delta=" + Delta + ", bHat=" + bHat);
    }
}
      

Java is common in Android/embedded robotics stacks; the same statistical models apply.

10. MATLAB/Simulink Lab — Error Budget Verification


fs = 100; Ts = 1/fs; N = 200;
t = (0:N-1)*Ts;

x = sin(2*pi*3*t);
sigma_n = 0.05;
sigma_b = 1e-4;

% Noise
n = sigma_n*randn(size(t));

% Drift as random walk
b = zeros(size(t));
for k=2:N
    b(k) = b(k-1) + sigma_b*randn();
end

y = x + n + b;

% Quantization
B = 10; ymin=-2; ymax=2;
Delta = (ymax-ymin)/2^B;
yq = Delta*round(y/Delta);

% Compare measured quantization variance to Delta^2/12
eq = yq - y;
fprintf('Delta=%g, Var(eq)=%g, Theoretical=%g\n', Delta, var(eq), Delta^2/12);

% Bias estimate via mean on first 20 samples
b_hat = mean(yq(1:20));
y_comp = yq - b_hat;
      

In Simulink, the same can be built with blocks: Signal Generator → Add Noise → Random Walk Bias → Quantizer → Zero-Order Hold.

11. Problems and Solutions

Problem 1 (Quantization Variance): A sensor uses a 12-bit ADC over range \([-5,5]\). (a) Compute \(\Delta\). (b) Under the uniform quantization model, compute \(\mathrm{Var}(e_q)\).

Solution:

\[ \Delta = \frac{5-(-5)}{2^{12}}=\frac{10}{4096}\approx 2.441\times 10^{-3}. \]

\[ \mathrm{Var}(e_q)=\frac{\Delta^2}{12} \approx \frac{(2.441\times10^{-3})^2}{12} \approx 4.96\times10^{-7}. \]

Problem 2 (Aliasing Check): A range sensor outputs a signal containing frequency components up to 30 Hz. What is the minimum sampling rate to avoid aliasing?

Solution:

\[ f_s > 2 f_{\max} = 2\cdot 30 = 60 \text{ Hz}. \]

So choosing \(f_s\) slightly above 60 Hz (e.g., 100 Hz) provides margin for imperfect anti-alias filtering.

Problem 3 (Random-Walk Drift Growth): Bias evolves as \(b[k+1]=b[k]+w_b[k]\) with \(w_b[k]\sim\mathcal{N}(0,\sigma_b^2)\). Prove that \(\mathrm{Var}(b[k])=k\sigma_b^2\).

Solution:

Unrolling the recursion: \(b[k]=b[0]+\sum_{i=0}^{k-1}w_b[i]\). Taking variance and using independence:

\[ \mathrm{Var}(b[k]) = \mathrm{Var}\!\left(\sum_{i=0}^{k-1}w_b[i]\right) = \sum_{i=0}^{k-1}\mathrm{Var}(w_b[i]) = \sum_{i=0}^{k-1}\sigma_b^2 = k\sigma_b^2. \]

Thus drift uncertainty grows linearly in discrete time.

12. Summary

We modeled sensor outputs as the true signal plus stochastic noise and slowly varying bias, then analyzed two discretization limits: finite resolution (quantization) and finite sampling rate. Quantization introduces bounded error with variance \(\Delta^2/12\); insufficient sampling causes aliasing unless \(f_s > 2f_{\max}\); drift can be captured as a random walk with growing uncertainty. These quantitative tools are essential for interpreting real robot sensor data.

13. References

  1. Shannon, C.E. (1949). Communication in the presence of noise. Proceedings of the IRE, 37(1), 10–21.
  2. Nyquist, H. (1928). Certain topics in telegraph transmission theory. Transactions of the AIEE, 47, 617–644.
  3. Widrow, B., & Kollár, I. (1985). Quantization noise: Roundoff error and signal quantization. IEEE Transactions on Instrumentation and Measurement, 34(4), 563–571.
  4. Van Trees, H.L. (1968). Detection, estimation, and modulation theory: analysis of noise processes. IEEE Transactions on Information Theory, 14(2), 254–263.
  5. Allan, D.W. (1966). Statistics of atomic frequency standards. Proceedings of the IEEE, 54(2), 221–230.
  6. Gray, R.M., & Neuhoff, D.L. (1998). Quantization. IEEE Transactions on Information Theory, 44(6), 2325–2383.