%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This Function will take in parameters       %
%Apply prewarping apply the bi-linear        %
%transformation and plot the magnitude       %
%response of the digital filter              %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function [b,a,w,Hm,Hma,n,Wc,B,A] = iir_filter_stop(wp,ws,ap,as,T)

%Inputs
%wp=digital passband     
%ws=digital stop band
%ap=passband attenuation  in db
%as=stopband attenuation  in db

%Values before Pre - Warp
%Bandstop:   wp = [.1*pi .8*pi], ws = [.2*pi .7*pi]


Wp=(2/T)*tan(wp/2);   %Pre-Warp
Ws=(2/T)*tan(ws/2);

%create an analog Elliptic Approximation

%Values after Pre - Warp
%Bandstop:   Wp = [.1 .8], Ws = [.2 .7]

[n,Wc]=ellipord(Wp,Ws,ap,as,'s');
[B,A]=ellip(n,ap,as,Wc,'stop','s');

%Bilinear Transformation on Analog Filter
[b,a]=bilinear(B,A,1/T);

%Frequency Response of Digital Filter
w=[0:pi/1023:pi]';
H=freqz(b,a,w);
Hm=abs(H);
Hma=-20*log10(Hm);

%Plot
figure,plot(w/pi,Hma),axis([0,1,0,50]),title('Attenuation'),xlabel('Normalized Frequency x*pi(rad/s)'),ylabel('Attenuation in db');
