You are on page 1of 7

IIR BUTTERWORTH FILTER DESIGN

Aim: To design an IIR BW:


(i)

LPF with p=0.3dB, s=30dB, fp=400Hz, fs=800Hz and sampling


frequency=2000Hz

(ii)

HPF with p=0.3dB, s=30dB, fp=800Hz, fs=400Hz and


sampling frequency=2000Hz

(iii)

BPF with p=0.2dB, s=20dB, wp1=0.5pi, wp2=0.8pi,


ws1=0.4pi, ws2=0.9pi

(iv)

BRF with p=0.2dB, s=20dB, wp1=0.4pi, wp2=0.9pi,


ws1=0.5pi, ws2=0.8pi

Algorithm:
1. For Butterworth LPF & HPF, input PB & SB attenuations, PB & SB
frequencies and sampling frequencies.
2. Normalize PB & SB frequencies.
3. Find the order, cut-off frequency and transfer function of the filter
using the corresponding equations.
4. Define the frequency range and find the frequency response.
5. Plot the magnitude and phase responses.
6. For Butterworth BPF & BRF, input PB & SB attenuations, PB & SB
edge frequencies.
7. Repeat steps 2-5.
Command window

BW LPF and HPF


Enter pb attn in dB: 0.3
Enter sb attn in dB: 30
Enter pb freq in Hz: 400
Enter sb freq in Hz: 800
Enter sampling freq in Hz: 2000

BW BPF and BRF


Enter pb attn in dB: 0.2
Enter sb attn in dB: 20
Enter pb edge1 and edge2 freq : [0.5*pi,0.8*pi]
Enter sb edge1 and edge2 freq : [0.4*pi,0.9*pi]
PROGRAM -HINTS
clc;
clear all;
close all;
disp('BW LPF and HPF');
%BW LPF
ap=input('Enter pb attn in dB: ');
as=input('Enter sb attn in dB: ');
fp=input('Enter pb freq in Hz: ');
fs=input('Enter sb freq in Hz: ');
f=input('Enter sampling freq in Hz: ');

wp=(2*fp)/f;
ws=(2*fs)/f;

inputs

angular frequency

[N,wc]=buttord(wp,ws,ap,as); %Using buttord fn ,find out filter order and


normalized cut off
frequency ,wc.
[b,a]=butter(N,wc);
%find out filter coefficients b and a.
w=0:0.01:pi;
% define range of angular frequency
h=freqz(b,a,w);
% freqz(b,a,n) returns the n-point
frequency response vector, h, and the corresponding angular frequency
vector, w, for the digital filter with numerator and denominator polynomial
coefficients stored in b and a, respectively
m=20*log10(abs(h)); %find magnitude
p=angle(h);
%find angle
subplot(2,1,1);
plot(w/pi,m);
grid on;
title('mag resp of IIR BW LPF');
xlabel('normalised frequency');
ylabel('magnitude(dB)');
%plot magnitude and phase
response
subplot(2,1,2);

plot(w/pi,p);
grid on;
title('phase resp of IIR BW LPF');
xlabel('normalised frequency');
ylabel('phase');

%BW HPF
[b,a]=butter(N,wc,'high');
..
..
Follow similar steps in LPF

disp('BW BPF and BRF');


%BW BPF
ap=input('Enter pb attn in dB: ');
as=input('Enter sb attn in dB: ');
wp=input('Enter pb edge1 and edge2 freq : '); %Enter in radian
ws=input('Enter sb edge1 and edge2 freq : ');
%Enter in radian
[N,wc]=buttord(wp/pi,ws/pi,ap,as);
..
..
Follow similar steps in LPF

%BW BRF
[b,a]=butter(N,wc,'stop');
..
..
Follow similar steps in LPF

IIR CHEBYSHEV FILTER DESIGN


Aim: To design an IIR Chebyshev I and II:
(i)

LPF with p=1dB, s=15dB, wp=0.2pi rad, ws=0.3pi rad

(ii)

HPF with p=1dB, s=15dB, wp=0.3pi rad, ws=0.2pi rad

(iii)

BPF with p=2dB, s=20dB, wp1=0.2pi, wp2=0.4pi, ws1=0.1pi,


ws2=0.5pi

(iv)

BRF with p=2dB, s=20dB, wp1=0.1pi, wp2=0.5pi, ws1=0.2pi,


ws2=0.4pi

Algorithm:
1. For Chebyshev 1 & 2 LPF & HPF, input PB & SB attenuations, PB &
SB frequencies.
2. Normalize PB & SB frequencies.
3. Find the order, cut-off frequency and transfer function of the filter
using the corresponding equations.
4. Define the frequency range and find the frequency response.
5. Plot the magnitude and phase responses.
6. For Chebyshev 1 & 2 BPF & BRF, input PB & SB attenuations, PB &
SB edge frequencies.
7. Repeat steps 2-5.
Program:
Chebyshev-I Filter
clc;

clear all;
close all;
disp('C-I LPF and HPF');
%C-I LPF
ap=input('Enter pb attn in dB: ');
as=input('Enter sb attn in dB: ');
wp=input('Enter pb freq in rad: ');
ws=input('Enter sb freq in rad: ');
[N,wc]=cheb1ord(wp/pi,ws/pi,ap,as);
[b,a]=cheby1(N,ap,wc);
..
..
Follow similar steps in LPF

%C-I HPF
[b,a]=cheby1(N,ap,wc,'high');
..
..
Follow similar steps in LPF

disp('C-I BPF and BRF');


%C-I BPF
ap=input('Enter pb attn in dB: ');
as=input('Enter sb attn in dB: ');
wp=input('Enter pb edge1 and edge2 freq : ');
ws=input('Enter sb edge1 and edge2 freq : ');
[N,wc]=cheb1ord(wp/pi,ws/pi,ap,as);
[b,a]=cheby1(N,ap,wc);
..
..
Follow similar steps in LPF

%C-I BRF
[b,a]=cheby1(N,ap,wc,'stop');
..

..
Follow similar steps in LPF

Chebyshev-II Filter
disp('C-II LPF and HPF');
%C-II LPF
ap=input('Enter pb attn in dB: ');
as=input('Enter sb attn in dB: ');
wp=input('Enter pb freq in rad: ');
ws=input('Enter sb freq in rad: ');
[N,wc]=cheb2ord(wp/pi,ws/pi,ap,as);
[b,a]=cheby2(N,as,wc);
..
..
Follow similar steps in LPF

%C-II HPF
[b,a]=cheby2(N,as,wc,'high');
..
..
Follow similar steps in LPF

disp('C-II BPF and BRF');


%C-II BPF
ap=input('Enter pb attn in dB: ');
as=input('Enter sb attn in dB: ');
wp=input('Enter pb edge1 and edge2 freq : ');
ws=input('Enter sb edge1 and edge2 freq : ');
[N,wc]=cheb2ord(wp/pi,ws/pi,ap,as);
[b,a]=cheby2(N,as,wc);
..
..
Follow similar steps in LPF

%C-II BRF
[b,a]=cheby2(N,as,wc,'stop');
..
..
Follow similar steps in LPF

Output:
C-I LPF and HPF
Enter pb attn in dB: 1
Enter sb attn in dB: 15
Enter pb freq in rad: 0.2*pi
Enter sb freq in rad: 0.3*pi
C-I BPF and BRF
Enter pb attn in dB: 2
Enter sb attn in dB: 20
Enter pb edge1 and edge2 freq : [0.2*pi,0.4*pi]
Enter sb edge1 and edge2 freq : [0.1*pi,0.5*pi]
C-II LPF and HPF
Enter pb attn in dB: 1
Enter sb attn in dB: 15
Enter pb freq in rad: 0.2*pi
Enter sb freq in rad: 0.3*pi
C-II BPF and BRF
Enter pb attn in dB: 2
Enter sb attn in dB: 20
Enter pb edge1 and edge2 freq : [0.2*pi,0.4*pi]
Enter sb edge1 and edge2 freq : [0.1*pi,0.5*pi]

You might also like