You are on page 1of 2

# clc; clear all; close all; %Taking the inputs from the user fp1=input('Enter the lower passband

edge frequency:'); fs1=input('Enter the lower stopband edge frequency:'); fs2=input('Enter the upper stopband edge frequency:'); fp2=input('Enter the upper passband edge frequency:'); rp=input('Enter the passband ripple:'); rs=input('Enter the minimum stopband attenuation:'); f=input('Enter the sampling frequency:'); %Calculating Prewarp frequencies pwp1=tan(2*pi*fp1/(2*f)); pws1=tan(2*pi*fs1/(2*f)); pws2=tan(2*pi*fs2/(2*f)); pwp2=tan(2*pi*fp2/(2*f)); %center frequency wo=sqrt(pwp1*pwp2); %Bandwidth W=pwp2-pwp1; %Calculating frequencies for Analog Prototype filter wp1=(W*pwp1)/((wo^2)-(pwp1^2)); ws1=(W*pws1)/((wo^2)-(pws1^2)); ws2=(W*pws2)/((wo^2)-(pws2^2)); wp2=(W*pwp2)/((wo^2)-(pwp2^2)); pws=min(abs(ws1),abs(ws2)); pwp=wp1; % or pwp=abs(wp2); fb=pws/pwp; %Calculating the order of the Analog prototype filter N=ellipord(pwp,pws,rp,rs,'s'); %Designing the Analog prototype filter of cutoff frequency 1 rad/sec [z,p,k]=ellipap(N,rp,rs); [b,a]=zp2tf(z,p,k); %instead of above two statements we can also use %[b,a]=ellip(N,rp,rs,1,'s'); %Frequency Transformation in s-domain [bt,at] = lp2bs(b,a,wo,W); %Converting the digital using bilinear transformation method [num,den] = bilinear(bt,at,fb); %Frequency Response [h,w]=freqz(num,den); %Magnitude response in dB m=20*log10(abs(h)); %Plotting the absolute magnitude response subplot(2,1,1);

plot(w/pi,abs(h)); xlabel('Normalized Frequency--->'); ylabel('Absolute Magnitude Response--->') title('Digital Elliptic IIR Bandstop Filter'); %Plotting the Magnitude response in dB subplot(2,1,2); plot(w/pi,m); xlabel('Normalized Frequency--->'); ylabel('Gain in dB--->') INPUTS: Enter the Enter the Enter the Enter the Enter the Enter the Enter the

lower passband edge frequency:15 kHz lower stopband edge frequency:20 kHz upper stopband edge frequency:25 kHz upper passband edge frequency:30 kHz passband ripple:0.2 dB minimum stopband attenuation:40 dB sampling frequency:100 kHz