%LOW PASS BUTTERWORTH FILTER
clc;clear;
wp=0.25*pi;
ws=0.55*pi;
ap=0.5;
as=15;
T=1;
op=(2/T)*tan(wp/2);
os=(2/T)*tan(ws/2);
[N,oc]=buttord(op,os,ap,as,'s');
disp(N);
oc=op/(10^(0.1*ap)-1)^(1/(2*N));
disp(oc);
[b,a]=butter(N,oc,'s');
tf(b,a)
%convert H(s) to H(z)--> use bilinear transform
[bz,az]=bilinear(b,a,1/T);
tf(bz,az,-1,'variable','z^-1')
[H W]=freqz(bz,az);
plot(W/pi,mag2db(abs(H)));%convert magnitude to decimal
ylim([-30 5]);
grid on;
title('Low Pass Butterworth Filter');
xlabel('Normalized Frequency (xpi rad/sample)');
ylabel('Gain (dB)');

%%LOW PASS CHEBYSHEV FILTER
clc;clear;
wp=0.25*pi;
ws=0.55*pi;
ap=1;
as=15;
T=1;
op=(2/T)*tan(wp/2);
os=(2/T)*tan(ws/2);
[N,oc]=cheb1ord(op,os,ap,as,'s');
disp(N);
oc=op/(10^(0.1*ap)-1)^(1/(2*N));
disp(oc);
[b,a]=cheby1(N,ap,op,'s');
tf(b,a)
[bz,az]=bilinear(b,a,1/T);
tf(bz,az,-1,'variable','z^-1')
[H W]=freqz(bz,az);
plot(W/pi,mag2db(abs(H)));
ylim([-30 5]);
grid on;
title('Chebysev Filter');
xlabel('Normalized Frequency (xpi rad/sample)');
ylabel('Gain (dB)');