A collection of Arduino-compatible digital filter classes used in Vulintus devices' firmware. This library started as a stripped-down fork of Jon Driscoll's "Filters" library, but now differs somewhat in the calculations based on our own interpretations. Basic examples for Arduino are included. This library is, as always, a work-in-progress.
Disclaimer: Sections of this README file were AI-generated, but checked for accuracy by a human.
The most basic low- or high-pass filters, "Vulintus_IIR_Filter," are designed as single-pole discretized RC filters. The implementation of these filters is adapted largely from the Wikipedia pages for low-pass and high-pass filters.
For IIR filters, new output values are calculated from the recurrence relations derived from basic RC circuit models:
These equations differ because the RC circuit models for low-pass and high-pass filters differ by flipping the position of the capacitor and resistor. For both equations,
where exp() function can be computationally expensive. So long as
The error difference between the exponential calculation and the approximation is less than 1% for
- Download the latest release as a
.zipfile. - In the Arduino IDE, go to Sketch → Include Library → Add .ZIP Library... and select the downloaded file.
- Alternatively, extract the archive directly into your
Arduino/libraries/folder and restart the IDE.
Include the library and instantiate a filter with a cutoff frequency in Hz:
#include <Vulintus_Digital_Filter.h>
const float CUTOFF_FREQ = 1.0; // Cutoff frequency, in Hz.
Vulintus_LowPass_Filter lp_filter(CUTOFF_FREQ); // Single-pole IIR low-pass filter.
Vulintus_HighPass_Filter hp_filter(CUTOFF_FREQ); // Single-pole IIR high-pass filter.Call input() in your sampling loop. When a single argument is passed, the filter will call micros() internally to use as the sampling time.
float filtered = lp_filter.input(raw);Passing a microsecond clock reading as a second argument allows for filter updates separated in time from signal sampling:
float raw = analogRead(A0);
unsigned long microtime = micros();
delay(5);
float filtered = lp_filter.input(raw, microtime);The current output is also accessible directly via the output member:
Serial.println(lp_filter.output);The cutoff frequency can be read or updated at any time:
lp_filter.cutoff_frequency(5.0); // Set to 5 Hz.
float fc = lp_filter.cutoff_frequency(); // Read current cutoff frequency.See examples/Vulintus_Digital_Filter_Demo for a complete example that uses the Arduino Serial Plotter to visualize filter output on a square-wave test signal.
This library is released under the MIT License.