% Figure 8.38
%
%  Compares the Butterworth and Chebyshev filters
%
w = 0:.01:8;
fprintf('Butterworth filter: \n')
[z,p,k] = buttap(3);      
[b,a]=zp2tf(z,p,k);
Wo=2;  % change cutoff frequency to 2 rad/s
[b,a] = lp2lp(b,a,Wo)
disp('b = ');disp(b');
disp('a = ');disp(a');
[magb,phaseb] = bode(b,a,w);
%
fprintf('Chebyshev filter: \n')
[z,p,k] = cheb1ap(3,3); 
b=poly(z)*k;          
a=poly(p);
[b,a] = lp2lp(b,a,Wo)
disp('b = ');disp(b');
disp('a = ');disp(a');
[magc,phasec] = bode(b,a,w);
%
subplot(211)
p71=1/sqrt(2);
H=plot(w,magb,'-',w,magc,'-.',[0 2],[p71 p71],'--',...
[2 2],[0 p71],'--',[3 3.7],[1.1 1.1],...
[3 3.7],[0.75 0.75],'y-.');
ylabel('       |H|')
h=text(-1.2,p71,'0.707');
h=[h; text(3.8,1.1,'Three-pole Butterworth')];
h=[h; text(3.8,0.75,'Three-pole Chebyshev')];
h=[h; text(0.5,0.15,'Passband')];
pubplot
%
subplot(212)
H=plot(w,phaseb,'-',w,phasec,'-.');
ylabel('Phase (deg)')
xlabel('Frequency (rad/sec)')
pubplot
subplot(111)
