% Chebyshev (0.5 dB) filters
freq = 10.^(-3:0.001:3);

% Begin with a clean graphical slate...
for fig=1:6 %bodeplot creates 6 figures.
   figure(fig)
   hold off
endfor


% 2-pole Chebyshev
Q = [0.864];
fn = [1.231];
Chebyshev2 = multistage(freq, Q, fn);
bodeplot(freq, Chebyshev2, 'r')

% 4-pole Chebyshev
Q = [0.705, 2.941];
fn = [0.597, 1.031];
Chebyshev4 = multistage(freq, Q, fn);
bodeplot(freq, Chebyshev4, 'g')

% 6-pole Chebyshev
Q = [0.684, 1.812, 6.494];
fn = [0.396, 0.768, 1.011];
Chebyshev6 = multistage(freq, Q, fn);
bodeplot(freq, Chebyshev6, 'b')

% 8-pole Chebyshev
Q = [0.677, 1.610, 3.640, 11.494];
fn = [0.297, 0.599, 0.861, 1.006];
Chebyshev8 = multistage(freq, Q, fn);
bodeplot(freq, Chebyshev8, 'm')

legendtext=['2-pole';'4-pole';'6-pole';...
   '8-pole'];

figure(1)
title('Gain of Chebyshev (0.5 dB) filters','fontsize',18)
xlabel('Frequency (Hz)','fontsize',16)
ylabel('Gain (dB)','fontsize',16)
legend(legendtext)
axis([0.01,1000,-160,2])
print('ChebyshevGain.pdf')
axis([0.1,10,-20,5])
print('ChebyshevGainZoom.pdf')

figure(2)
title('Phase of Chebyshev (0.5 dB) filters','fontsize',18)
xlabel('Frequency (Hz)','fontsize',16)
ylabel('Phase (degrees)','fontsize',16)
legend(legendtext)
print('ChebyshevPhase.pdf')

figure(3)
title('Time delay of Chebyshev (0.5 dB) filters','fontsize',18)
xlabel('Frequency (Hz)','fontsize',16)
ylabel('Time delay (fc = 1)','fontsize',16)
legend(legendtext)
print('ChebyshevTimeDelay.pdf')

figure(4)
title('Time delay vs. attenuation of Chebyshev (0.5 dB) filters','fontsize',18)
xlabel('Attenuation (dB)','fontsize',16)
ylabel('Time delay (s)','fontsize',16)
legend(legendtext)
axis([-3,10])
print('ChebyshevTimeDelay-Attenuation.pdf')

figure(5)
title('Step response of Chebyshev (0.5 dB) filters','fontsize',18)
xlabel('Time (s)','fontsize',16)
ylabel('Response','fontsize',16)
legend(legendtext)
axis([-6,16])
print('ChebyshevStepResponse.pdf')

figure(6)
title('Impulse response of Chebyshev (0.5 dB) filters','fontsize',18)
xlabel('Time (s)','fontsize',16)
ylabel('Response','fontsize',16)
legend(legendtext)
axis([-6,16])
print('ChebyshevImpulseResponse.pdf')
