Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

tutorial dsp

Tianshu Huang edited this page Oct 4, 2018 · 6 revisions

Digital Signal Processing, Filtering, and Control

Whenever you read in data, it will inevitably come with some amount of random noise.

As a matter of fact, if you use dirt-cheap sensors like these (10 for $14.99!), you might have a lot of random noise.

Average Filter

The simplest, and easiest way to filter data is to take the average over a range.

Procedure AverageFilter(newValue, queue previousValues):
    previousValues.pop()
    previousValues.push(newValue)
    return mean(previousValues)

However, while simple, this approach is not robust to extreme outliers. For example, with a queue length of 4, if the correct value is 4, but an erroneous value of 100 is read in, a value of 28 will be returned, which, while closer to 4 than 100, will probably crash your robot.

Median Filter

A more robust (an my personal recommendation for this application) filter is a simple median filter. Here, we collect a number of values, and, instead of computing the mean, take the median:

Procedure MedianFilter(newValue, queue previousValues):
    previousValues.pop()
    previousValues.push(newValue)
    return median(previousValues)

This method, while requiring at least a partial sort of the data, is much more robust for outliers.

PID

A PID controller (Proportional-Integral-Derivative Controller) is a control scheme with three terms:

  • Proportional: the proportion of error from the desired position
  • Integral: integral of the error; a measure of historical deviation
  • Derivative: derivative of the error; how much the error is changing over time

The PID control function f for a device with error e is a linear combination of the proportional, integral, and derivative terms:

Clone this wiki locally