FIRNotch
Example of 50 Hz (+harmonics) notch filter.
- Boards:
- AVR, AVR USB, Nano 33 IoT, Nano 33 BLE, Due, Teensy 3.x, ESP8266, ESP32
- See also
- https://tttapa.github.io/Pages/Mathematics/Systems-and-Control-Theory/Digital-filters/FIR-Notch.html
Be careful when selecting a sampling frequency that's a multiple of 50 Hz, as this will alias 50 Hz harmonics to 0 Hz (DC), and this might introduce a more or less constant error to your measurements.
It's best to add an analog anti-aliasing filter as well.
Filtered mains power noise signal (blue is unfilterd, red is filtered)
Written by PieterP, 2019-11-22
https://github.com/tttapa/Arduino-Filters
void setup() {
Serial.begin(1e6);
}
const double f_s = 250;
const double f_c = 50;
const double f_n = 2 * f_c / f_s;
void loop() {
if (timer) {
Serial.print(raw);
Serial.print('\t');
Serial.println(filter2(filter1(raw)));
}
}
Dummy header file for Arduino builder.
A class for easily managing timed events.
analog_t analogRead(pin_t pin)
An ExtIO version of the Arduino function.
FIRFilter< 3, T > simpleNotchFIR(double f_n)
Create a very simple second-order FIR notch filter.