EXP.NO:05 Iir Filter Date:: s p 0.1αs 0.1αp
EXP.NO:05 Iir Filter Date:: s p 0.1αs 0.1αp
DATE:
AIM:
To write a matlab program to design a IIR filter in analog and digital form and to plot its
response.
SOFTWARE REQUIRED:
MATLAB Simulator
THEORY:
Filters are used in digital signal processing to remove undesirable parts of the signal, such as
random noise, or to extract useful parts of the signal, such as the parts of the signal
belonging to a particular range. Digital filters can be classified into two groups, FIR (finite-
duration impulse response) and IIR (infinite-duration impulse response) filters.
IIR FILTER:
The infinite impulse response filter is a recursive filter.It consists of feedback.It is of two
types.They are butterworth filter and chebyshev filter.
The design of butterworth filter involves various steps starting from deciding the order of
the filter.The order of the filter is given by ,
ε = √ ( 100.1αp -1)
The order is rounded off to the next higher integer.Then the transfer function is found for
the value of ‘N’.The cut-off frequency is found by,
Ωc = Ωp / ( 100.1αp -1)^(1/2N)
The magnitude function of the butterworth lowpass filter is given by,
|H(jΩ)| = 1/(1+(Ω/Ωc)^2N)^(1/2)
For a low pass butterworth filter Ha(s)=H(s) for s = s / Ωc
For a high pass butterworth filter Ha(s)=H(s) for s = Ωc /s
The chebyshev filter is used to separate one band of frequencies from another.They may be
analog or digital filter. They have either passband ripple (type I) or stopband ripple (type II).
Chebyshev filters have the property that they minimize the error between the idealized and
the actual filter characteristic over the range of the filter.
The design of chebyshev filter involves various steps starting from deciding the order of
the filter.The order of the filter is given by ,
N >= cosh-1 ( λ / ε ) / cosh-1 ( Ωs / Ωp )
where , λ = √ ( 100.1αs -1)
ε = √ ( 100.1αp -1)
The major and minor axis is also found and the digital chebyshev filter is designed using
either impulse invariant method or bilinear transformation.
PROGRAM:
clc;
close all;
clear all;
Ap=input("passband attenuation");
As=input("stopband attenuation");
Wp=input("passband freq");
Ws=input("stopband freq");
fs=input('sampling frequency');
N = log10(sqrt(((power(10,0.1*As)-1))/(power(10,0.1*Ap)-1)))/log10(Ws/Wp);
X=round(N);
if(N>X)
n=X+1;
end
n=X;
Wc=Wp/power((power(10,(0.1*Ap))-1),1/(2*n));
H=[];
X=[];
num=1;
for f=1:10
t=1;
s=2*pi*f*t;
s=s/Wc;
if(n==1)
H(f)=(s+1);
elseif(n==2)
H(f)=(power(s,2)+sqrt(2)*s+1);
elseif(n==3)
H(f)=((s+1)*(power(s,2)+s+1));
else
H(f)=((power(s,2)+0.76*s+1)*(power(s,2)+1.84*s+1));
end
X(f)=1/H(f);
end
figure(1);
plot(abs(X));
xlabel("W");
ylabel("|H(js)|");
title("Lowpass filter");
figure(2);
zplane(1./H);
[numd,dend] = bilinear(num,H,fs);
figure(3);
freqs(numd,dend);
[zz,pp,kk]=tf2zp(numd,dend);
figure(4);
zplane(zz,pp);
title("Z domain")
%hpf
N = log10(sqrt(((power(10,0.1*As)-1))/(power(10,0.1*Ap)-1)))/log10(Ws/Wp);
X=round(N);
if(N>X)
n=X+1;
end
n=X;
Wc=Wp/power((power(10,(0.1*Ap))-1),1/(2*n));
H1=[];
X1=[];
num=1;
for f=1:10
t=1;
s=2*pi*f*t;
s=Wc/s;
if(n==1)
H1(f)=(s+1);
elseif(n==2)
H1(f)=(power(s,2)+sqrt(2)*s+1);
elseif(n==3)
H1(f)=((s+1)*(power(s,2)+s+1));
else
H1(f)=((power(s,2)+0.76*s+1)*(power(s,2)+1.84*s+1));
end
X1(f)=1/H1(f);
end
figure(5);
plot(abs(X1));
xlabel("W");
ylabel("|H(s)|");
title("Highpass filter");
figure(6);
zplane(1./H1);
[numd,dend] = bilinear(num,H1,fs);
[zz,pp,kk]=tf2zp(numd,dend);
figure(7);
freqs(numd,dend);
figure(8);
zplane(zz,pp);
title("Z domain");
%chebyshev
N2 = acos(sqrt(((power(10,0.1*As)-1))/(power(10,0.1*Ap)-1)))/log10(Ws/Wp);
X=round(N);
if(N>X)
n=X+1;
end
n=X;
epsi=sqrt(power(10,0.1*Ap)-1);
meu=(1/eps)+sqrt((1/eps*eps)+1);
%minoraxis
a=(Wp/2)*(power(meu,(1/n))-(power(meu,-1/n)));
%majoraxis
b=(Wp/2)*(power(meu,(1/n))+(power(meu,-1/n)));
p=[];
z=1;
for i=1:n
ok=(pi/2)+((2*i)-1)*(pi/(2*N));
p(i)=a*cos(ok)+1i*b*sin(ok);
end
for i=1:n
z=p(i)*z;
end
z=-1*z;
[num,den] = zp2tf(z,p,1);
figure(9);
freqs(num,den)
figure(10);
zplane(z,p);
LOWPASS FILTER:
BUTTERWORTH FILTER:
HIGH PASS FILTER:
Pole-Zero Plot
Rea I Part
-°0
-140
-180
Frequency (rad s)
Rea I Part
200
% 00
-/ 00
Frequency (rad's)
Presentation Uniqueness Punctuality Viva Total
RESULT:
Thus the matlab program to design IIR filter was done and its response was
plotted.