%
% Digital Chebyshev lowpass design
%
% Analog specs
wpha=100; wsha=200; Gp=-2; Gs=-25;
T = 1/(2*600*pi);

% Step 1: prewarp pass and stop frequencies
wph=(2/T)*tan(wpha*T*0.5);
wsh=(2/T)*tan(wsha*T*0.5);

% Step 2: determine n
r=-Gp;
P1=-Gs/10; P2=r/10; Wsp=wsh/wph;
nc=acosh( sqrt( (10^P1-1)/(10^P2-1) ) )/(acosh(Wsp));
n= ceil(nc);
fprintf('Filter order is %i\n', n)

% Step 3: determine transfer function of analog prototype low pass
[num1, den1] = cheby1(n, r, wph, 's');

% Display prototype low pass transfer function
disp('The prototype lowpass transfer function is')
format short e
num1, den1

% Step 4 transform to digital
[numd1, dend1] = bilinear(num1, den1, 1/T);

%  Now display final filter transfer function
disp('The final transfer function is')
numd1, dend1
format
