To Design and Implement An IIR Filter For Given Specifications
To Design and Implement An IIR Filter For Given Specifications
To Design and Implement An IIR Filter For Given Specifications
Theory:
There are two methods of stating the specifications as illustrated in previous program. In the first program, the
given specifications are directly converted to digital form and the designed filter is also implemented. In the last
two programs the Butterworth and Chebyshev filters are designed using bilinear transformation.
Method1:
Program 1:
Generate filter coefficients and plot the frequency response of an LPF for the given order & cutoff say N=10,
fc=150Hz and sampling frequency fs=1000 Hz, using Butterworth approximation
clc;
close all;
clear all;
Fs=1000;
N=10;
fc=150;
[b,a]=butter(N, fc/(Fs/2)) %filter coefficients
b = 1×11
0.0000 0.0005 0.0022 0.0060 0.0104 0.0125 0.0104 0.0060
a = 1×11
1.0000 -3.9877 8.0944 -10.4763 9.4233 -6.0842 2.8353 -0.9364
1
Method 2:
Design a Low pass Butterworth filter with pass band ripple less than 3db, stop band attenuation not more than
40db, and pass band corner frequency is 200 Hz, Stop band edge frequency is 500 Hz, sampling frequency 2
kHz. Plot Magnitude and Phase response of the filter.
Program 2:
Design of a Band pass filter using Chebyshev type1 approximation for rp=3dB, rs=40dB, Pass band frequencies
are fpb1=100Hz and fpb2=200Hz. Stop band frequencies are fsb1=50Hz and fsb2=300Hz. Sampling frequency
Fs= 1KHz. Plot Magnitude and Phase response the filter.
clear all;
close all;
clc;
Rp=3;
Rs=40;
fp=[100 200]; %pass band frequencies
fs=[50 300]; %stop band frequencies
Fs=1000; %sampling frequency
Wp=2*fp/Fs; % normalizing between 0 and 1
Ws=2*fs/Fs;
2
[N,Wn]=cheb1ord(Wp,Ws,Rp,Rs) %computes order & cutoff
N = 4
Wn = 1×2
0.2000 0.4000
Program 1a:
3
Design an IIR digital low pass filter using Butterworth approximation and Bilinear transformation technique for
the following specifications. rp=3dB, rs=40dB, wp=800Hz, ws=1600, wsa=4000. Plot the frequency response.
4
Program 1b:
To Design an IIR band pass digital filter using Butterworth approximation. Given rp= 3db, rs= 40db,
wp1=100Hz , wp2=200Hz, ws1=50Hz , ws2=250 Hz, Sampling frequency F is 1KHz. Plot Magnitude and Phase
response of the filter.
% To Design an IIR band pass digital filter using Butterworth approximation by applying Bilinea
clc;
clear all;
close all;
% rp=3;
% rs=40;
% fp1=100;
% fp2=200;
% fs1=50;
% fs2=250;
% F=700;
rp=input('enter the passband attenuation=');
rs=input('enter the stopband attenuation=');
fp1= input('Enter first passband edge frequency in Hz=');
fp2= input('Enter second passband edge frequency in Hz=');
fs1= input('Enter first stopband edge frequency in Hz=');
fs2= input('Enter second stopband edge frequency in Hz=');
F= input('Enter sampling frequency in Hz=');
wp1=2*pi*fp1/F; % conversion to radians
wp2=2*pi*fp2/F;
5
ws1=2*pi*fs1/F;
ws2=2*pi*fs2/F;
pwp1=2*F*tan(wp1/2); % prewarping
pwp2=2*F*tan(wp2/2);
pws1=2*F*tan(ws1/2);
pws2=2*F*tan(ws2/2);
pw = [pwp1 pwp2];
sw = [pws1 pws2];
[N,wc]=buttord(pw,sw,rp,rs,'s'); % to compute order & cutoff
%frequency
[b,a]=butter(N,wc,'s'); % to compute the filter
%coefficients
[num,den]=bilinear(b,a,F); % converts s-domain transfer
%function to z-domain
[mag,freq1]=freqz(num,den,128); %to plot the frequency response
subplot(211);
freq=freq1*F/(2*pi); %conversion from radians to frequency
m=20*log10(abs(mag));
plot(freq,m); % magnitude response plot
xlabel('frequency');
ylabel('magnitude');
title('frequency response');
grid on;
Program 2a.
6
Design an IIR digital low pass filter using Chebyshev approximation and applying Bilinear transformation
technique for the following specifications. rp=3dB, rs=40dB, wp=800Hz, ws=1600, wsa=4000. Plot the
frequency response.
%design of IIR LPF using Chebyshev approximation and bilinear transformation technique
clc;
clear all;
close all;
rp=3;
rs=40;
wp=800;
ws=1600;
wsa=4000;
% Conversion to radians
awp= 2*pi*wp/wsa;
aws=2*pi*ws/wsa;
% Prewrapped frequency
pwp = 2*wsa*tan(awp/2);
pws = 2*wsa*tan(aws/2);
%Calculate order and cutoff freq
[N,wc]= cheb1ord(pwp, pws, rp, rs,'s');
% analog filter transfer function
[b,a] = cheby1(N,rp,wc,'s');
% obtaining the digital filter using bilinear transformation
[num,den]= bilinear(b,a,wsa);
%plot the frequency response
[mag,freq1]=freqz(num,den,128);
freq=freq1*wsa/(2*pi);
m = 20*log10(abs(mag));
plot(freq,m);
grid;
7
Program 2b.
Design an IIR digital BPF using Chebyshev approximation and applying Bilinear transformation technique for
the following specifications. rp= 3db, rs= 40db, wp1=100Hz , wp2=200Hz, ws1=50Hz , ws2=250 Hz, Sampling
frequency F is 1KHz
% To Design an IIR digital band pass filter using Chebyshev approximation by applying Bilinear
clc;
clear all;
close all;
% rp=3;
% rs=40;
% fp1=100;
%use any one of the methods, given data
%directly or user inputs
% fp2=200;
% fs1=50;
% fs2=250;
% F=700;
rp=input('enter the passband attenuation=');
rs=input('enter the stopband attenuation=');
fp1= input('Enter first passband edge frequency in Hz=');
fp2= input('Enter second passband edge frequency in Hz=');
fs1= input('Enter first stopband edge frequency in Hz=');
fs2= input('Enter second stopband edge frequency in Hz=');
F= input('Enter sampling frequency in Hz=');
8
% conversion to radians
wp1=2*pi*fp1/F;
wp2=2*pi*fp2/F;
ws1=2*pi*fs1/F;
ws2=2*pi*fs2/F;
% prewarping
pwp1=2*F*tan(wp1/2);
pwp2=2*F*tan(wp2/2);
pws1=2*F*tan(ws1/2);
pws2=2*F*tan(ws2/2);
pw = [pwp1 pwp2];
sw = [pws1 pws2];
[N,wc]=cheb1ord(pw,sw,rp,rs,'s'); % to compute order & cutoff frequency
[b,a]=cheby1(N,rp,wc,'s'); % to compute the filter coefficients
[num,den]=bilinear(b,a,F); % converts s-domain transfer function to z-domain
[mag,freq1]=freqz(num,den,128); %to plot the frequency response
freq=freq1*F/(2*pi); %conversion from radians to frequency
m=20*log10(abs(mag));
plot(freq,m); % magnitude response plot
xlabel('Frequency');
ylabel('phase');
title('frequency response');
grid on;
Inference:
IIR filter of given specification is designed and implemented.