Noise and filtering · University · about 30 min
A moving average, then the exponential filter that does the same job in one line and no memory.
[1 mark]An exponential filter starts at 50 and sees three readings of 60. What does it print?
ALPHA = 0.2
filtered = 50.0
for raw in (60, 60, 60):
filtered = ALPHA * raw + (1 - ALPHA) * filtered
print(round(filtered, 2))52.0 53.6 54.88
Each step closes a fifth of the remaining gap: 50 + 0.2 x 10 = 52, then 52 + 0.2 x 8 = 53.6, then 53.6 + 0.2 x 6.4 = 54.88.
[1 mark]Using the lesson's rule of thumb, an exponential filter with alpha = 0.1 behaves roughly like a moving average of how many readings?
[1 mark]Why should an exponential filter be started at the first reading rather than at 0?
[1 mark]Compared with a moving average giving similar smoothing, what is the main practical advantage of the exponential filter?
[1 mark]Rearranged, the filter is filtered = filtered + alpha * (raw - filtered). In the Kalman filter of U6.3 the update has the same shape. What is different there?
[1 mark]In signal processing terms, the exponential filter is a first order what kind of filter?
[1 mark]Put these lines in order to run an exponential filter while driving.
Number the lines 1 to 5 to put them in the right order.
filtered = ALPHA * raw + (1 - ALPHA) * filteredfor i in range(60): raw = distance() plot("filtered", filtered)filtered = distance()filtered = distance()
for i in range(60):
raw = distance()
filtered = ALPHA * raw + (1 - ALPHA) * filtered
plot("filtered", filtered)Start the filter at a real reading, then each tick read, update, and plot the filtered value.
Drive towards the wall with an exponential filter running, plotting raw and filtered as you go, and print the alpha: you chose.
from bugbot import * connect() ALPHA = 0.25 filtered = distance()
The hint students can ask for: filtered = alpha * new + (1 - alpha) * filtered, once per tick. Plot both lines while the robot drives towards the wall, and watch the filtered line follow the raw one at a distance.
from bugbot import *
connect()
ALPHA = 0.25
filtered = distance()
forward(45)
for i in range(70):
raw = distance()
filtered = ALPHA * raw + (1 - ALPHA) * filtered
plot("raw", raw)
plot("filtered", filtered)
if filtered < 30:
stop()
wait(0.1)
stop()
print("alpha:", ALPHA)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.