laboratory 10: iir butterworth filter design · 2020. 8. 27. · laboratory 10: iir butterworth...

13
Page 1 EE-384: Digital Signal Processing Spring 2020 Laboratory 10: IIR Butterworth Filter Design Instructor: Mr Ammar Naseer EE UET New Campus Aims IIR filters have infinite-duration impulse responses, hence they can be matched to analog filters, all of which generally have infinitely long impulse responses. Therefore the basic technique of IIR filter design transforms well-known analog filters into digital filters using complex-valued mappings. The advantage of this technique lies in the fact that both analog filter design (AFD) tables and the mappings are available extensively in the literature. This basic technique is called the A/D (analog-to-digital) filter transformation. There are two approaches to this basic technique of IIR filter design: Figure 10.1: IIR Filter design approaches The first approach is used in MATLAB to design IIR filters. A straightforward use of these MATLAB functions does not provide any insight into the design methodology. Therefore we will study the second approach because it involves the frequency band transformation in the digital domain. Hence in this IIR filter design technique we will follow the following steps: Design analog lowpass filters Study and apply filter transformations to obtain digital lowpass filters. Study and apply frequency-band transformations to obtain other digital filters from digital lowpass filters. We begin with a discussion on the analog filter specifications and the properties of the magnitude squared response used in specifying analog filters. This is followed by MATLAB implementation of widely used analog filters: namely, Butterworth, Chebychev

Upload: others

Post on 03-Mar-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Page 1

EE-384: Digital Signal Processing Spring 2020

Laboratory 10: IIR Butterworth Filter Design

Instructor: Mr Ammar Naseer EE UET New Campus

Aims

IIR filters have infinite-duration impulse responses, hence they can be matched to analog filters, all of

which generally have infinitely long impulse responses. Therefore the basic technique of IIR filter design

transforms well-known analog filters into digital filters using complex-valued mappings. The advantage

of this technique lies in the fact that both analog filter design (AFD) tables and the mappings are

available extensively in the literature. This basic technique is called the A/D (analog-to-digital) filter

transformation. There are two approaches to this basic technique of IIR filter design:

Figure 10.1: IIR Filter design approaches

The first approach is used in MATLAB to design IIR filters. A straightforward use of these MATLAB

functions does not provide any insight into the design methodology. Therefore we will study the second

approach because it involves the frequency band transformation in the digital domain. Hence in this IIR

filter design technique we will follow the following steps:

Design analog lowpass filters

Study and apply filter transformations to obtain digital lowpass filters.

Study and apply frequency-band transformations to obtain other digital filters from digital

lowpass filters.

We begin with a discussion on the analog filter specifications and the properties of the magnitude

squared response used in specifying analog filters. This is followed by MATLAB implementation of widely

used analog filters: namely, Butterworth, Chebychev

Page 2: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.2

Pre-Lab: Some Preliminaries We discuss two preliminary issues in this section. First, we consider the magnitude-squared response

specifications, which are more typical of analog (and hence of IIR) filters. These specifications are given

on the relative linear scale. Second, we study the properties of the magnitude-squared response.

Relative Linear Scale

Let be the frequency response of an analog filter. Then the lowpass filter specifications on the

magnitude-squared response are given by

| | | |

| |

| |

(10.1)

where ϵ is a passband ripple parameter, is the passband cutoff frequency in rad/sec,

Figure 10.2: Analog lowpass filter specifications

A is a stopband attenuation parameter, and is the stopband cutoff in rad/sec. These specifications

are shown in Figure 10.2. The parameters ϵ and A are related to parameters Rp and As, respectively, of

the dB scale. These relations are

√ ⁄ (10.2)

and

(10.3)

The ripples, and , of the absolute scale are related to ϵ and A by

Page 3: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.3

(10.4)

and

(10.5)

Properties

Analog filter specifications (10.1), which are given in terms of the magnitude-squared response, contain

no phase information. Now to evaluate the s-domain system function , consider

| |

Then we have

| | |

or

| | (10.6)

Therefore the poles and zeros of the magnitude squared function are distributed in a mirror image

symmetry with respect to the axis. Also for real filters, poles and zeros occur in complex conjugate

pairs (or mirror image symmetry with respect to the real axis). A typical pole-zero pattern of

is shown in Figure 10.3. From this pattern we can construct , which is the system

function of our analog filter. We want to represent a causal and stable filter. Then all poles of

must lie within the left half-plane. Thus we assign all left-half poles of to .

However, zeros of can lie anywhere in the s-plane. Therefore they are not uniquely determined

unless they all are on the axis. We will choose the zeros of lying left to or on the

axis as the zeros of . The resulting filter is then called a minimum phase filter.

Butterworth Lowpass Filters

This filter is characterized by the property that its magnitude response is at in both passband and

stopband. The magnitude-squared response of an Nth-order lowpass filter is given by

| |

(

)

(10.7)

Page 4: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.4

Figure 10.3: Typical pole-zero pattern of

where N is the order of the filter and is the cutoff frequency in rad/sec. The plot of the magnitude

squared response is as follow.

Figure 10.4: Response of a Butterworth filter

From this plot, we can observe the following properties:

at =0, | | ,

at , | |

, , which implies a 3 dB attenuation at .

| | is a monotonically decreasing function of .

| | approaches an ideal lowpass filter as N → ∞.

| | is maximally flat at since derivatives of all orders exist and are equal to zero.

To determine the system function , we put (10.7) in the form of (10.6) to obtain

| |

(

)

(10.8)

The roots of the denominator polynomial are given by

(10.9)

An interpretation of (10.9) is that

there are 2N poles of , which are equally distributed on a circle of radius with

angular spacing of

radians

for N odd the poles are given by k = 0,. . . , 2N – 1

for N even the poles are given by (

) k = 0, . . ., 2N – 1

the poles are symmetrically located with respect to the axis

Page 5: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.5

a pole never falls on the imaginary axis, and falls on the real axis only if N is odd

A stable and causal filter can now be specified by selecting poles in the left half-plane, and

can be written in the form

∏ (10.10)

Matlab implementation

MATLAB provides a function called [z,p,k]=buttap(N) to design a normalized (i.e., ) Butterworth

analog prototype filter of order N, which returns zeros in z array, poles in p array, and the gain value k.

However, we need an unnormalized Butterworth filter with arbitrary . Poles of the unnormalized

filter are on a circle with radius instead of on a unit circle. This means that we have to scale the array

p of the normalized filter by and the gain k by . In the following function, called

U_buttap(N,Omegac), we design the unnormalized Butterworth analog prototype filter.

function [b,a] = u_buttap(N,Omegac);

% Unnormalized Butterworth Analog Lowpass Filter Prototype

% __________________________________________________________

% [b,a] = u_buttap(N,Omegac);

% b = numerator polynomial coefficients of Ha(s)

% a = denominator polynomial coefficients of Ha(s)

% N = Order of the Butterworth Filter

% Omegac = Cutoff frequency in radians/sec

%

[z,p,k] = buttap(N);

p = p*Omegac;

k = k*Omegac^N;

B = real(poly(z));

b0 = k; b = k*B; a = real(poly(p));

end

This function provides a direct form (or numerator-denominator) structure. Often we also need a

cascade form structure. The following sdir2cas function describes the procedure that is suitable for

analog filters.

function [C,B,A] = sdir2cas(b,a);

% DIRECT form to CASCADE form conversion in s-plane

% __________________________________________________

% [C,B,A] = sdir2cas(b,a)

% C = gain coefficient

% B = K by 3 matrix of real coefficients containing b k s

% A = K by 3 matrix of real coefficients containing a k s

% b = numerator polynomial coefficients of DIRECT form

% a = denominator polynomial coefficients of DIRECT form

%

Na = length(a)-1; Nb = length(b)-1;

% compute gain coefficient C

Page 6: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.6

b0 = b(1); b = b/b0; a0 = a(1); a = a/a0; C = b0/a0;

%

% Denominator second-order sections:

p= cplxpair(roots(a)); K = floor(Na/2);

if K*2 == Na % Computation when Na is even

A = zeros(K,3);

for n=1:2:Na

Arow = p(n:1:n+1,:); Arow = poly(Arow);

A(fix((n+1)/2),:) = real(Arow);

end

elseif Na == 1 % Computation when Na = 1

A = [0 real(poly(p))];

else % Computation when Na is odd and > 1

A = zeros(K+1,3);

for n=1:2:2*K

Arow = p(n:1:n+1,:); Arow = poly(Arow);

A(fix((n+1)/2),:) = real(Arow);

end

A(K+1,:) = [0 real(poly(p(Na)))];

end

% Numerator second-order sections:

z = cplxpair(roots(b)); K = floor(Nb/2);

if Nb == 0 % Computation when Nb = 0

B = [0 0 poly(z)];

elseif K*2 == Nb % Computation when Nb is even

B = zeros(K,3);

for n=1:2:Nb

Brow = z(n:1:n+1,:); Brow = poly(Brow);

B(fix((n+1)/2),:) = real(Brow);

end

elseif Nb == 1 % Computation when Nb = 1

B = [0 real(poly(z))];

else % Computation when Nb is odd and > 1

B = zeros(K+1,3);

for n=1:2:2*K

Brow = z(n:1:n+1,:); Brow = poly(Brow);

B(fix((n+1)/2),:) = real(Brow);

end

B(K+1,:) = [0 real(poly(z(Nb)))];

End

Design Equations

The analog lowpass filter is specified by the parameters , , and . Therefore the essence of the

design in the case of Butterworth filter is to obtain the order N and the cutoff frequency , given these

specifications. We want

at , -10 | | or

Page 7: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.7

(

(

)

)

and

at , -10 | | or

(

(

)

)

Solving these two equations for N and , we have

[ (

)

]

(10.11)

where the operation means "choose the smallest integer larger than x". Since the actual N chosen is

larger than required, specifications can be either met or exceeded either at or at . To satisfy the

specifications exactly at ,

(10.12)

or, to satisfy the specifications exactly at

√ (10.13)

MATLAB Implementation

The preceding design procedure can be implemented in MATLAB as a simple function. Using the

U_buttap function, we provide the afd_butt function to design an analog Butterworth lowpass filter,

given its specifications. This function uses (10.12).

function [b,a] = afd_butt(Wp,Ws,Rp,As);

% Analog Lowpass Filter Design: Butterworth

% _________________________________________

% [b,a] = afd_butt(Wp,Ws,Rp,As);

% b = Numerator coefficients of Ha(s)

% a = Denominator coefficients of Ha(s)

Page 8: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.8

% Wp = Passband edge frequency in rad/sec; Wp > 0

% Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0

% Rp = Passband ripple in +dB; (Rp > 0)

% As = Stopband attenuation in +dB; (As > 0)

%

if Wp <= 0

error('Passband edge must be larger than 0')

end

if Ws <= Wp

error('Stopband edge must be larger than Passband edge')

end

if (Rp <= 0) | (As < 0)

error('PB ripple and/or SB attenuation must be larger than 0')

end

N = ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(Wp/Ws)));

fprintf( '\n*** Butterworth Filter Order = %2.0f \n ,N')

OmegaC = Wp/((10^(Rp/10)-1)^(1/(2*N)));

[b,a]=u_buttap(N,OmegaC);

End

To display the frequency-domain plots of analog filters, we provide a function called freqs_m, which is a

modified version of a function freqs provided by MATLAB. This function computes the magnitude

response in absolute as well as in relative dB scale and the phase response. This function is similar to the

freqz_m function discussed earlier. One main difference between them is that in the freqs_m function

the responses are computed up to a maximum frequency .

function [db,mag,pha,w] = freqs_m(b,a,wmax);

% Computation of s-domain frequency response: Modified version

% _____________________________________________________________

% [db,mag,pha,w] = freqs m(b,a,wmax);

% db = Relative magnitude in db over [0 to wmax]

% mag = Absolute magnitude over [0 to wmax]

% pha = Phase response in radians over [0 to wmax]

% w = array of 500 frequency samples between [0 to wmax]

% b = Numerator polynomial coefficents of Ha(s)

% a = Denominator polynomial coefficents of Ha(s)

% wmax = Maximum frequency in rad/sec over which response is desired

%

w = [0:1:500]*wmax/500; H = freqs(b,a,w);

mag = abs(H); db = 20*log10((mag+eps)/max(mag)); pha = angle(H);

end

The impulse response ha(t) of the analog filter is computed using MATLABs impulse function.

10A: Design the analog Butterworth lowpass filter using MATLAB passband cutoff: ;

passband ripple: Rp = 7 dB, stopband cutoff: and stopband ripple: As = 16 dB..

From (10.11)

Page 9: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.9

[ (

)

]

To satisfy the specification exactly at from 10.12 we obtain

To satisfy the specification exactly at from 10.13 we obtain

We choose between the above two number. Hence we design the butterworth filter with

N=3. Using (10.10) we get

Matlab Implementation

>> wp = 0.2*pi; ws = 0.3*pi; Rp = 7; As = 16;

>> Ripple = 10^(-Rp/20);

>> Attn = 10^(-As/20);

>> % Analog filter design:

>> [b,a] = afd_butt(wp,ws,Rp,As);

*** Butterworth Filter Order = >> 3;

>> % Calculation of second-order sections:

>> [C,B,A] = sdir2cas(b,a)

C =

0.1238

B =

0 0 1

A =

1.0000 0.4985 0.2485

0 1.0000 0.4985

>> % Calculation of Frequency Response:

>> [db,mag,pha,w] = freqs_m(b,a,0.5*pi);

>> % Calculation of Impulse response:

>> [ha,x,t] = impulse(b,a);

The system function is given as

Where the filter response of the system is calculated as shown in Figure 10.5

Page 10: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.10

Figure 10.5: filter response

Impulse Invariant Transform

In this design method we want the digital filter impulse response to look similar to that of a frequency

selective analog filter. Hence we sample ha(t) at some sampling interval T to obtain h(n); that is,

The parameter T is chosen so that the shape of ha(t) is "captured" by the samples. Since this is a

sampling operation, the analog and digital frequencies are related by

(10.14)

or

Since on unit circle and on the imaginary axis, we have the following transformation

from the s-plane to the z-plane:

(10.15)

The complex plane transformation under the mapping (10.15) is shown in Figure 10.6, from which we

have the following observations:

1. Using , we note that

< 0 maps into lzl < 1 (inside of the UC)

= 0 maps onto lzl= 1 (on the UC)

> 0 maps into (z( > 1 (outside of the UC)

2. All semi-infinite strips (shown above) of width ⁄ map into lzl < 1. Thus this mapping is not

unique but a many to one mapping.

3. Since the entire left half of the s-plane maps into the unit circle, a causal and stable analog filter

maps into a causal and stable digital filter.

Page 11: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.11

Figure 10.6: Complex-plane mapping in impulse invariance transformation

However, no analog filter of finite order can be exactly band-limited. Therefore some aliasing error will

occur in this design procedure, and hence the sampling interval T plays a minor role in this design

method.

Matlab Implementation

Given a rational function description of , we can use the residue function to obtain its pole-zero

description. Then each analog pole is mapped into a digital pole using (10.15). Finally, the residuez

function can be used to convert H (z) into rational function form. This procedure is given in the function

imp_invr

function [b,a] = imp_invr(c,d,T)

% Impulse Invariance Transformation from Analog to Digital Filter

% _________________________________________________________________

%[b,a] = imp_invr(c,d,T)

% b = Numerator polynomial in z(-1) of the digital filter

% a = Denominator polynomial in z(-1) of the digital filter

% c = Numerator polynomial in s of the analog filter

% d = Denominator polynomial in s of the analog filter

% T = Sampling (transformation) parameter

%

[R,p,k] = residue(c,d);

p = exp(p*T);

[b,a] = residuez(R,p,k);

b = real(b');

a = real(a');

end

10B: Transform

into a digital filter H (z) using the impulse invariance technique in which T = 0.1.

>> c = [1,1];

>> d = [1,5,6];

>> T= 0.1;

Page 12: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.12

>> [b,a] = imp_invr(c, d, T)

b =

1.0000

-0.8966

a =

1.0000

-1.5595

0.6065

Using the code our digital filter would be defined as

Bilinear Transformation

This mapping is the best transformation method; it involves a well-known function given by

⁄ (10.16)

The complex plane mapping under (10.16) is shown in Figure 10.7, from which we have the following

observations

Figure 10.7: Complex-plane mapping in bilinear transformation

1. Using in (10.16), we obtain

⁄ (10.17)

Hence

| |

| |

| |

2. The entire left half-plane maps into the inside of the unit circle. Hence this is a stable

transformation.

3. The imaginary axis maps onto the unit circle in a one to one fashion. Hence there is no aliasing in

the frequency domain.

Page 13: Laboratory 10: IIR Butterworth Filter Design · 2020. 8. 27. · Laboratory 10: IIR Butterworth Filter Design 10.2 Pre-Lab: Some Preliminaries We discuss two preliminary issues in

Laboratory 10: IIR Butterworth Filter Design 10.13

Substituting in (10.17), we obtain

since the magnitude is 1. Solving for ω as a function of Ω, we obtain

(

)

(

) (10.18)

This shows that Ω is nonlinearly related to (or warped into) ω but that there is no aliasing. Hence in

(10.18) we will say that ω is prewarped into Ω.

MATLAB provides a function called bilinear to implement this mapping. Its invocation is similar to the

imp_invr function, but it also takes several forms for different input output quantities.

10C: Transform function defined in 10B into a digital filter using the bilinear transformation. Choose

T=1.

>> c = [1,1];

>> d = [1,5,6];

>> T = 1; Fs = 1/T;

>> [b,a] = bilinear(c,d,Fs)

b =

0.1500 0.1000 -0.0500

a =

1.0000 0.2000 -0.0000

Using the code our digital filter would be defined as

Main Lab

10D. Design a digital lowpass Butterworth filter using Impulse Invariant Transformation to satisfy

passband cutoff: ; passband ripple: Rp = 1 dB, stopband cutoff: and stopband

ripple: As = 15 dB.

10E. Design a digital lowpass Butterworth filter using bilinear transformation to satisfy passband cutoff:

; passband ripple: Rp = 1 dB, stopband cutoff: and stopband ripple: As = 15 dB.