Module 3 - Digital Filters
Module 3 - Digital Filters
Introduction
FIR filters
IIR filters
FIR vs IIR
Content
Introduction
FIR filters
IIR filters
FIR vs IIR
Digital filters I
BSF
BPF
Content
Introduction
FIR filters
IIR filters
FIR vs IIR
FIR filters I
This equation expresses that the current sample of the output y [n]
is equal to the sum of the current and past input samples, each
multiplied by a corresponding coefficient ai . The coefficients ai are
the filter coefficients and constitute the impulse response of the
system. By modifying these coefficients, the type of filter can be
altered.
FIR filters II
Let’s remember the example of module 1:
Solution:
y [0] = a0 x[0] = (4)(0.5) = 2
y [1] = a0 x[1] + a1 x[0] = (0.5)(3) + (0.5)(4) = 3.5
y [2] = a0 x[2] + a1 x[1] = (0.5)(−1) + (0.5)(3) = 1
y [3] = a0 x[3] + a1 x[2] = (0.5)(2) + (0.5)(−1) = 0.5
y [4] = a0 x[4] + a1 x[3] = (0.5)(1) + (0.5)(2) = 1.5
y [5] = a0 x[5] + a1 x[4] = (0.5)(0) + (0.5)(1) = 0.5
FIR filters III
Plotting all the signals, we have:
Input signal x[n] Impulse response h[n]
5 1
3
0.5
h[n]
x[n]
0
0
−1
−2 −0.5
−1 0 1 2 3 4 5 −0.5 0 0.5 1 1.5 2 2.5 3
n n
Output signal y[n]
4
3.5
2.5
2
y[n]
1.5
0.5
−0.5
−1
−1 0 1 2 3 4 5 6
n
FIR filters design I
# Filter parameters:
order = 100 # Filter order
cf= 20 # cutoff frequency in Hz
cfn=cf/(fs/2) # Normalized cutoff frequency
window = ’hamming’ # Window
# Filter design using firwin:
coefs = firwin(order, cutoff=cfn, window=window, pass_zero=True)
Python code - FIR II
# Signal filtering:
f_x = lfilter(coefs, 1.0, x)
# Plot the noisy and filtered signal:
plt.figure(),
plt.plot(t, x)
plt.grid(True), plt.title("Noisy Signal")
plt.xlabel("Time (s)"), plt.ylabel("Amplitude")
plt.figure()
plt.plot(t, f_x)
plt.grid(True), plt.title("Filtered Signal")
plt.xlabel("Time (s)"), plt.ylabel("Amplitude")
Introduction
FIR filters
IIR filters
FIR vs IIR
IIR filters
M
X N
X
y [n] = bk x(n − k) − ak y (n − k)
k=0 k=1
= b0 x[n] + b1 x[n − 1] + · · · + bN x[n − N]
−a1 y [n − 1] − a2 y [n − 2] − · · · − aM y [n − M]
Similar to the FIR case, the design of an IIR filter involves finding
the coefficients b and a according to specifications such as filter
type, orders N and M, cutoff frequency(ies) (ωn ), and sampling
frequency ωs . The methods employed are as follows:
I Analog Prototype Filters: Butterworth, Chebyshev.
I Derivatives Approximation.
I Impulse Invariance.
I Bilinear Transformation.
I Frequency Transformations: analog and digital Domain.
Practical example - IIR filter I
We have the following signal sampled at fs = 1 KHz.
# Filter parameters:
order = 5 # Filter order
cf= 20 # cutoff frequency in Hz
cfn=cf/(fs/2) # Normalized cutoff frequency
# Design the IIR filter using butter:
b, a = butter(order, cfn, btype=’low’, analog=False, output=’ba’)
Python code - IIR II
# Signal filtering:
f_x = lfilter(b, a, x)
# Plot the noisy and filtered signal:
plt.figure(),
plt.plot(t, x)
plt.grid(True), plt.title("Noisy Signal")
plt.xlabel("Time (s)"), plt.ylabel("Amplitude")
plt.figure()
plt.plot(t, f_x)
plt.grid(True), plt.title("Filtered Signal")
plt.xlabel("Time (s)"), plt.ylabel("Amplitude")
Introduction
FIR filters
IIR filters
FIR vs IIR
FIR vs IIR
Regarding IIR filters, they are effective with few coefficients, but
due to their feedback nature, they have a tendency to become
unstable.