IIR Filter Using Butterworth Filter Approximation
IIR Filter Using Butterworth Filter Approximation
IIR Filter Using Butterworth Filter Approximation
Aim:
To write a MATLAB program for IIR filter using Butterworth approximation.
Pre-Lab Questions:
Algorithm:
1. Start the program.
2. Get pass band ripple and stop band ripple.
3. Get Pass band and stop band frequency.
4. Calculate the order of the filter.
5. Plot the band pass and band stop filter.
Program:
clc;
clear all;
close all;
rp=input('Enter passband ripple rp=');
rs=input('Enter stopband ripple rs=');
wp=input('Enter passband frequency fp=');
ws=input('Enter stopband frequency fs=');
f=input('Enter the sampling frequency f=');
w1=2*wp/f;
w2=2*ws/f;
%LPF
[n,wn]=buttord(w1,w2,rp,rs,'s');
[b,a]=butter(n,wn,'low','s');
w=0:0.1:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
wn=angle(h);
subplot(4,2,1);
plot(om/pi,m);
title('Magnitude response of LPF');
xlabel('Normalized frequency');
ylabel('Gain in dB');
subplot(4,2,2);
plot(om/pi,wn);
title('Phase response of LPF');
xlabel('Normalized frequency');
ylabel('Phase in radians');
%HPF
[n,wn]=buttord(w1,w2,rp,rs,'s');
[b,a]=butter(n,wn,'high','s');
w=0:0.1:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
wn=angle(h);
subplot(4,2,3);
plot(om/pi,m);
title('Magnitude response of HPF');
xlabel('Normalized frequency');
ylabel('Gain in dB');
subplot(4,2,4);
plot(om/pi,wn);
title('Phase response of HPF');
xlabel('Normalized frequency');
ylabel('Phase in radians');
Theory:
1
c
Where N is the order of the filter and is the cutoff frequency. The magnitude response of
the Butterworth filter closely approximates the ideal response as the order N increases.
The phase response response becomes more non-linear as N increases.
The order of the filter
100.1 s 1
log 0.1 p
N 10 1
s
log
p
Where αs= stopband attenuation at stopband frequency Ωs
αp= passband attenuation at passband frequency Ωp
p
c 1
0.1
(10 p
1) 2 N
Procedure:
%BSF
wn=[w1 w2];
[b,a]=butter(n,wn,'stop','s');
w=0:0.1:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
wn=angle(h);
subplot(4,2,7);
plot(om/pi,m);
title('Magnitude response of BSF');
xlabel('Normalized frequency');
ylabel('Gain in dB');
subplot(4,2,8);
plot(om/pi,wn);
title('Phase response of BSF');
xlabel('Normalized frequency');
ylabel('Phase in radians');
Output:
Enter the pass band ripple10
Enter the stop band ripple30
Enter the pass band frequency [0.2 0.8]
Enter the stop band frequency [0.4 0.7]
Post-Lab Questions:
Aim:
To write a MATLAB program for IIR filter using Chebyshev approximation.
Pre-Lab Questions:
2. The magnitude response of the chebyshev filter exhibits _____in passband and stop band.
a)ripple b)linear c)none d) nonlinear
3. Chebyshev filter poles are close to jΩ axis than those in butterworth filter
a)true b)false c)none d) lie on origin
Algorithm:
1. Start the program.
2. Get pass band ripple and stop band ripple.
3. Get Pass band and stop band frequency.
4. Calculate the order of the filter.
5. Plot the band pass and band stop filter.
Program:
%LPF
clc;
clear all;
close all;
format long rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
wp=input('enter the pass band frequency');
ws=input('enter the stop band frequency');
fs=input('enter the sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
wn=[w1,w2];
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'low');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(4,2,1);
plot(om/pi,m);
ylabel('gain in db--->');
xlabel('freq');
title('magnitude response');
subplot(4,2,2);
plot(om/pi,an);
ylabel('gain in db--->');
xlabel('angle');
title('phase response');
%HPF
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(4,2,3);
plot(om/pi,m);
ylabel('gain in db--->');
xlabel('freq');
title('magnitude response');
subplot(4,2,4);
plot(om/pi,an);
ylabel('gain in db--->');
xlabel('angle'); title('phase response');
Theory:
The transfer function of Chebyshev filter is given by
1
H (j )
2
1
1 j C
N
p
Where ε is a parameter of the filter related to the ripple in the passband and CN(x) is the
Nth order Chebyshev polynomial defined as
C N (x) cos(Ncos 1x) for x 1
C N (x) cosh(Ncos h x) for x 1
The order N of Chebyshev filter is given by,
100.1 s 1
cosh 1 0.1
N 10 p 1
cosh 1 s
p
p
Where s is stop band attenuation at stop band frequency s and is pass band
p
attenuation at pass band frequency . The major and minor axes of the ellipse are given
by
Where 1
1 2
0.1
And 10 1
p
Procedure:
%BSF
[n,wn]=cheb1ord(w1,w2,rp,rs);
wn=[w1,w2];
[b,a]=cheby1(n,rp,wn,'stop');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(4,2,7);
plot(om/pi,m);
ylabel('gain in db--->');
xlabel('freq');
title('magnitude response');
subplot(4,2,8);
plot(om/pi,an);
ylabel('gain in db--->');
xlabel('angle');
title('phase response');
Output:
Enter the pass band ripple 0.4
Enter the stop band ripple 50
Enter the pass band frequency 1200
Enter the stop band frequency 2200
Enter the sampling frequency 6000
Post-Lab Questions:
5. What is the number of minima present in the pass band of magnitude frequency response
of chebyshev-I filter of order 4?
a)1 b) 2 c)3 d) 4