Handout - 8 Digital Filter Design
Handout - 8 Digital Filter Design
Using Matlab
2
Introduction
Digital filter design involves the following three steps:
1. Specification:
Specify the desired frequency response function characteristics
to address the needs of a specific application.
2. Approximation:
Approximate the desired frequency response function by the
frequency response of a filter with a polynomial or a rational
system function. The goal is to meet the specifications with
minimum complexity, that is, by using the filter with the lowest
number of coefficients.
3. Implementation:
Realize the system obtained in hardware, software, or both
using one of the structures discussed in the previous chapter.
3
Introduction
• Filters are broadly classified according to their frequency-
domain characteristics into five types:
1. Lowpass filter (LPF)
2. Highpass filter (HPF)
3. Bandpass filter (BPF)
4. Bandstop filter (BSF)
5. Allpass filter (APF)
4
Ideal Filters
Ideal Lowpass Filter (LPF): Frequency domain
1 for 𝜔 ≤ 𝜔𝑐
𝐻𝑙𝑝 𝜔 =ቊ
0 for 𝜔𝑐 ≤ 𝜔 ≤ 𝜋
5
Ideal Filters
Ideal Lowpass Filter (LPF): Time domain
ℎ𝑙𝑝 𝑛
Impulse Response
Noncausal impulse
response
𝜔𝑐ൗ
sin(𝜔𝑐 𝑛) 𝜔𝑐 𝜔𝑐 𝑛 𝜋 for 𝑛 = 0
ℎ𝑙𝑝 𝑛 = = sinc = ൞sin(𝜔𝑐 𝑛)
𝜋𝑛 𝜋 𝜋 for 𝑛 ≠ 0
𝜋𝑛
6
Ideal Filters
Ideal Highpass Filter (HPF)
Lowpass Highpass
filter filter
Bandpass Bandstop
filter filter
10
LPF Design
LPF Relative Specifications (Linear)
Passband
1
Gain 𝐺𝑝𝑎𝑠𝑠
Magnitude
|H(𝜔)|
Transition
Passband band Stopband
Stopband 𝐺𝑠𝑡𝑜𝑝
Gain/Ripple
0 𝜔Wp
𝑝𝑎𝑠𝑠 𝜔𝑠𝑡𝑜𝑝
Ws 𝜋1
Normalized frequency
11
LPF Design
LPF Relative Specifications (dB)
0
𝐴𝑝𝑎𝑠𝑠
Magnitude (dB)
Passband
Ripple in dB
𝐴𝑠𝑡𝑜𝑝
Stopband
Attenuation in dB
Stopband
Passband Transition
band
0 𝜔Wp
𝑝𝑎𝑠𝑠 𝜔𝑠𝑡𝑜𝑝
Ws 𝜋1
Normalized frequency
12
LPF Design
LPF Relative Specifications
Example (1):
Given the minimum passband gain 𝐺𝑝𝑎𝑠𝑠 = 0.8 and the maximum stopband
ripple 𝐺𝑠𝑡𝑜𝑝 = 0.01, determine the passband ripple and the stopband
attenuation in dB.
Solution:
𝐴𝑝𝑎𝑠𝑠 = −20 log10 (0.8) = 1.94 dB
13
LPF Design
LPF Relative Specifications
Example (2):
In a certain filter’s specifications the passband ripple is 1 dB, and the stopband
attenuation is 50 dB. Determine 𝐺𝑝𝑎𝑠𝑠 and 𝐺𝑠𝑡𝑜𝑝 .
Solution:
Example (3):
A digital LPF filter has the following specifications:
0.8 ≤ 𝐻 𝜔 ≤1 0 ≤ 𝜔 ≤ 0.2𝜋
𝐻 𝜔 ≤ 0.2 0.6𝜋 ≤ 𝜔 ≤ 𝜋
Find its related design parameters.
Solution:
𝐴𝑝𝑎𝑠𝑠 = −20 log10 0.8 = 1.94 dB
𝜔𝑠𝑡𝑜𝑝 = 0.6𝜋
16
FIR LPF Design using Window Method
The design procedure of the FIR filter via windowing is summarized
as follows:
To become a
causal filter
17
FIR LPF Design using Window Method
18
FIR LPF Design using Window Method
19
FIR LPF Design using Window Method
Solution:
2𝜋𝐹𝑐 2𝜋(800)
𝜔𝑐 = = = 0.2𝜋
𝐹𝑠 8000
2M+1=taps=3,
therefore M=1
20
FIR LPF Design using Window Method
21
FIR LPF Design using Window Method
22
FIR LPF Design using Window Method
linear-phase response, 3 taps ( odd symmetry). There are three
coefficients and two delay cells . Note that this filter is of order 2
(M), the number of delay cells
23
FIR LPF Design using Window Method
Matlab Implementation
0.2
0.18
0.16
MATLAB: 0.14
Amplitude
0.12
>> b = fir1(2, .2, 'noscale') 0.1
0.08
0.06
b= 0.04
0.7
b= 0.6
Amplitude
0.5
0.3
0.2
0.1
28
IIR LPF Design
The Butterworth
analog filter
2
𝐺𝑝𝑎𝑠𝑠
𝐴𝑝𝑎𝑠𝑠 dB
= −20 log10 𝐺𝑝𝑎𝑠𝑠
𝐴𝑠𝑡𝑜𝑝 dB
= −20 log10 𝐺𝑠𝑡𝑜𝑝
2
𝐺𝑠𝑡𝑜𝑝
Ω𝑝𝑎𝑠𝑠 Ω𝑠𝑡𝑜𝑝
2
1
𝐻𝑎 (𝑗Ω) = 2𝑁
Ω
1+
Ω𝑐 30
Design of Butterworth LPF using BLT
The design procedure of a lowpass IIR filter via Butterworth analog
prototype and bilinear transformation is summarized as follows:
32
Design of Butterworth LPF using BLT
5. Calculate the analog 3-dB cutoff frequency, Ω𝑐 .
Ω𝑠𝑡𝑜𝑝 Ω𝑠𝑡𝑜𝑝
Ω𝑐 = 1 = 1
1 2𝑁 100.1(𝐴𝑝𝑎𝑠𝑠)dB − 1 2𝑁
൘𝐺 2 − 1
𝑠𝑡𝑜𝑝
Note that if 𝐴𝑝𝑎𝑠𝑠 = 3 dB then Ω𝑐 = Ω𝑝𝑎𝑠𝑠
6. Find the Transfer Function, 𝐻𝑎 (𝑠) of the analog LPF by
substituting s with 𝑠ΤΩ𝑐 in 𝐻𝑝 𝑠 .
7. Use the bilinear transformation (BLT) to obtain the digital filter
𝐻(𝑧).
𝐻 𝑧 = 𝐻𝑎 𝑠 ቚ 2 1−𝑧 −1
𝑠=𝑇
1+𝑧 −1
33
Design of Butterworth LPF using BLT
Example 1:
Design a digital lowpass Butterworth filter with the following
specifications:
• Passband ripple = 1 dB
• Stopband attenuation = 20 dB
• Passband frequency 𝐹𝑝𝑎𝑠𝑠 = 1 kHz
• Stopband frequency 𝐹𝑠𝑡𝑜𝑝 = 3 kHz
• Sampling frequency 𝐹𝑠 = 8 kHz
Solution:
1. Calculate the digital frequencies 𝜔𝑝𝑎𝑠𝑠 and 𝜔𝑠𝑡𝑜𝑝 .
2𝜋𝐹𝑝𝑎𝑠𝑠 2𝜋 1𝑘
𝜔𝑝𝑎𝑠𝑠 = = = 0.25𝜋 rad/sample
𝐹𝑠 8𝑘
2𝜋𝐹𝑠𝑡𝑜𝑝 2𝜋 3𝑘
𝜔𝑠𝑡𝑜𝑝 = = = 0.75𝜋 rad/sample
𝐹𝑠 8𝑘 34
Design of Butterworth LPF using BLT
2. Pre-warp the digital frequencies to compute the equivalent
analog frequencies Ω𝑝𝑎𝑠𝑠 and Ω𝑠𝑡𝑜𝑝 .
2 𝜔𝑝𝑎𝑠𝑠 0.25𝜋
Ω𝑝𝑎𝑠𝑠 = tan = 2 8𝑘 tan = 6627.4 rad/sec
𝑇 2 2
2 𝜔𝑠𝑡𝑜𝑝 0.75𝜋
Ω𝑠𝑡𝑜𝑝 = tan = 2 8𝑘 tan = 38627.4 rad/sec
𝑇 2 2
3. Find the filter order.
100.1(𝐴𝑠𝑡𝑜𝑝 )dB − 1
log 102 − 1
100.1(𝐴𝑝𝑎𝑠𝑠 )dB − 1 log
100.1 − 1
𝑁= = = 1.69
Ω𝑠𝑡𝑜𝑝 38627.4
log log
Ω𝑝𝑎𝑠𝑠 6627.4
We choose 𝑁 = 2
35
Design of Butterworth LPF using BLT
4. The normalized Butterworth prototype for N = 2 is given by:
1
𝐻𝑃 (𝑠) = 2
𝑠 + 1.414 𝑠 + 1
Ω𝑠𝑡𝑜𝑝 38627.4
Ω𝑐 = 1 = 1 = 12245.8 rad/sec
100.1(𝐴𝑝𝑎𝑠𝑠)dB − 1 2𝑁 102 − 1 4
𝐻 𝑧 = 𝐻𝑎 𝑠 ቚ 2 1−𝑧 −1
𝑠=
𝑇 1+𝑧 −1
12245.8 2
= 2
2 1 − 𝑧 −1 2 1 − 𝑧 −1 2
+ 17318.18 + 12245.8
𝑇 1 + 𝑧 −1 𝑇 1 + 𝑧 −1
38
Design of Butterworth LPF using BLT
Matlab Implementation
39
Design of Butterworth LPF using BLT
Example 2:
Design a second-order digital lowpass Butterworth filter with a
cut-off frequency of 1kHz and a sampling rate of 10 kHz.
Solution:
In this example, N = 2 and the cut-off frequency are already given.
42.23 × 106
𝐻𝑎 𝑠 = 2
𝑠 + 9.19 × 103 𝑠 + 42.23 × 106
41
Design of Butterworth LPF using BLT
7. Finally, use the BLT to obtain the digital filter 𝐻(𝑧).
𝐻 𝑧 = 𝐻𝑎 𝑠 ቚ 2 1−𝑧 −1
𝑠=
𝑇 1+𝑧 −1
42.23 × 106
𝐻 𝑧 = 2
2 1 − 𝑧 −1 2 1 − 𝑧 −1
+ 9.19 × 103 + 42.23 × 106
𝑇 1 + 𝑧 −1 𝑇 1+𝑧 −1
42
Design of Butterworth LPF using BLT
Matlab Implementation
MATLAB: >> b
N = 2; b=
Fc = 1000; 0.0675 0.1349 0.0675
Fs = 10000;
Wc = 2*Fc/Fs; % without pi >> a
[b, a] = butter(N, Wc, 'low'); a=
freqz(b, a, 512, Fs); 1.0000 -1.1430 0.4128
43
Design of Butterworth LPF using BLT
Matlab Implementation
44
Matlab Commands
buttord Butterworth filter order and cutoff frequency
butter Butterworth filter design
cheb1ord Chebyshev Type I filter order
cheby1 Chebyshev Type I filter design
cheb2ord Chebyshev Type II filter order
cheby2 Chebyshev Type II filter design
ellipord Minimum order for elliptic filters
fir1 Window-based FIR filter design
45