%% Discrete-Time Representation of an Elliptic Filter
% Design a 6th-order elliptic analog lowpass filter with 3 dB of ripple in the passband and a stopband 90 dB down. Set cutoff frequency f_c =20\;\textrm{Hz} and sample rate f_s =200\;\textrm{Hz}.

clear
Fc = 20;
Fs = 200;                             
[z,p,k] = ellip(6,3,90,2*pi*Fc,'s');
[num,den] = zp2tf(z,p,k);

% Calculate the magnitude response of the analog elliptic filter. Visualize the analog filter.

[h,w] = freqs(num,den);
plot(w/(2*pi),mag2db(abs(h)))
hold on
xlim([0 50])
[l1,l2] = meshgrid(Fc,[-120 0]);
plot(l1,l2)
grid
legend('Magnitude response','Passband Edge')
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')

% Use bilinear to transform it to a discrete-time IIR filter. Set the match frequency as f_p =20\;\textrm{Hz}.

[numd,dend] = bilinear(num,den,Fs,20);

%
% Visualize the filter using fvtool.

fvtool(numd,dend,'Fs',Fs)                     

% Copyright 2015 The MathWorks, Inc.