0% found this document useful (0 votes)
68 views45 pages

Handout - 8 Digital Filter Design

Uploaded by

mohammadtestpi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views45 pages

Handout - 8 Digital Filter Design

Uploaded by

mohammadtestpi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Digital Signal Processing

Using Matlab

Digital Filter Design


Overview
• Introduction
• Ideal Filters
• Practical Filters
• LPF Design
• FIR LPF Design using Window Method
• IIR LPF Design using Butterworth
Approximation and BLT

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

• Ideal LPF passes low-


frequency signals and
eliminates high-
frequency signals.

Transfer Function Passband Stopband

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)

• Ideal HPF passes high-


frequency signals and
eliminates low-
frequency signals.

Ideal Bandpass Filter (BPF)

• Ideal BPF passes signals


between two specific
frequencies, but
eliminates signals at
other frequencies. 7
Ideal Filters
Ideal Bandstop Filter (BSF)

• Ideal BSF filter eliminates


signals between two
specific frequencies and
passes signals at all other
frequencies.

Ideal Allpass Filter (APF)

• Ideal APF passes all


frequencies equally in
gain, but changes their
phases.
8
Practical Filters
Ideal filters have the following characteristics:
• Unity gain in passband.
• Zero gain in stopband
• Zero-phase (no delay)
• Noncausal (infinite two-sided impulse response).
• Unstable (the sinc function is not absolutely summable)

Ideal filters cannot be implemented in practice; therefore, they


have to be approximated by practically realizable filters. Practical
filters differ from ideal filters in several respects:
(a) the passband responses are not perfectly flat,
(b) the stopband responses cannot completely reject (eliminate)
bands of frequencies, and
(c) the transition between passband and stopband regions takes
place over a finite transition band. 9
Practical Filters (Real , causal)

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

( Apass ) dB = −20 log10 (G pass )  0 for passband


( Astop ) dB = −20 log10 (Gstop )  0 for stopband

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

𝐴𝑠𝑡𝑜𝑝 = −20 log10 (0.01) = 40 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:

𝐴𝑝𝑎𝑠𝑠 = 1 = −20 log10 (𝐺𝑝𝑎𝑠𝑠 )

𝐺𝑝𝑎𝑠𝑠 = 10−1/20 = 0.891

𝐴𝑠𝑡𝑜𝑝 = 50 = −20 log10 (𝐺𝑠𝑡𝑜𝑝 )

𝐺𝑠𝑡𝑜𝑝 = 10−50/20 = 0.00316


14
LPF Design
LPF Design Parameters

– Impulse response = FIR/IIR


– Filter order = 𝑁 (Minimum/Specified)
– Sampling frequency = 𝐹𝑠 Hz
𝐹𝑝𝑎𝑠𝑠
– Passband frequency = 𝐹𝑝𝑎𝑠𝑠 Hz or 𝜔𝑝𝑎𝑠𝑠 = 2𝜋
𝐹𝑠
𝐹𝑠𝑡𝑜𝑝
– Stopband frequency = 𝐹𝑠𝑡𝑜𝑝 Hz or 𝜔𝑠𝑡𝑜𝑝 = 2𝜋
𝐹𝑠
– Passband ripple = 𝐴𝑝𝑎𝑠𝑠 dB
– Stopband attenuation = 𝐴𝑠𝑡𝑜𝑝 dB
– Design method:
• FIR = Window, Equiripple, Interpolated, etc.
• IIR = Butterworth, Chebyshev, Elliptic, etc.
15
LPF Design
LPF Relative Specifications

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

𝐴𝑠𝑡𝑜𝑝 = −20 log10 0.2 = 13.98 dB


𝜔𝑝𝑎𝑠𝑠 = 0.2𝜋

𝜔𝑠𝑡𝑜𝑝 = 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

Impulse response for the low-pass FIR filter:


𝜔𝑐ൗ
sin(𝜔𝑐 𝑛) 𝜔𝑐 𝜔𝑐 𝑛 𝜋 for 𝑛 = 0
ℎ 𝑛 = = sinc = ൞sin(𝜔𝑐 𝑛)
𝜋𝑛 𝜋 𝜋 for 𝑛 ≠ 0
𝜋𝑛

For 3-tap FIR Filter, 𝑛 = −1, 0, 1

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

b = fir1(n, Wn, 'ftype', window, 'normalization')


Impulse Response

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.0150 0.2000 0.0150 0.02

0 50 100 150 200 250


Time (useconds)
Impulse Response
0.9
>> b = fir1(2, .2) 0.8

0.7

b= 0.6
Amplitude

0.5

0.0651 0.8698 0.0651 0.4

0.3

0.2

0.1

0 50 100 150 200 250


Time (useconds)
24
IIR LPF Design ***
• The most common method of designing IIR filters is based on
the conversion of analog lowpass filter prototypes (like
Butterworth, Chebyshev, and Elliptic) into digital filters by using
a mapping algorithm such as the bilinear transformation (BLT).
• Bilinear transformation maps the s-plane poles and zeros of the
analog filter into the z-plane.
• Under this mapping:
o the entire 𝑗Ω axis in the s-plane is mapped onto the unit
circle in the z-plane;
o the left-half s-plane is mapped inside the unit circle and
o the right-half s-plane is mapped outside the unit circle.
• It is also possible to design an IIR filter without any reference to
analog designs.
25
IIR LPF Design

𝐻𝑎 (𝑠) Mapping (BLT) 𝐻(𝑧)

Bilinear transformation (BLT) from the s-plane (analog)


to the z-plane (digital)
26
IIR LPF Design
▪ Butterworth filters:
• Maximally flat magnitude response in both passband and
stopband (no ripple).
• Slow roll-off rate (large transition band).
• Fairly linear phase in the passband.
• Require higher order compared to other types.
▪ Chepychev filters:
• Type I: have ripple in passband and flat in stopband.
• Type II: flat in passband and have ripple in stopband.
• Moderate roll-off rate (sharper transition).
• Phase characteristics in between Butterworth and elliptic.
• Moderate filter order.
27
IIR LPF Design
▪ Elliptic filters:
• Have ripples in both passband and stopband.
• Fast roll-off rate (steeper transition than that of a
Butterworth or Chebyshev).
• Highly nonlinear phase response in the passband.
• Lower filter order.

28
IIR LPF Design

Comparison of Butterworth, Chebyshev, and elliptic filters


29
Design of Butterworth LPF using BLT

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:

1. Calculate the digital frequencies 𝜔𝑝𝑎𝑠𝑠 and 𝜔𝑠𝑡𝑜𝑝 .


2. Compute the equivalent analog frequencies Ω𝑝𝑎𝑠𝑠 and Ω𝑠𝑡𝑜𝑝
using the pre-warping equation:
2 𝜔𝑝𝑎𝑠𝑠 2 𝜔𝑠𝑡𝑜𝑝
Ω𝑝𝑎𝑠𝑠 = tan Ω𝑠𝑡𝑜𝑝 = tan
𝑇 2 𝑇 2
3. Find the filter order using:
1
൘𝐺 2 − 1
log
𝑠𝑡𝑜𝑝 100.1(𝐴𝑠𝑡𝑜𝑝 )dB − 1
1 log
൘𝐺 2 − 1 100.1(𝐴𝑝𝑎𝑠𝑠)dB − 1
𝑝𝑎𝑠𝑠
𝑁= =
Ω𝑠𝑡𝑜𝑝 Ω𝑠𝑡𝑜𝑝
log log
Ω𝑝𝑎𝑠𝑠 Ω𝑝𝑎𝑠𝑠 31
Design of Butterworth LPF using BLT
4. Select the normalized (Ω𝑐 = 1) Butterworth prototype
corresponding to N from the following table:

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

5. Calculate the analog 3-dB cutoff frequency, Ω𝑐 .

Ω𝑠𝑡𝑜𝑝 38627.4
Ω𝑐 = 1 = 1 = 12245.8 rad/sec
100.1(𝐴𝑝𝑎𝑠𝑠)dB − 1 2𝑁 102 − 1 4

6. Find the Transfer Function, 𝐻𝑎 (𝑠) of the analog LPF.


12245.8 2
𝐻𝑎 𝑠 = 𝐻𝑃 𝑠 ቚ 𝑠 = 2 2
𝑠→
Ω𝑐 𝑠 + 17318.18 𝑠 + 12245.8
36
Design of Butterworth LPF using BLT
7. Finally, use the BLT to obtain the digital filter 𝐻(𝑧).

𝐻 𝑧 = 𝐻𝑎 𝑠 ቚ 2 1−𝑧 −1
𝑠=
𝑇 1+𝑧 −1

12245.8 2
= 2
2 1 − 𝑧 −1 2 1 − 𝑧 −1 2
+ 17318.18 + 12245.8
𝑇 1 + 𝑧 −1 𝑇 1 + 𝑧 −1

Simplifying this equation yields to:


0.2195 + 0.4391 𝑧 −1 + 0.2195 𝑧 −2
𝐻 𝑧 =
1 − 0.3105 𝑧 −1 + 0.1887 𝑧 −2

In final exam, no need to find the exact function 𝑯 𝒛


37
Design of Butterworth LPF using BLT
Matlab Implementation

[N, Wc] = buttord(Wpass, Wstop, Apass, Astop)


[b, a] = butter(N, Wc, ftype)
MATLAB: >> b
Apass = 1; b=
Astop = 20; 0.2195 0.4391 0.2195
Fpass = 1000;
Fstop = 3000; >> a
Fs = 8000; a=
Wpass = 2*Fpass/Fs; % without pi 1.0000 -0.3105 0.1887
Wstop = 2*Fstop/Fs; % without pi
[N, Wc] = buttord(Wpass, Wstop, Apass, Astop);
[b, a] = butter(N, Wc, 'low');
freqz(b, a, 512, Fs);

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.

1. Calculate the digital cutoff frequency 𝜔𝑐


2𝜋𝐹𝑐 2𝜋 1𝑘
𝜔𝑐 = = = 0.2𝜋 rad/sample
𝐹𝑠 10𝑘
2. Pre-warp 𝜔𝑐 to get the new analog Ω𝑐
2 𝜔𝑐 2 0.2𝜋
Ω𝑐 = tan = −4 tan = 6498.4 rad/sec
𝑇 2 10 2
40
Design of Butterworth LPF using BLT
3. The filter order is given as N = 2.
4. The second-order Butterworth prototype is given by:
1
𝐻𝑝 (𝑠) = 2
𝑠 + 1.414𝑠 + 1

5. The analog 3-dB cut-off frequency Ω𝑐 = 6498.4 rad/sec

6. Find the Transfer Function, 𝐻𝑎 (𝑠) of the analog LPF.


Ω𝑐 2
𝐻𝑎 𝑠 = 𝐻𝑝 (𝑠)ቚ 𝑠 = 2
𝑠=Ω
𝑐 𝑠 2 + 1.414Ω𝑐 𝑠 + Ω𝑐

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

0.0675 + 0.1349 𝑧 −1 + 0.0675 𝑧 −2


𝐻 𝑧 =
1 − 1.143 𝑧 −1 + 0.4128 𝑧 −2

42
Design of Butterworth LPF using BLT
Matlab Implementation

[b, a] = butter(N, Wc, ftype)

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

You might also like