Digital Filters
A digital filter is a system which employs mathematical algorithms to process discrete-time
signals (a sequence of numbers) in order to modify or enhance it. Its primary purpose is to
remove unwanted parts of the signal, such as noise, or to extract useful parts.
Unlike analog filters, which are built from physical components like resistors and capacitors,
digital filters are implemented in software or on digital hardware like Arduino.
A Finite Impulse Response (FIR) filter is a type of digital filter where the output for any given
sample is a weighted sum of a finite number of past and present input samples defined by the
difference equation :
𝑁
𝑦[𝑛] = 𝑏0𝑥[𝑛] + 𝑏1𝑥[𝑛 − 1] + ... + 𝑏𝑁𝑥[𝑛 − 𝑁] = ∑ 𝑏𝑘𝑥[𝑛 − 𝑘]
𝑘=0
Taking the z-transform on both the sides and re-arranging the terms, we obtain the required
transfer function for an Nth order FIR Filter :
𝑁
𝑌(𝑧) −𝑘 −1 −2 −𝑁
𝐻(𝑧) = 𝑋(𝑧)
= ∑ 𝑏𝑘𝑧 = 𝑏0 + 𝑏1𝑧 + 𝑏2𝑧 + ... + 𝑏𝑁𝑧
𝑘=0
Filter Design
The following FDATool Parameters were taken to design the required low-pass filter :
The Magnitude Response
The Phase Response
Arduino Implementation
const int order = 10;
float Fs = 9600.0;
float c[order + 1] = {0.250053488759641, 0.0000269621085108913, -0.0000269004254105769,
0.0000262908497138089, -0.0000266491974043805, 0.0000261646054666165,
-0.0000266491974043805, 0.0000262908497138089, -0.0000269004254105769,
0.0000269621085108913, 0.250053488759641};
float x[order + 1] = {0};
long currentTime = 0;
long previousTime = 0;
long samplePeriod_micros = 1000000 / Fs;
void setup()
{
[Link](115200);
previousTime = micros();
}
void loop()
{
currentTime = micros();
if(currentTime - previousTime >= samplePeriod_micros)
{
previousTime = currentTime;
float t = (float)currentTime / 1000000.0;
float curr_x = sin(200.0 * PI * t) + 0.1 * sin(2.0 * PI * t);
for (int i = order; i > 0; i--)
{
x[i] = x[i - 1];
}
x[0] = curr_x;
float curr_y = 0;
for (int i = 0; i <= order; i++)
{
curr_y += c[i] * x[i];
}
[Link](curr_x);
[Link](",");
[Link](curr_y);
}
}
Serial Plotter depicting the Input (Blue) and Output (Red) signal waveforms