Giter Site home page Giter Site logo

digitalfilters's Introduction

License: MIT

Bolder Flight Systems Logo     Arduino Logo

Filter

This is a library of digital filters. This library is compatible with Arduino and with CMake build systems.

Installation

Arduino

Use the Arduino Library Manager to install this library or clone to your Arduino/libraries folder. Additionally, the Bolder Flight Systems Units library must be installed. This library is added as:

#include "filter.h"

An example Arduino executable is located at examples/arduino/filter_example/filter_example.ino. Teensy 3.x, 4.x, and LC devices are used for testing under Arduino and this library should be compatible with other devices.

CMake

CMake is used to build this library, which is exported as a library target called filter. The header is added as:

#include "filter.h"

The library can be also be compiled stand-alone using the CMake idiom of creating a build directory and then, from within that directory issuing:

cmake ..
make

This will build the library, an example executable called filter_example, and an executable for testing using the Google Test framework, called filter_test. The example executable source files are located at examples/cmake/filter_example.cc.

Namespace

This library is within the namespace bfs

Classes

Filter

Description

Filter dlpf(b, a)
y = dlpf(x) 

Filters the input data x using a rational transfer function defined by the numerator and denominator coefficients b and a, similar to MATLAB's filter function. If a[0] is not equal to 1, then filter normalizes the filter coefficients by a[0]. Therefore, a[0] must be nonzero.

Methods

Filter(const T (&b)[N], const T (&a)[M]) This creates a Filter object. It is a templated class and the constructor takes an array of the numerator coefficients and an array of the denomenator coefficients.

/* Moving average filter with a window size of 5 */
float b[] = {0.2, 0.2, 0.2, 0.2, 0.2};
float a[] = {1};
bfs::Filter<float, 5, 1> dlpf(b, a);

T Update(const T val) Filters the input data returning the filtered value.

/* Filter data array x */
for (size_t i = 0; i < 100; i++) {
  y = dlpf.Update(x[i]);
}

void Reset() Resets the filter states.

dlpf.Reset();

Iir

This class implements a 1st order IIR filter given a desired cutoff and sampling frequency. Optionally, an initial value may also be passed for non-zero initial values.

Methods

void Init(const float cutoff_hz, const float samp_hz) Initializes the IIR filter given a cutoff frequency and sampling rate.

/*
* An IIR filter with a 10 Hz cutoff frequency
* and a 50 Hz sampling rate
*/
bfs::Iir dlpf;
dlpf.Init(10.0f, 50.0f);

void Init(const float cutoff_hz, const float samp_hz, const float initial_val) Initializes the IIR filter given a cutoff frequency, sampling rate, and initial value.

/*
* An IIR filter with a 10 Hz cutoff frequency,
* a 50 Hz sampling rate, and an initial value
* of 101325.
*/
bfs::Iir dlpf;
dlpf.Init(10.0f, 50.0f, 101325.0f);

float Filter(const float val) Passes a new value to the filter and returns the filtered result.

dlpf.Filter(97600.0f);

digitalfilters's People

Contributors

flybrianfly avatar tl-4319 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.