You are on page 1of 14

Project 7.2 IIR Filter Design %Q7.

1 UsingMATLAB determine the lowest order of a digital IIR lowpass filter of all four %types. The specifications are as follows: sampling rate of 40 kHz, passband edge frequency %of 4 kHz, stopband edge frequency of 8 kHz, passband ripple of 0.5 dB, and a minimum %stopband attenuation of 40 dB. Comment on your results. clc,clear fs = 40000; rp = 0.5; rs = 40; wp = 4000/fs; ws = 8000/fs; %Filtro Butterworth [N, Wn] = buttord(wp, ws, rp, rs); disp(['orden Filtro Butterworth = ', num2str(N)]) %Filtro Chevichev tipo 1 [N, Wn] = cheb1ord(wp, ws, rp, rs); disp(['orden Filtro Chevichev tipo 1 = ', num2str(N)]) %Filtro Chevichev tipo 2 [N, Wn] = cheb2ord(wp, ws, rp, rs); disp(['orden Filtro Chevichev tipo 2 = ', num2str(N)]) %Filtro Eliptico [N, Wn] = ellipord(wp, ws, rp, rs); disp(['orden Filtro Eliptico = ', num2str(N)]) orden orden orden orden Filtro Filtro Filtro Filtro Butterworth = 8 Chevichev tipo 1 = 5 Chevichev tipo 2 = 5 Eliptico = 4

%% Q7.2 Using MATLAB determine the lowest order of a digital IIR highpass filter of all %four types. The specifications are as follows: sampling rate of 3,500 Hz, passband edge %frequency of 1,050 Hz, stopband edge frequency of 600 Hz, passband ripple of 1 dB, and %a minimum stopband attenuation of 50 dB. Comment on your results. clc,clear fs = 7000; wp = [1400 2100]./fs; ws = [1050 2450]./fs; rp = 0.4; rs = 50; %Filtro Butterworth [N, Wn] = buttord(wp, ws, rp, rs); disp(['orden Filtro Butterworth = ', num2str(N)]) %Filtro Chevichev tipo 1 [N, Wn] = cheb1ord(wp, ws, rp, rs); disp(['orden Filtro Chevichev tipo 1 = ', num2str(N)]) %Filtro Chevichev tipo 2 [N, Wn] = cheb2ord(wp, ws, rp, rs); disp(['orden Filtro Chevichev tipo 2 = ', num2str(N)]) %Filtro Eliptico

[N, Wn] = ellipord(wp, ws, rp, rs); disp(['orden Filtro Eliptico => ', num2str(N)]) orden orden orden orden Filtro Filtro Filtro Filtro Butterworth = 12 Chevichev tipo 1 = 7 Chevichev tipo 2 = 7 Eliptico => 5

%Q7.3 UsingMATLAB determine the lowest order of a digital IIR bandpass filter of all four %types. The specifications are as follows: sampling rate of 7 kHz, passband edge frequencies %at 1.4 kHz and 2.1 kHz, stopband edge frequencies at 1.05 kHz and 2.45 kHz, passband %ripple of 0.4 dB, and a minimum stopband attenuation of 50 dB. Comment on your results. clc,clear fs = 7000; wp = [1400 2100]./fs; ws = [1050 2450]./fs; rp = 0.4; rs = 50; %Filtro Butterworth [N, Wn] = buttord(wp, ws, rp, rs); disp(['orden Filtro Butterworth = ', num2str(N)]) %Filtro Chevichev tipo 1 [N, Wn] = cheb1ord(wp, ws, rp, rs); disp(['orden Filtro Chevichev tipo 1 = ', num2str(N)]) %Filtro Chevichev tipo 2 [N, Wn] = cheb2ord(wp, ws, rp, rs); disp(['orden Filtro Chevichev tipo 2 > ', num2str(N)]) %Filtro Eliptico [N, Wn] = ellipord(wp, ws, rp, rs); disp(['orden Filtro Eliptico = ', num2str(N)])

orden Filtro Butterworth = 12 orden Filtro Chevichev tipo 1 = 7 orden Filtro Chevichev tipo 2 = 7 orden Filtro Eliptico = 5
Q7.4 Using MATLAB determine the lowest order filter of all four types. The specifications rate of 12 kHz, passband edge frequencies at stopband edge frequencies at 2.7 kHz and 3.9 dB, and a minimum stopband attenuation of 45 results. clc,clear fs = 12000; wp = [2100 4500]./fs; ws = [2700 3900]./fs; rp = 0.6; rs = 45; %Filtro Butterworth of a digital IIR bandstop are as follows: sampling 2.1 kHz and 4.5 kHz, kHz, passband ripple of 0.6 dB. Comment on your

[N, Wn] = buttord(wp, ws, rp, rs); disp(['orden Filtro Butterworth => ', num2str(N)]) %Filtro Chevichev tipo 1 [N, Wn] = cheb1ord(wp, ws, rp, rs); disp(['orden Filtro Chevichev tipo 1 => ', num2str(N)]) %Filtro Chevichev tipo 2 [N, Wn] = cheb2ord(wp, ws, rp, rs); disp(['orden Filtro Chevichev tipo 2 => ', num2str(N)]) %Filtro Eliptico [N, Wn] = ellipord(wp, ws, rp, rs); disp(['orden Filtro Eliptico => ', num2str(N)])

orden orden orden orden

Filtro Filtro Filtro Filtro

Butterworth => 10 Chevichev tipo 1 => 6 Chevichev tipo 2 => 6 Eliptico => 5

Project 7.2 IIR Filter Design % Program P7_1 % Design of a Butterworth Bandstop Digital Filter Ws = [0.4 0.6]; Wp = [0.3 0.7]; Rp = 0.4; Rs = 50; % Estimate the Filter Order [N1, Wn1] = buttord(Wp, Ws, Rp, Rs); % Design the Filter [num,den] = butter(N1,Wn1,'stop'); % Display the transfer function disp('Numerator coefficients are ');disp(num); disp('Denominator coefficients are ');disp(den); % Compute the gain response %[g,w] = gain(num,den); % Plot the gain response plot(w/pi,g);grid axis([0 1 -60 5]); xlabel('\omega /\pi'); ylabel('Gain, dB'); title('Gain Response of a Butterworth Bandstop Filter');

Las especificaciones del filtros son : Numerator coefficients are Columns 1 through 9 0.0330 0.0000 0.2972 0.0000 1.1889 0.0000 2.7741 0.0000 4.1611 Columns 10 through 18 0.0001 4.1611 0.0000 2.7741 0.0000 1.1889 0.0000 0.2972 0.0000 Column 19 0.0330

Denominator coefficients are Columns 1 through 9 1.0000 0.0000 2.6621 0.0000 4.1451 0.0001 4.1273 0.0001 2.8977 Columns 10 through 18 0.0000 1.4381 0.0000 0.5027 0.0000 0.1178 0.0000 0.0167 0.0000 Column 19 0.0011
Gain Response of a Butterworth Bandstop Filter 0

-10

-20 Gain in dB

-30

-40

-50

-60

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

the filters unwrapped phase response and the group delay response are

Q7.6 Modify Program P7 1 to design a Type 1 Chebyshev lowpass filter meeting the specifications given in Question Q7.1. Write down the exact expression for the transfer function generated. Does your design meet the specifications? Using MATLAB, compute and plot the filters unwrapped phase response and the group delay response. % Program P7_1 % Design of a Type 1 Chebyshev lowpass Digital Filter

Ws = [0.4]; Wp = [0.3]; Rp = 0.4; Rs = 50; % Estimate the Filter Order [N1, Wn1] = cheb1ord(Wp, Ws, Rp, Rs); % Design the Filter [num,den] = cheby1(N1,.5,Wn1,'low'); % Display the transfer function disp('Numerator coefficients are ');disp(num); disp('Denominator coefficients are ');disp(den); % Compute the gain response [g,w] = gain(num,den); % Plot the gain response plot(w/pi,g);grid; axis([0 1 -60 5]); xlabel('\omega /\pi'); ylabel('Gain, dB'); title('Gain Response of a Chebyshev I lowpass Filter'); tf(num,den) grpdelay(num,den) % respuesta en fase. plot(w/pi,unwrap(angle(g))); Las espicificaciones del filtro son: Numerator coefficients are Columns 1 through 9 0.0000 0.0001 0.0003 0.0007 0.0011 0.0011 0.0007 0.0003 0.0001

Column 10 0.0000 Denominator coefficients are Columns 1 through 9 1.0000 -6.1183 18.0559 -33.3232 42.1114 -37.6501 23.7711 -10.2170 2.7160 Column 10 -0.3413

Q7.7 Modify Program P7 1 to design a Type 2 Chebyshev highpass filter meeting the specifications given in Question Q7.2. Write down the exact expression for the transfer function generated. Does your design meet the specifications? Using MATLAB, compute and plot the filters unwrapped phase response and the group delay response. % Program P7_1 % Design of a Type 2 Chebyshev highpass Digital Filter Ws = [0.4]; Wp = [0.7]; Rp = 0.4; Rs = 50; % Estimate the Filter Order [N1, Wn1] = cheb2ord(Wp, Ws, Rp, Rs); % Design the Filter [num,den] = cheby2(N1,40,Wn1,'high'); % Display the transfer function disp('Numerator coefficients are ');disp(num); disp('Denominator coefficients are ');disp(den); % Compute the gain response [g,w] = gain(num,den); % Plot the gain response plot(w/pi,g);grid; axis([0 1 -60 5]); xlabel('\omega /\pi'); ylabel('Gain, dB'); title('Gain Response of a Chebyshev II highpass Filter'); tf(num,den) grpdelay(num,den) % respuesta en fase. plot(w/pi,unwrap(angle(g))); Numerator coefficients are 0.0890 -0.2749 0.4509 Denominator coefficients are 1.0000 0.2047 0.7543 La ganancia es: -0.4509 0.0152 0.2749 0.0912 -0.0890 -0.0038

the unwrapped phase response and the group delay response are:

Q7.8 Modify Program P7 1 to design an elliptic bandpass filter meeting the specifications given in Question Q7.3. Write down the exact expression for the transfer function generated. Does your design meet the specifications? Using MATLAB, compute and plot the filters unwrapped phase response and the group delay response. Ws = [0.4 0.6]; Wp = [0.3 0.7]; Rp = 0.4; Rs = 50; % Estimate the Filter Order [N1, Wn1] = ellipord(Wp,Ws, Rp, Rs); % Design the Filter [num,den] = ellip(N1,.5,40, Wn1); % Display the transfer function disp('Numerator coefficients are ');disp(num); disp('Denominator coefficients are ');disp(den); % Compute the gain response [g,w] = gain(num,den); % Plot the gain response plot(w/pi,g);grid; axis([0 1 -60 5]); xlabel('\omega /\pi'); ylabel('Gain, dB'); title('Gain Response of a elliptic bandpass Filter'); tf(num,den) grpdelay(num,den) % respuesta en fase. plot(w/pi,unwrap(angle(g))); Numerator coefficients are 0.0689 0.0000 -0.1381 -0.0000 0.1864 0.0000 -0.0000 0.0689 Denominator coefficients are 1.0000 -0.0000 1.3061 0.0000 0.2361 0.0000 1.4830 0.0000

-0.1381

0.7771

the gain response is:

the unwrapped phase response and the group delay response are:

Project 7.5 FIR Filter Design Q7.20 Using the function fir1, design a linear-phase FIR lowpass filter meeting the specifications given in Question Q7.13 and plot its gain and phase responses. Use the order estimated using Kaisers formula in Question Q7.13. Show the filter coefficients in a tabular form. Does your design meet the specifications? If it does not, adjust the filter order until the design meets the specifications. What is the order of the filter meeting the specifications?

Las especificacin son: n = 54 Wn = 0.4500 beta = 4.0909 ftype = low hh = Columns 1 through 9 0.0004 -0.0011 -0.0012 Columns 10 through 18 0.0023 -0.0077 -0.0059 Columns 19 through 27 0.0045 -0.0323 -0.0183 Columns 28 through 36 0.4500 0.3136 0.0487 -0.0925 -0.0450 0.0423 0.0393 -0.0183 -0.0323 0.0393 0.0423 -0.0450 -0.0925 0.0487 0.3136 0.0083 0.0111 -0.0072 -0.0175 0.0033 0.0248 0.0013 0.0025 -0.0011 -0.0043 0.0000 0.0061

Columns 37 through 45 0.0045 0.0248 0.0033 -0.0175 -0.0072 0.0111 0.0083 -0.0059 -0.0077

Columns 46 through 54 0.0023 0.0061 0.0000 -0.0043 -0.0011 0.0025 0.0013 -0.0012 -0.0011

Column 55 0.0004

50 Magnitude (dB) 0 -50 -100 -150

0.1

0.2

0.3 0.4 0.5 0.6 0.7 0.8 Normalized Frequency ( rad/sample)

0.9

0 Phase (degrees)

-1000

-2000

-3000

0.1

0.2

0.3 0.4 0.5 0.6 0.7 0.8 Normalized Frequency ( rad/sample)

0.9

2 0

2 0

4 0

6 0

8 0

1 0 0

5 0

1 0 0

1 5 0

2 0 0

2 5 0

3 0 0

Q7.23 Design an FIR lowpass filter using a Kaiser window. The filter specifications are: p = 0.3, s 0.4, and As = 50 dB. Note that the function kaiser requires the values of the parameter and the order N which must first be calculated using Eqs. (7.36) and (7.37), respectively. Does your design meet the specifications? Wn = [0.3 0.4]; df = 0.4 - 0.3; A = 50; if (A > 50) beta = 0.1112*(A - 8.7) else if (A < 21) beta = 0 else

end end

beta = (0.5842*(A - 21)^0.4) + 0.07880*(A - 21)

if (A > 21) N = (A - 7.95)/(14.36*df) + 1 else N = (0.9222/df) + 1 end L = real (ceil(N)) w = kaiser(L+1,beta); b = fir1(L,Wn,w) wvtool(w) freqz(b) w = 0:pi/255:pi; h = freqz(b,1,w); g = 20*log10(abs(h)); plot(g) The coefficients of the lowpass filter corresponding to the specifications given in Question 7.23 are as shown below

b= Columns 1 through 12 -0.0005 -0.0042 -0.0052 0.0050 0.0200 0.0150 -0.0204 -0.0507 -0.0244 0.0501 0.0880 0.0241 Columns 13 through 24 -0.0868 -0.1138 -0.0102 0.1132 0.1132 -0.0102 -0.1138 -0.0868 0.0241 0.0880 0.0501 -0.0244 Columns 25 through 32 -0.0507 -0.0204 0.0150 0.0200 0.0050 -0.0052 -0.0042 -0.0005
The generated gain and phase responses are given below:

Time domain 40 1 20 0.8 Magnitude (dB) 0 Amplitude

Frequency domain

0.6

-20 -40

0.4

0.2

-60

-80 5 10 15 20 Samples 25 30

0.2 0.4 0.6 0.8 Normalized Frequency ( rad/sample)

-50

-100

-150

-200

-250

-300

-350

50

100

150

200

250

300

Q7.24 Repeat Question Q7.23 using the functions kaiserord and fir1. fsamp = 10000; fcuts = [3000 4000]; mags = [1 0]; devs = [0.005 0.005]; [n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp) hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale') freqz(hh) w = 0:pi/255:pi; h = freqz(hh,1,w); g = 20*log10(abs(h)); pause plot(g)

The coefficients of the lowpass filter corresponding to the specifications given in Question 7.23 are as shown below

hh = Columns 1 through 12 -0.0019 0.0025 0.0009 -0.0077 0.0111 -0.0027 -0.0167 0.0314 -0.0194 -0.0262 0.0796 -0.0847 Columns 13 through 24 -0.0325 0.5659 0.5659 -0.0325 -0.0847 0.0796 -0.0262 -0.0194 0.0314 -0.0167 -0.0027 0.0111 Columns 25 through 28 -0.0077 0.0009 0.0025 -0.0019
M g itu e ( B a n d d ) 5 0

-0 5

-0 1 0

0 . 1

0 . 2

0 . 3 0 . 4 N aeF uc ( o lz rqn r i d eey m

0 . 5

0 . 6

0 . 7

0 . 8

0 . 9

/ m e rdap) as l

P a e( e r e ) h s d ge s

0 -0 5 0 -0 10 0 -5 10 0 -0 20 0

0 . 1

0 . 2

0 . 3 0 . 4 N aeF uc ( o lz rqn r i d eey m

0 . 5

0 . 6

0 . 7

0 . 8

0 . 9

/ m e rdap) as l

5 0 0 5 0 1 0 0 1 5 0 2 0 0 2 5 0 3 0 0 3 5 0

5 0

1 0 0

1 5 0

2 0 0

2 5 0

3 0 0

Q7.25 Using fir2 design an FIR filter of order 95 with three different constant magnitude levels: 0.4 in the frequency range 0 to 0.25, 1.0 in the frequency range 0.3 to 0.45, and 0.8

in the frequency range 0.5 to 1.0. Plot the magnitude response of the filter designed. Does your design meet the specifications? N = 30; f = [0 0.25 0.3 0.45 0.5 1]; m = [0.4 0.4 1 1 0.8 0.8]; b = fir2(N,f,m); [h,w] = freqz(b,1,128); plot(f,m,w/pi,abs(h)) legend('Ideal','fir2 Designed') title('Comparison of Frequency Response Magnitudes') The magnitude response of the filter designed for the specifications given in Question Q7.25 is shown below:
C nqR M ooe e a s mFcp g poe s n af u o id r rn n t i s y s u e e 1 Il d e a fD ie rs 2n ie g d

0 . 9

0 . 8

0 . 7

0 . 6

0 . 5

0 . 4

0 . 1

0 . 2

0 . 3

0 . 4

0 . 5

0 . 6

0 . 7

0 . 8

0 . 9

You might also like