Lecture 21

Post on 28-Nov-2015

31 views 1 download

description

dsp

Transcript of Lecture 21

Digital Filter Design procedure: 1. Specify Discrete-Time domain filter requirements

(LP,HP,…; ωp, ωs, …; αp, αs) 2. Use easiest (T=2) inverse bilinear transformation to

warp frequencies to Continuous-Time domain :

3. Design analog filter for (Ωp, Ωs, …, αp, αs ) and obtain Ha(s)=BCT(s)/ACT(s)

4. Convert to Discrete-time domain, using bilinear transformation, to obtain the rational transfer function G(z)=BDT(z)/ADT (z)

)2(tan)2(tan sspp

1

1

1

1|)()(

z

zs

a sHzG

Analog Filter Design procedure

1. Develop specifications of an analog lowpass filter prototype HLP(s) (choose ΩP=1) from specifications of desired analog filter HD(ŝ) using a frequency transformation s=F(ŝ) (e.g. HP to LP: )

2. Design the prototype analog lowpass filter

3. Derive the transfer function HD(ŝ) of the desired filter by inverse frequency transformation ŝ=F-1(s)

ss

pp

ˆ

Point 3 of previous slide is realized by:

)1(log20 10 pp

)(log20 10 ss

Peak passband ripple:

Minimum stopband attenuation

20101p

p

2010s

s

Peak ripple values δp and δs are obtained by inverting formulas:

Example: αp=0.15 dB → δp=0.017121 αs=41 dB → δs=0.0089125

)1(log20 2

10max

Maximum passband attenuation

As

1log20 10

Minimum stopband attenuation

Inverting formulas:

110 102max

2010s

A

Example: αmax=0.5 dB → ε2=0.12202 αs=40 dB → A=100

RECURSION:

Chebyshev polynomials and Chebyshev filters

Type 1 Chebyshev filter

Type 2 Chebyshev filter

Exercise: Given the Chebyshev polynomial of order 5, i.e. T5(x), for -2≤ x ≤ 2: • Plot

• Plot

• Plot

• Plot

)(25 xT

)(5 xT

)(1.01/1 2

5 xT

)(

101/1

12

5 xT

(corresponding to squared amplitude of a Type1 filter)

(corresponding to squared amplitude of a Type2 filter)

x=-2:1/100:2;

%Chebyshev Type1 polynomial y=16*x.^5-20*x.^3+5*x;

plot(x,y);

pause

axis([-2 2 -2 2]);

pause

plot(x,y.^2);

axis([-2 2 -2 2]);

pause

%Chebyshev Type1 filter plot(x,1./(1+0.1*y.^2))

pause

%Chebyshev Type2 filter y2=16*x.^-5-20*x.^-3+5*x.^-1;

plot(x,1./(1+10*y2.^-2))

Try also using higher order polynomials

)(5 xT

)(25 xT

)(1.01/1 2

5 xT

)(

101/1

12

5 xT

Analog lowpass filter design It is realized in Matlab by one of the following (see help of single functions):

Butterworth: [N,Wn]=buttord(Wp,Ws,Rp,Rs,’s’);

[B,A]=butter(N,Wn,’s’);

Chebyshev Type 1: [N,Wn]=cheb1ord(Wp,Ws,Rp,Rs,’s’);

[B,A]=cheby1(N,Rp,Wn,’s’);

Chebyshev Type 2: [N,Wn]= cheb2ord(Wp,Ws,Rp,Rs,’s’);

[B,A]= cheby2(N,Rs,Wn,’s’);

Elliptic: [N,Wn]=ellipord(Wp,Ws,Rp,Rs,’s’);

[B,A]=ellip(N,Rp,Rs,Wn,’s’);

Wp,Ws in rad/s Rp decibels of peak-to-peak passband ripple Rs minimum stopband attenuation in dB

Frequency transformations from LP analog filters in Matlab: [NUMT,DENT] = lp2lp(NUM,DEN,Wo)

transforms the analog lowpass filter prototype NUM(s)/DEN(s) with unity cutoff frequency of 1 rad/sec to a lowpass filter with cutoff frequency Wo (rad/sec) [NUMT,DENT] = lp2hp(NUM,DEN,Wo)

transforms the analog lowpass filter prototype with a cutoff angular frequency of 1 rad/s into highpass filters with desired cutoff angular frequency Wo [NUMT,DENT] = lp2bp(NUM,DEN,Wo,Bw)

transforms analog lowpass filter prototypes with a cutoff angular frequency of 1 rad/s into bandpass filters with desired center frequency Wo and bandwidth Bw [NUMT,DENT] = lp2bs(NUM,DEN,Wo,Bw)

transforms analog lowpass filter prototypes with a cutoff angular frequency of 1 rad/s into bandstop filters with desired center frequency Wo and bandwidth Bw

Bilinear transformation in Matlab: [num,den]=bilinear(NUM,DEN,fs)

converts an s-domain transfer function Ha(s) given by coefficients NUM and DEN to a discrete time equivalent G(z) given by coefficients num and den Row vectors NUM and DEN specify the coefficients of the numerator and denominator, respectively, in descending powers of s fs is the sampling frequency in hertz (fs=0.5 for the simplified condition T=2) bilinear returns the coefficients of the discrete-time equivalent filter in row vectors num and den in descending powers of z (ascending powers of z–1)

Design a digital filter according to the following requirements: Lowpass, 1 dB ripple in passband, ωp=0.4π, stopband attenuation ≥ 40 dB at ωs=0.5π and attenuation increasing with frequency.

Passband ripples, stopband monotonic → Chebyshev1 We assume T=2 → simplifies bilinear transformation Warp band-edges to continuous-time domain:

srad

srad

ss

p

p

/0.125.0tan2

tan

/7265.02.0tan2

tan

Magnitude specifications: 1 dB passband ripple

5087.08913.0101

1 20/1

2

40 dB stopband attenuation

10001.0101 20/40 AA

09.7

cosh

1cosh

1

21

p

s

A

N

Required Chebyshev1 filter order:

i.e. needs N=8

Filter design example

Filter design example (continued)

Design analog filter and then map it to discrete time domain: N=8;

Wp=0.7265;

pbripple=1.0;

[B,A]=cheby1(N,pbripple,Wp,’s’);

[b,a]=bilinear(B,A,0.5); %we assumed T=2

[H,W]=freqs(B,A,0:1/100:2);

plot(W,20*log10(abs(H)));

axis([0 2 -60 5]);

[HD,w]=freqz(b,a);

plot(w/pi,20*log10(abs(HD)));

axis([0 1 -60 5]);

Ω

)( jH Analog filter

ω/π

)( jeHD Digital filter

Design of Highpass IIR Digital Filter – Chebyshev Type 1 Specifications: passband edge: 700 Hz stopband edge: 500 Hz passband ripple: 1dB minimum stopband attenuation: 32 dB sampling frequency: 2kHz

Fp=700;

Fs=500;

alpha_p=1;

alpha_s=32;

FT=2000;

%Normalized angular bandedge (in rad/sample) wp=2*pi*Fp/FT;

ws=2*pi*Fs/FT;

%Assuming T=2 in inverse bilinear transformation Wp=tan(wp/2); %in rad/s Ws=tan(ws/2);

Wp_lp=1; %Normalized passband edge Ws_lp=Wp_lp*Wp/Ws; %Frequency transformation HP to LP

Band-edges of the discrete-time HP filter

Band-edges of the continuous-time HP filter

Band-edges of the continuous-time LP prototype

%find filter order and pass-band edge frequency [N,Wn]=cheb1ord(1,Ws_lp,alpha_p,alpha_s,'s');

%Design the LP prototype [B,A]=cheby1(N,alpha_p,Wn,'s');

%Apply frequency transformation LP to HP [BT,AT]=lp2hp(B,A,Wp);

%Apply bilinear transformation to get the discrete-time filter (again T=2) [num,den]=bilinear(BT,AT,0.5);

%Plot the amplitude of obtained transfer function [H,w]=freqz(num,den);

plot(w/pi,20*log10(abs(H)));

axis([0 1 -50 5]); %Zoom )( jeH

ω/π

Design of Highpass IIR Digital Filter - Elliptic Specifications: passband edge: 250 Hz stopband edge: 200 Hz passband ripple: 1dB minimum stopband attenuation: 80 dB sampling frequency: 1kHz

Fp=250;

Fs=200;

alpha_p=1;

alpha_s=80;

FT=1000;

wp=2*pi*Fp/FT;

ws=2*pi*Fs/FT;

Wp=tan(wp/2);

Ws=tan(ws/2);

Wp_lp=1;

Ws_lp=Wp_lp*Wp/Ws;

[N,Wn]=ellipord(1,Ws_lp,alpha_p,alpha_s,'s');

[B,A]=ellip(N,alpha_p,alpha_s,Wn,'s');

[BT,AT]=lp2hp(B,A,Wp);

[num,den]=bilinear(BT,AT,0.5);

[H,w]=freqz(num,den);

plot(w/pi,20*log10(abs(H)));

[N,Wn]=ellipord(wp/pi,ws/pi,alpha_p,alpha_s);

[num1,den1]=ellip(N,alpha_p,alpha_s,Wn,’high’);

[H1,w]=freqz(num1,den1);

plot(w/pi,20*log10(abs(H1)),'r');

The design procedure of the previous slide can be realized automatically by Matlab with a direct digital design:

Use of ellipord and ellip directly in the discrete time domain!

Matlab is applying bilinear transformation and frequency transformation for us.

Digital lowpass filter design It is directly realized in Matlab by one of the following (see help of single functions):

Butterworth: [N,Wn]=buttord(Wp,Ws,Rp,Rs);

[b,a]=butter(N,Wn);

Chebyshev Type 1: [N,Wn]=cheb1ord(Wp,Ws,Rp,Rs);

[b,a]=cheby1(N,Rp,Wn);

Chebyshev Type 2: [N,Wn]= cheb2ord(Wp,Ws,Rp,Rs);

[b,a]= cheby2(N,Rs,Wn);

Elliptic: [N,Wn]=ellipord(Wp,Ws,Rp,Rs);

[b,a]=ellip(N,Rp,Rs,Wn);

Wp,Ws normalized frequencies in the range 0…1. (1 corresponds to half the sampling rate) Rp decibels of peak-to-peak passband ripple Rs minimum stopband attenuation in dB

Design of Butterworth digital filters using the function butter : Lowpass: [b,a]=butter(N,Wn,’low’);

Highpass: [b,a]=butter(N,Wn,’high’);

Bandpass: [b,a]=butter(N,[Wn1,Wn2]); %two passband edge frequencies Bandstop: [b,a]=butter(N,[Wn1,Wn2],’stop’); %two stopband edge frequencies Note: bandpass and bandstop filters will have order 2*N Wn are normalized frequencies in the range 0…1 Similar syntax holds for cheby1, cheby2, ellip (see help of these functions).

Exercise 1: Design digital Butterworth filters with the following specifications: Order N=5; Sampling frequency fs=8000 Hz 1. Lowpass, cutoff frequency= 1000 Hz 2. Highpass, cutoff frequency = 2000 Hz 3. Bandpass, pass band = [1000, 2000] Hz 4. Bandstop, stop band = [1000, 2000] Hz Lowpass filter using directly digital design: fs=8000;

N=5;

fc=1000;

[b,a]=butter(N,fc/(fs/2),’low’);

[H,w]=freqz(b,a);

subplot(2,2,1);

plot(w/pi*fs/2,abs(H));

xlabel(‘Freq (Hz)’);

title(‘Freq. response of a low-pass filter’);

grid on

Complete the exercise with the other three cases.

Exercise 2: Compare the orders of Butterworth, Chebyshev Type1, Chebyshev Type2 and elliptic filters meeting the following specifications: • Lowpass • Passband edge at ω=π/2 • Maximum passband deviation of 1 dB • Stopband edge at ω=0.6π • Minimum stopband attenuation of 40 dB

[Use buttord, cheb1ord, cheb2ord, ellipord, with input parameters (0.5,0.6,1,40) and output parameters [N,Wn]. See help of these functions]

Exercise 3: Compare the frequency responses of Butterworth, Chebyshev Type1, Chebyshev Type2 and Elliptic lowpass filters of order 6 with cut-off frequency ω=π/2.

Butterworth Chebyshev 1 Chebyshev 2 Elliptic

Exercise 4: Design a digital highpass elliptic filter with the following specifications: FT=1.5 MHz, Fp=600 kHz, Fs=210kHz, αp=0.4 dB, αs=45 dB. Derive first the analog lowpass prototype and then convert it into the desired digital filter.

alpha_p=0.4;

alpha_s=45;

wp=2*pi*Fp/FT;

ws=2*pi*Fs/FT;

Wp=tan(wp/2);

Ws=tan(ws/2);

Wp_lp=1;

Ws_lp=Wp/Ws;

[N, Wn]=ellipord(Wp_lp, Ws_lp, alpha_p, alpha_s, ‘s’);

[B,A]=ellip(N, alpha_p, alpha_s, Wn, ‘s’);

[BT, AT]=lp2hp(B, A, Wp);

[num, den]=bilinear(BT, AT, 0.5);

076.3ˆ p

471.0ˆ s

p

s

sp

1 p

s

p

ps

ˆ

ˆ

8329.06434.13315.1

8329.00556.0)(

23

2

sss

ssH LP

0007.35ˆ1418.15ˆ0726.6ˆ

ˆ6322.0ˆ)ˆ(

23

3

sss

sssHHP

321

321

4357.05169.19413.11

0285.00414.00414.00285.0)(

zzz

zzzzGHP

Check zero and pole positions on the complex plane. Compare with direct digital design: [N,Wn]=ellipord(wp/pi,ws/pi,alpha_p,alpha_s);

[b,a]=ellip(N,alpha_p,alpha_s,Wn,‘high’);