Noise and filtering · University · about 25 min
Some readings are not noisy, they are wrong. The median, and gating on what you expected.
[1 mark]Nine readings of 60 cm and one of 400 cm are averaged. By how many centimetres does the outlier shift the mean away from 60?
[1 mark]A window of five holds two maximum-range readings. What does this print?
window = [61, 400, 59, 60, 400] median = sorted(window)[len(window) // 2] mean = sum(window) / len(window) print(median, mean)
61 196.0
Sorted, the window is 59, 60, 61, 400, 400, and the middle one is 61. The mean is 196, ruined by the two outliers the median ignores.
[1 mark]How many bad readings out of five can a median of five survive with its output still one of the good readings?
[1 mark]A gate is rejecting about half of all readings. What does that most likely say?
[1 mark]Which of these are real costs of a median filter?
Tick every answer that is true.
[1 mark]In a Kalman filter, the validation gate is set from the covariance. What does that achieve?
Drive towards the wall with a median filter and a gate running, and stop 35 cm from it, without being fooled by the robot that crosses in front. Plot raw and median, and print thrown out:, the number of readings your gate rejected.
from bugbot import * connect() window = [] thrown = 0
The hint students can ask for: Another robot shuttles across between you and the wall. While it is in the beam the sensor measures it, not the wall: two readings far too short. Stop 35 cm from the wall itself. A median of the last five ignores two bad readings completely; without it the robot believes the wall has jumped towards it and stops early. Count the readings you refuse.
from bugbot import *
connect()
window = []
thrown = 0
last_good = distance()
forward(40)
for i in range(70):
raw = distance()
window.append(raw)
if len(window) > 5:
window.pop(0)
med = sorted(window)[len(window) // 2]
if abs(raw - med) > 25:
thrown += 1
else:
last_good = med
plot("raw", raw)
plot("median", last_good)
if last_good < 35:
stop()
wait(0.1)
stop()
print("thrown out:", thrown)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.