Real sensor data versus ideal simulation data
How noise, constant bias, bias drift, quantization, a finite sampling frequency and latency each change the signal a controller receives, compared with the perfect value a simulator can provide.
What it demonstrates
How noise, constant bias, bias drift, quantization, a finite sampling frequency and latency each change the signal a controller receives, compared with the perfect value a simulator can provide.
How it works
An ideal gyro signal (a sum of sinusoids plus an occasional step) is generated at 1 kHz. A sensor model samples it at the chosen frequency, adds bias, a bias random walk and white noise, and rounds the result to a quantization step (one least-significant bit). Each sample then waits in a delivery queue for the chosen latency.
Between deliveries the software keeps seeing the last delivered value (zero-order hold), which produces the staircase. The RMS error over the last 2 s summarises the combined effect. The presets are illustrative orders of magnitude, not values from any datasheet.
Adjustable parameters
- Sampling frequency (25, 50, 100, 200, 1000 Hz)
- White noise σ (0–0.2 rad/s)
- Constant bias (−0.2 to 0.2 rad/s)
- Bias random walk (0–0.05 rad/s/√s)
- Quantization step (0–0.1 rad/s)
- Latency (0–100 ms)
Known limitations
- Latency is a constant delay. Real buses add jitter and occasionally drop or reorder packets (see Chapter 5).
- No anti-aliasing filter, so high-frequency content aliases at low sampling rates, as it would without one.
- Noise is white and Gaussian. Real sensors also show flicker noise, vibration pickup and temperature effects.
Equations
Core update rule
// lib/sim/ch04-sensors.ts
driftBias += biasWalk * Math.sqrt(dt) * gaussian(rng);
if (t >= nextSample) { // ADC sample at rateHz
const v = quantize(ideal + bias + driftBias + noise * gaussian(rng), lsb);
pipeline.push({ t, v });
nextSample += 1 / rateHz;
}
while (pipeline[0]?.t <= t - latency) output = pipeline.shift().v; // deliveryExplained in Chapter 4: Sensors & Data