PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

Analog and Digital Filters 623


MATLAB Solution
% Script file: butt _ chev
Rp = 1 ; % in db (passband ripple)
Rs = 1 ; % in db (stopband ripple)
Wp = 1 ; % pass band edge
% Butterworth LPF.
n = 5; % order
% transfer function, But. LPF.
[num1, den1] = butter (n, Wp, ‘s’);
% plot the frequency response Butterworth. LPF
w = [0:.1: 5];
h1 = freqs (num1, den1, w);
gain1 = 20 * log10 (abs (h1));
figure(1);
subplot(1,3,1);
plot(w,gain1);axis([0 5 -80 20]);
title (‘Butterworth LPF, N = 5’)
xlabel (‘ frequency w (rad/sec)’)
ylabel (‘gain, db’)
% Chebyshev LPF, type 1
[num2, den2] = Cheby1 ( n, Rp, Wp, ‘s’);
% plot the frequency response, Chebyshev 1 LPF
h2 = freqs (num2,den2,w);
gain2 = 20 * log10 (abs(h2));
subplot (1, 3, 2);
plot (w, gain2);
title (‘ Chebyshev 1 LPF, N=5’); axis([0 5 -100 20]);
xlabel (‘frequency w (rad/sec)’);
ylabel (‘gain, db’)
% Chebyshev LPF, type 2.
Wn = 1;% cut off norm. freq.
[num3, den3] = Cheby2 (n, Rs, Wn, ‘s’);
h3 = freqs (num3, den3, w);
gain3 = 20 * log10 (abs(h3));
subplot (1, 3, 3);
plot (w, gain3);
title (‘Chebyshev 2 LPF, N=5’);axis([0 2 -50 10]);
xlabel (‘ frequency w (rad/sec)’);
ylabel (‘gain, db’)
figure(2) % Butterworth phase
phase1=angle(h1);
subplot(1,3,1);
plot(w,phase1);axis([0 3 -4 4]);
xlabel (‘freq w(rad/sec)’);
ylabel(‘phase in rad’);
title(‘Butterworth, phase plot’)
% Chebyshev1 phase
phase2=angle(h2);
subplot(1,3,2)
plot(w,phase2);axis([0 2 -4 4]);
xlabel(‘freq w(rad/sec)’);
ylabel(‘phase in rad’);
title(‘Chebyshev 1, phase plot ‘)
% Chebyshev2 phase
Free download pdf