Step 3
Noise, mean, variance & bias
A sensor's error has two parts. Noise averages away; bias doesn't, so measure it on something you know.
A sensor with two kinds of error
probe.read(name) measures a ball's position in metres. Every reading differs from the ball's true position in two ways:
- is noise: a fresh random error in every reading, about 12 mm per coordinate, as likely to be too big as too small.
- is bias: the same error in every reading, a few centimetres, set by how the probe is mounted. It changes every run.
Mean and standard deviation
For readings of one coordinate, the mean is their average and the standard deviation measures how spread out they are:
is called the variance. Some books divide by instead of ; either is fine here. A histogram of many readings makes a bell curve, the Gaussian (normal) distribution, centred on and about wide on each side.
Noise averages away, bias doesn't
The noise in each reading is different, so in an average much of it cancels. The mean's own error is about : 400 readings pin it down to 12/20 = 0.6 mm. But the bias is the same every time, so the mean still sits at . A few centimetres off is enough to miss the ball on most runs.
To measure a bias, measure something whose true position you know. The blue ball sits in the ring at world.targets()[0], so
Then correct the red ball's mean: , where the hat marks an estimate.
Noisy Sensors & Kalman Filters, step 1 averages noisy readings of a ball you can't see directly.
Your task
- Write
mean_and_std(samples).samplesis an array (one reading per row); return(mean, std), each 3 numbers, one per coordinate. - Take 400 readings of the blue ball (the starter plots a histogram of their x-values) and store the bias in a global
BIAS(3 numbers, in metres). It must be within 3 mm of the truth. - Average 400 readings of the red ball, subtract
BIASand put the red ball in the cup.