This example illustrates the process of creating a low-pass filter (LPF) object and effectively eliminating the noise signal through digital filtering.
// 2023-05-24
#include <Arduino.h>
#include <iir_filter1.h>
IIRFilter1 lpf;
double y = 0.0;
double n = 0.0;
double ym = 0.0;
double yf = 0.0;
double t = 0.0;
double fc = 10.0;
double T = 0.001;
void setup()
{
Serial.begin(115200);
lpf.init(IIRFilter1::TYPE_LPF, fc, T);
randomSeed(0);
}
void loop()
{
static int i;
n = (double)(random(-1000, 1000)) / 1000.0;
t = (double)(i)*T;
y = sin(2.0 * PI * 1.0 * t);
ym = y + n;
yf = lpf.update(ym);
i++;
Serial.print(ym, 4);
Serial.print(" ");
Serial.print(y, 4);
Serial.print(" ");
Serial.print(yf, 4);
Serial.println();
Serial.flush();
delay(10);
}