Skip to content

martinbudden/Library-Filters

Repository files navigation

license open source

Filters Library

This library contains a collection of filter classes. They have been developed for use in a Self Balancing Robot and have been used to:

  1. Filter gyro and accelerometer output for use in the Attitude and Heading Reference System (AHRS).
  2. Filter motor encoder values for use in the motor controller.
  3. Filter derivative terms in a PID controller.
  4. Filter motor power input values to smooth the motor speed.

Class Diagram

The filters are somewhat statically (build-time) polymorphic, and somewhat dynamically (run-time) polymorphic.
This is deliberate.

The filters have functions that have names and signatures in common, but the only virtual function is filterVirtual.

The filter function may called directly by calling filter, or indirectly (via the vtable) using filterVirtual.

This means the the filters are somewhat interchangeable at build time, depending on which functions are used.

classDiagram
    class FilterNull {
        init(float k)
        reset()
        setToPassthrough()
        setCutoffFrequency(float cutoffFrequency, float dT)
        setCutoffFrequencyAndReset(float cutoffFrequency, float dT)
        filter(float input) float
        filter(float input, float dT) float
    }
Loading
classDiagram
    class FilterMovingAverage~N~ {
        reset()
        filter(float input) float
        filter(float input, float dT) float
    }
Loading
classDiagram
    class ButterWorthFilter {
        setParameters(const ButterWorthFilter& other)
        reset()
        setToPassthrough()
        filter(float input) float
    }
Loading
classDiagram
    class IIR_filter {
        init(float alpha)
        setAlpha(float alpha)
        reset()
        setToPassthrough()
        setCutoffFrequency(float cutoffFrequency, float dT)
        setCutoffFrequencyAndReset(float cutoffFrequency, float dT)
        filter(float input) float
        filter(float input, float dT) float
    }
Loading
classDiagram
    class PowerTransferFilter1 {
        init(float k)
        reset()
        setToPassthrough()
        setCutoffFrequency(float cutoffFrequency, float dT)
        setCutoffFrequencyAndReset(float cutoffFrequency, float dT)
        filter(float input) float
        gainFromDelay(float delay, float dT) float $
        gain(float cutoffFrequency, float dT) float $
    }

    class PowerTransferFilter2 {
        init(float k)
        reset()
        setToPassthrough()
        setCutoffFrequency(float cutoffFrequency, float dT)
        setCutoffFrequencyAndReset(float cutoffFrequency, float dT)
        filter(float input) float
        gainFromDelay(float delay, float dT) float $
        gain(float cutoffFrequency, float dT) float $
    }

    class PowerTransferFilter3 {
        init(float k)
        reset()
        setToPassthrough()
        setCutoffFrequency(float cutoffFrequency, float dT)
        setCutoffFrequencyAndReset(float cutoffFrequency, float dT)
        filter(float input) float
        gainFromDelay(float delay, float dT) float $
        gain(float cutoffFrequency, float dT) float $
    }
Loading
classDiagram
    class IIR_filter {
        setWeight(float weight)
        setParameters(float a1, float a2, float b0, float b1, float b2, float weight)
        setParameters(float a1, float a2, float b0, float b1, float b2)
        setParameters(const BiquadFilter& other)

        reset()
        setToPassthrough()

        filter(float input) float
        filterWeighted(float input) float

        initNotch(float frequency, float loopTimeSeconds, float Q)

        calculateOmega(float frequency) float
        setLowPassFrequency(float frequency, float weight)
        setNotchFrequency(float frequency, float weight)
        setNotchFrequency(float sinOmega, float two_cosOmega, float weight)

        calculateQ(float centerFrequency, float lowerCutoffFrequency) float $
        setQ(float centerFrequency, float lowerCutoffFrequency)
        setQ(float Q)
        getQ() float
        setLoopTime(float loopTimeSeconds)
    }
Loading

About

Library containing a collection of filter classes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages