Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Filters

Jaden Bottemiller edited this page Jun 27, 2018 · 15 revisions

In Scarlet, we provide a few options for input/output filters; as of now we have:

  • Average Filter (computes a rolling average of inputs)
  • Low Pass Filter (filters out high-frequency components of an input signal)

Our filters work with any numeric type.


Average Filter

An average filter computes a rolling average or continuous average on a set of inputs.

Preparation: Simply construct a filter object (make sure to import Scarlet.Filters)

Average YourFilter = new Average(FilterCount);

or to use a continuous average

Average YourFilter = new Average(null);

Where FilterCount (an int) represents the width of the roll. For example, 10 would setup the filter to find the average of the last 10 inputs, setting this to null gets the average of all inputs to the filter (essentially setting FilterCount to infinity.)

Usage:

  • void Feed(T Input)
    • Use this method to feed an input into the filter, the output will be calculated and updated depending on the input value.
  • void Feed(T Input, T Rate)
    • Since this filter is not rate-dependent, rate is ignored, so this is the same operation as Feed(T input)
  • bool IsSteadyState()
    • Returns whether or not the filter is in a steady state. In this case, if the output has been the same for FilterCount number of cycles, then it is determined to be in a steady state. This is always false if FilterCount is null.
  • T GetOutput()
    • Returns the computed average of the inputs to the filter.

Low Pass Filter

A low pass filter rejects high frequency components of an input signal. This can sound more complicated than it actually is, for more information this guide is pretty helpful.

The step response of a low pass filter is depicted here, and is a good illustration of why we use them for our motors: they make great ramp-up functions.

Preparation: Simply construct a filter object (make sure to import Scarlet.Filters)

LowPass YourFilter = new LowPass(LPFk, SteadyStateEpsilon);

Where LPFk (a double) is the low pass filter time constant, which can be thought of as a damping coefficient. The larger the number, the lower the cutoff frequency. SteadyStateEpsilon (a double) is the maximum difference between the last two outputs for the system to be considered in a steady state. By default this is zero, so that the system is never considered to be in a steady state.

Usage:

  • void Feed(T Input)
    • Use this method to feed an input into the filter, the output will be calculated and updated depending on the input value.
  • void Feed(T Input, T Rate)
    • Since this filter is not rate-dependent, rate is ignored, so this is the same operation as Feed(T input).
  • bool IsSteadyState()
    • Returns whether or not the filter is in a steady state. In this case, if the difference between the last output and the current output is less than or equal to the SteadyStateEpsilon supplied in the constructor, the filter is considered to be in a steady state.
  • T GetOutput()
    • Returns the output computed by the filter.

Logo

Quick Links:
NuGet
Pin Diagrams: RPi | BBB
Developers: CaiB, Baldstrom

General Info:
Home
Common Issues
Getting Started
Supported Devices

Sections:
Logging
DataLog
Filters
Hardware I/O:
- BeagleBone Black
- Raspberry Pi
- Pin Diagrams: RPi | BBB
- GPIO: Using | For Beginners
- PWM: Using | For Beginners
- ADC: Using | For Beginners
- I2C: Using | For Beginners
- SPI: Using | For Beginners
- UART: Using | For Beginners
- CAN: Using | For Beginners
Networking
Sensors
StateStore

Other: Interesting Case Studies

Clone this wiki locally