The answersDownload the PDF
Worksheet

U4.5 The price of filtering

Noise and filtering · University · about 30 min

BugBotLab
NameClassDate

What this lesson is about

Every filter delays. Measuring the delay, and what it does to a loop closed around it.

Questions 6 marks in all

  1. [1 mark]An exponential filter with alpha = 0.2 runs in a 0.1 s loop. About how many seconds does it delay the signal?

  2. [1 mark]What does this print?

    DT = 0.1
    for a in (0.5, 0.25, 0.1):
        steps = (1 - a) / a
        print(a, round(steps, 2), round(steps * DT, 2))
  3. [1 mark]A controller holds a gap to the wall. Why should the filter go on the measurement rather than on the error?

    1. AFiltering the error also delays the response to a change in the target
    2. BFiltering the error removes more noise
    3. CThe error has no noise in it
    4. DFiltering the measurement has no delay
  4. [1 mark]In a PID controller, which term usually needs the filter?

    1. AThe D term
    2. BThe P term
    3. CThe I term
    4. DAll three equally
  5. [1 mark]The plant has a time constant of 0.25 s and the loop runs at 0.1 s. By the lesson's rule of thumb, which filter is acceptable in the loop?

    1. Aalpha = 0.5, a delay of 0.1 s
    2. Balpha = 0.1, a delay of 0.9 s
    3. Calpha = 0.05, a delay of 1.9 s
    4. DAny alpha, since delay does not affect stability
  6. [1 mark]A controller was twitchy, so its sensor filter was made heavier twice. It now oscillates slowly. What is the right fix?

    1. AFilter less, because the added delay is now causing the oscillation
    2. BFilter more, to smooth out the oscillation
    3. CRaise the gain so it responds faster
    4. DFilter the error as well as the measurement

The task: measure the lag

Drive steadily at the wall, filter the distance, plot raw and filtered, and print lag:, the seconds by which the filtered signal trails the raw one.

from bugbot import *
connect()

ALPHA = 0.2
DT = 0.1
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-5-the-price-of-filtering/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Measure the lag at three values of alpha and plot lag against alpha. Does it match the formula?
  2. Put the filter inside a controller that holds 25 cm from the wall, and find the alpha at which it starts to oscillate.
  3. Extrapolate: add lag * rate_of_change to the filtered value and see how much of the delay you can buy back.