The answersDownload the PDF
Worksheet

U4.3 The low pass filter

Noise and filtering · University · about 30 min

BugBotLab
NameClassDate

What this lesson is about

A moving average, then the exponential filter that does the same job in one line and no memory.

Questions 7 marks in all

  1. [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))
  2. [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?

  3. [1 mark]Why should an exponential filter be started at the first reading rather than at 0?

    1. AStarting at 0 makes the output climb from zero for the first second, which looks like a real signal
    2. BStarting at 0 makes alpha wrong for the whole run
    3. CStarting at 0 makes the filter unstable
    4. DThe filter needs a nonzero value to avoid dividing by zero
  4. [1 mark]Compared with a moving average giving similar smoothing, what is the main practical advantage of the exponential filter?

    1. AIt stores only its previous output, instead of the last n readings
    2. BIt has no delay
    3. CIt rejects outliers
    4. DIts output reaches a step's new value in exactly one step
  5. [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. AThe weighting is computed each tick from how uncertain the belief is compared with the measurement
    2. BThe weighting is always 0.5
    3. CThe measurement is filtered twice
    4. DThe difference raw - filtered is squared
  6. [1 mark]In signal processing terms, the exponential filter is a first order what kind of filter?

  7. [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.

    1. filtered = ALPHA * raw + (1 - ALPHA) * filtered
    2. for i in range(60):
    3. raw = distance()
    4. plot("filtered", filtered)
    5. filtered = distance()

The task: a low pass filter

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()

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/u4-3-the-low-pass-filter/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Run the same drive at alpha 0.05, 0.2 and 0.6 and compare the charts.
  2. Implement the moving average as well and plot all three. Which is smoother for the same delay?
  3. Filter imu()[1] instead. What is a sensible alpha for a signal you want to use in a controller?