Matlab Program for Infinite Impulse Response
Filter
by
R.Senthilkumar, Assistant Professor, ECE
Department, IRTT
Matlab Program for IIR Butterworth Filter Design using Bilinear
Transformation
clear all;
close all;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
delta1 = input('Enter the Pass Band Ripple');
delta2 = input('Enter the Stop Band Ripple');
wp = input('Enter the Digital Pass Band Edge Frequency');
ws = input('Enter the Digital Stop Band Edge Frequency');
T = input('Enter the Sampling Time Period in Seconds');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Analog Frequencies Calculated using Bilinear Transformation
omegap = (2/T)*tan(wp/2);
omegas = (2/T)*tan(ws/2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%To Calculate the filter order
den = 2*log10(omegas/omegap);
delta = ((1/(delta2^2))-1);
epsi = ((1/(delta1^2))-1);
num = log10(delta/epsi);
N = ceil(num/den);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%To Calculate the Analog Cut off frequency
disp('If LPF enter 1, If HPF enter 2, If BPF enter 3, If BSF
enter 4');
type = input('enter the type of the filter you want to design');
switch type
case 1
omegac = omegap/(epsi^(1/(2*N)));
wc = 2*atan(omegac/2);
[b,a] = butter(N,wc/pi);
case 2
omegac = omegap/(epsi^(1/(2*N)));
wc = 2*atan(omegac/2);
[b,a] = butter(N,wc/pi,'high');
case 3
omegac1 = omegap/(epsi^(1/(2*N)));
omegac2 = omegas/(delta^(1/(2*N)));
wc1 = 2*atan(omegac1/2);
wc2 = 2*atan(omegac2/2);
wc = [wc1,wc2]
[b,a] = butter(N,wc/pi);
case 4
omegac1 = omegap/(epsi^(1/(2*N)));
omegac2 = omegas/(delta^(1/(2*N)));
wc1 = 2*atan(omegac1/2);
wc2 = 2*atan(omegac2/2);
wc = [wc1,wc2]
[b,a] = butter(N,wc/pi,'stop');
otherwise
disp('The Type Entered is not a valid filter');
end
[H,W] = freqz(b,a,128);
plot(W/pi,20*log10(abs(H)));
grid on
xlabel('Frequency x Pi in radians per sample')
ylabel('Magnitude in dB')
title('Butterworth Filter Design using Bilinear Method')
IIR Filters Types:
1) Butterworth IIR Filter
2) Chebychev IIR Filter
3) Bessel IIR Filter
4) Elliptic IIR Filter
Transformation Methods – Analog IIR Filter Transfer Function [ H(S) ]
to Digital IIR Filter Transfer Function [ H(Z)]
1) Bilinear Transformation
2) Impulse Invariant Method
3) Matched Z Transform
4) Approximation of Derivatives Method
1) Bilinear Transformation:
(1-z-1)
H(Z) = H(S) / S = (2/T) -------
(1+z-1)
example : H(S) = 2/(s+1)(S+2)
2) Impulse Invariant Method:
Step 1 : Do Partial Fraction so that H(s) = 2 (-2)
---- + ------
(S+1)
(S+2)
Step 2 : Take Inverse Laplace transform to find out h(t)
Step 3: To Design a Digital Filter, Sample the Impulse Response h(t)
So that it becomes h(nT). Replace t by nT
Step 4: Find out the Z transform
H(Z) = Z { h(nT)}
Butterworth IIR Filter:
1) Formula to Calculate Filter Order (N)
1
1
2
log 2
1 1
2
1
N
2 log
s
P
2) Formula to calculate Poles
S jce j( 2k 1) / 2N
where k = 0,1,2,………N-1
Design Of Digital Butterworth IIR Filter uisng Bilinear Transformation
Procedure:
Given Parameters in problem
wp – Digital Pass band Edge Frequency δ1 = Pass band Ripple
ws –Digital Stop band Edge Frequency δ2 = Pass band Ripple
Step 1:
Ωp = Analog Pass band Edge Frequency = (2/T) tan( wp / 2)
Ωs = Analog Pass band Edge Frequency = (2/T) tan( ws / 2)
Step 2:
1
1
Filter Order = 2
log 2
1
1
2
1
N
s
2 log
P
Step 3:
Analog Cut off Frequency Ωc = Ωp / [(1/ δ12 ) -1] (1/2N)
Step 4:
Analog Butterworth IIR Filter transfer function
(Ωc) N
H(S) = ---------
poles
Step 5:
Poles
S j ce j( 2k 1) / 2N
Where k =0,1,2….N-1
Step 6:
Digital IIR Butterworth Filter from Analog IIR Butterworth Filter
(1-z-1)
H(Z) = H(S) / S = (2/T) -------
(1+z-1)