You are on page 1of 22

Digital Signal Processing Lab, Dept. of ECE, KL University. Id.

No: 2000040230

Name: G.NAGENDRA Lab Section:B Id No:2000040230

Pre-lab Session In-Lab Session Post Lab session Viva Total Marks
work (15M) work (15M) work (10M) (10M) 50M

Remarks if any:

Date: Signature of the Instructor Marks awarded

Digital Signal Processing-19EC2208


Lab-3: Design and Implementation of Infinite Impulse
Response (IIR) Filters- Lab5
Lab Report

Introduction: A digital filter is a Linear Time


Invariant System. The input sequence is
modified according to the characteristics of the
system and gives some output. Hence the
system is acting some kind of filtering operation. In time domain the input and outputs
are related by , where is impulse response of the system. If the

impulse response duration is infinite, then it is referred to as IIR filter. IIR filters have
nonlinear phase characteristic which means the output of such a filter is (most likely) a
deformed version of the input without the filtered frequency. On the other hand IIR filters
might become unstable.

Objectives:

To
 The study of the basic theory of analog Butterworth filters design.
 Design and implementation of analog Butterworth IIR filters.
 Design and implementation of digital IIR filters using Impulse Invariance
Transformation Techniques.

1
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

 Design and implementation of digital IIR filters using Bilinear Transformation


Techniques.

Requirements: Digital Computer with MATLAB software.

Basic theory: The input output relation of a IIR digital filter is described by a
difference equation:

where and are filter coefficients, N is the order of the filter, N > M. The transfer

function of the digital filter is represented by

The design of an IIR filter for the given specifications is determining filter coefficients

and of the filter.

The classic IIR filter design technique includes the following steps.
1. Determine the order of the analog prototype filter from the given specifications.
2. Find an analog lowpass filter with cutoff frequency of 1 rad/sec and translate this
prototype filter to the specified band configuration.
3. Transform the analog filter to the digital domain.
4. Discretize the filter.
5. Find the digital filter transfer function.
6. Plot the frequency response of both analog and digital filters.

Step1: Analog filters Prototype Design

The first step in the classical approach of IIR filter design is to determine the order of
the filter from the given specifications. The following two examples illustrate the finding
the order of low-pass and high-pass filters.

Find the order of the filter from the analog filter coefficients. Design a lowpass analog
prototype filters with cutoff frequency of 1 rad/sec.

Ex1: Design and implementation of Low Pass Filter with the following specifications:

2
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

(a) Find the order of the Butterworth LPF filter


(b) Determine normalized analog Butterworth LPF transfer function.
(c) Plot the frequency response of the normalized Butterworth LPF transfer function.
(d) Find the analog Butterworth LPF transfer function with desired cut off frequency.
(e) Plot the frequency response of the desired filter transfer function.

Develop Matlab code and validate with theoretical results.


Solution: Given that
Pass band frequency Fp = 500 Hz, Stop band frequency Fs = 3000 Hz
Pass band ripple rp = -1.5 dB, Stop band ripple rs = -20 dB,
Sampling frequency Fsamp = 12000 Hz.
Fp = 500; Fs= 3000; rp = 1.5; rs = 20; Fsamp = 12000;
Converting the frequencies in terms of radians / sec as
Op = 2*pi*Fp; Os=2*pi*Fs;

% Design and implementation of Analg Low-pass Butterworth Filter


% Developed by Dr. M. Venu Gopala Rao,
% Email: mvgr03@kluniversity.in, mvgr03@gmail.com,

clear;close all;clc;

format long

% Filter specifications
rp = -1.5; % Passband ripple
rs = -20; % Stopband ripple
Fp = 500; % Passband frequency in Hz
Fs= 3000; % Stopband frequency in Hz
Fsamp = 12000; % Sampling frequency

Analog filter frequencies in radians/sec

% Analog filter frequencies in rad / sec


Op = 2*pi*Fp; Os=2*pi*Fs;

(a) Determining the order of the filter

3
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

% Determining the order of the analog Butterworth filter


N = ceil((log10((10.^(0.1*abs(rs))-1)./(10.^(0.1*abs(rp))-1)))/ ...
(2*log10(Os/Op)));

disp('Order of the Butterworth filter');

Order of the Butterworth filter

N
N =
2

Computing the cut-off frequency from the given specifications using the formula

% Determining the cut-off frequency of the analog Butterworth filter


Oc = Os / ((10^(0.1*abs(rs))-1)^(1/(2*N)))
disp('The cutoff frequency');

The cutoff frequency

Oc
Oc =
5.975748682891273e+03
Determining Butterworth low pass filter order and cut-off frequency using Matlab 'butter.m'
command.

% Using Matlab comman 'butter.m'


[N,Oc] = buttord(Op,Os,rp,rs,'s');

(b) Determine normalized analog filter transfer function.


Computing the Normalized filter coefficients with normalized cut-off frequency (unity).

% Computing the normalized filter coefficients with normalized cut-off


% frequency unity.
Ocn = 1; % Normalized cut off frequency 1 rad / sec

4
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

[bn,an] = butter(N,Ocn,'s');
bn
bn = 1×3
0 0 1
an
an = 1×3
1.000000000000000 1.414213562373095 1.000000000000000
% Determining Analog filter transfer function with Normalized cut off
frequency
Hsn = tf(bn, an);
Hsn
Hsn =
1
-----------------
s^2 + 1.414 s + 1

Continuous-time transfer function.


(c) Plotting the frequency response of normalized analog Butterworth filter

% Plot the frequency response of normalized analog Butterworth filter


w = logspace(-1,1); % Frequency axis
Hn = freqs(bn,an,w); % Frequency response
mag = abs(Hn); % Magnitude response
phase = angle(Hn); % Phase response
phasedeg = phase*180/pi; % Phase in degrees

figure();
subplot(2,1,1);loglog(w,mag);grid on
title('Magnitude Response of normalized transfer function');
xlabel('Frequency (rad/s)'); ylabel('Magnitude');

subplot(2,1,2);semilogx(w,phasedeg);grid on
title('Phase Response of normalized transfer function');
xlabel('Frequency (rad/s)'); ylabel('Phase (degrees)');

lines = findall(gcf,'type','line');
lines(1).Color ='blue'; lines(2).Color = 'red';

5
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

(d) Determining analog filter transfer function with desired cut off frequency.

Desired analog Butterworth filter coefficients can be derived by transforming Low pass to

low pass filter, by substituting

% Computing the desired filter coefficients with desired cut-off


% frequency Oc rad / sec calculated above
[b,a] = butter(N,Oc,'s');
b
b = 1×3
107 ×
0 0 3.570957232107679
a
a = 1×3
107 ×
0.000000100000000 0.000845098483268 3.570957232107679

% Another method
[b, a] = lp2lp(bn, an, Oc)

b =
3.570957232107679e+07
a = 1×3

6
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

107 ×
0.000000100000000 0.000845098483268 3.570957232107679

Determining analog filter transfer function with desired cut off frequency.

% Analog filter transfer function with desired cut off frequency


Hsn = tf(b, a)
Hsn =

3.571e07
-----------------------
s^2 + 8451 s + 3.571e07

Continuous-time transfer function.


(e) Plotting the frequency response of desired analog Butterworth low-pass filter.

% Normalized filter transfer function


w = logspace(-1,1);
H = freqs(b,a,w);
mag = abs(H);
phase = angle(H);
phasedeg = phase*180/pi;

figure();
subplot(2,1,1);loglog(w,mag);grid on
title('Magnitude Response of desired transfer function');
xlabel('Frequency (rad/s)'); ylabel('Magnitude');

subplot(2,1,2);semilogx(w,phasedeg);grid on
title('Phase Response of desired transfer function');
xlabel('Frequency (rad/s)'); ylabel('Phase (degrees)');

lines = findall(gcf,'type','line');
lines(1).Color ='blue'; lines(2).Color = 'red';

Ex2: Design and implementation of High Pass Filter with the following specifications:

(a) Find the order and cut-off frequency of the Butterworth HPF filter
(b) Determine normalized Butterworth analog LPF transfer function.
(c) Find the analog Butterworth HPF transfer function with desired cut off frequency.

7
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

(d) Plot the frequency response of the desired Butterworth HPF transfer function.

Develop Matlab code and validate with theoretical results.


Solution: Given that
Pass band frequency Fp = 3000 Hz, Stop band frequency Fs = 500 Hz
Pass band ripple rp = -1.5 dB, Stop band ripple rs = -20 dB,
Sampling frequency Fsamp = 12000 Hz.
Fp = 500; Fs= 3000; rp = 1.5; rs = 20; Fsamp = 12000;
Converting the frequencies in terms of radians / sec as
Op = 2*pi*Fp; Os=2*pi*Fs;

% Design and implementation of Analg Butterworth High-pass Filter


%%% Developed by Dr. M. Venu Gopala Rao,
%%% Email: mvgr03@kluniversity.in, mvgr03@gmail.com.

clear;close all;clc;
format long

% Filter specifications
rp = -1.5;
rs = -20;
Fs = 500; % Hz
Fp= 3000; % Hz
Fsamp = 12000; % Hz

% Analog filter frequencies in rad / sec


Op = 2*pi*Fp; Os=2*pi*Fs;

The task is to design a high pass filter. However, first we will design a low pass filter and
then transform into high pass filter. To do this, we will interchange the pass band and
stop band frequencies and find the normalized Butterworth LPF transfer function.

(a) Computing the order and cut-off frequency of Butterworth low pass filter from the given
specifications.

8
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

[N,Oc] = buttord(Os,Op,rp,rs,'s')
N =
2
Oc =
5.975748682891273e+03

N
N =
2

Oc
Oc =
5.975748682891273e+03
(b) Determining normalized Butterworth analog LPF transfer function.

% Determining filter coefficients with unit cut off frequency


Ocn = 1; % Cutoff frequency 1 rad / sec
[bn,an] = butter(N,Ocn, 's');
bn
bn = 1×3
0 0 1
an
an = 1×3
1.000000000000000 1.414213562373095 1.000000000000000

Determining the normalized analog Butterworth low-pass filter transfer function.

Hsn = tf(bn, an) ;


Hsn
Hsn =

1
-----------------
s^2 + 1.414 s + 1

Continuous-time transfer function.

(c) Determining the desired Butterworth analog high-pass filter transfer function: Desired analog
Butterworth filter coefficients can be derived by transforming Low pass to high pass filter,

by substituting .

[bh, ah] = lp2hp(bn, an, Oc);


bh
bh = 1×3

9
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

1 0 0
ah
ah = 1×3
107 ×
0.000000100000000 0.000845098483268 3.570957232107679

Determining the desired analog Butterworth high-pass filter transfer function.

% Analog Desired Butterworth high pass filter transfer function


Hs = tf(bh, ah);
Hs
Hs =

s^2
-----------------------
s^2 + 8451 s + 3.571e07

Continuous-time transfer function.

(d) Plotting the frequency response of desired Butterworth high pass filter.

% Desired filter transfer function


w = logspace(-1,1);
H = freqs(bh,ah,w);
mag = abs(H);
phase = angle(H);
phasedeg = phase*180/pi;

figure();
subplot(2,1,1);loglog(w,mag);grid on
title('Magnitude Response of desired transfer function');
xlabel('Frequency (rad/s)'); ylabel('Magnitude');

subplot(2,1,2);semilogx(w,phasedeg);grid on
title('Phase Response of desired transfer function');
xlabel('Frequency (rad/s)'); ylabel('Phase (degrees)');

lines = findall(gcf,'type','line');
lines(1).Color ='blue'; lines(2).Color = 'red';

10
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

Ex3: Design and implementation of IIR low pass digital filter using IIM: Design a digital
low pass Butterworth filter using impulse-invariant transformation with pass band and
stop band cut off frequencies 0.08*pi and 0.2*pi rad/sec respectively. The pass band and
stop band attenuation are -1.5 dB and -20 dB respectively.

% Design and implementation of digital low pass filter using Impulse


% Invariance transformation Method
% %%% Developed by Dr. M. Venu Gopala Rao,
% %%% Email: mvgr03@kluniversity.in, mvgr03@gmail.com,
clear;close all;clc;
format long

% Digital Filter specifications


rp = -1.5; % Passband ripple
rs = -20; % Stopband ripple
wp = 0.08*pi; % Passband frequency in rad/sec
ws = 0.2*pi; % Stopband frequency in rad/sec

Converting Digital Filter parameters into analog filter parameters Impulse Invariance
Method.

% Converting Digital Filter parameters into analog filter parameters


T = 1; % Assume
Op = wp/T; Os = ws/T; rp = -5; rs = -12;
fs = 1/T;

11
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

Determining the order and cut-off frequencies from the analog filter specifications

% Determing the order and cut-off frequency of the Butterworth low pass
filter
N = ceil((log10((10.^(0.1*abs(rs))-1)./(10.^(0.1*abs(rp))-1)))/ ...
(2*log10(Os/Op)));
N
N =
2

% Determing the desired cut off frequency


Oc = Op / ((10^(.1*abs(rp))-1)^(1/(2*N)));
Oc
Oc =
0.207258329938706

Determining the normalized filter transfer function

% Determining normalized filter coefficients with cutoff frequency 1 rad /


sec
Ocn = 1; %Normalized LPF cut-off frequency
[bn,an] = butter(N,Ocn, 's') ;
bn
bn = 1×3
0 0 1
an
an = 1×3
1.000000000000000 1.414213562373095 1.000000000000000

% Analog filter transfer function with Normalized cut off frequency


Hsn = tf(bn, an) ;
Hsn
Hsn =

1
-----------------
s^2 + 1.414 s + 1

Continuous-time transfer function.

Determining Butterworth low-pass filter coefficients with desired cutoff frequency Oc.

% Determining filter coefficients with desired cutoff frequency Oc


[b,a] = butter(N,Oc, 's') ;
b

12
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

b = 1×3
0 0 0.042956015328982
a
a = 1×3
1.000000000000000 0.293107541114116 0.042956015328982

% Another method using lowpass to low pass filter transformation


[b, a] = lp2lp(bn, an, Oc)
b =
0.042956015328982
a = 1×3
1.000000000000000 0.293107541114116 0.042956015328982

% Analog filter transfer function with desired cut off frequency


Hs = tf(b, a);
Hs
Hs =

0.04296
------------------------
s^2 + 0.2931 s + 0.04296

Continuous-time transfer function.

Digital Filter design using Impulse Invariance transformation method.

% Impulse-Invariant Transformation
[bz,az] = impinvar(b,a,fs);
bz
bz = 1×2
0 0.036967556921763
az
az = 1×3
1.000000000000000 -1.708841648573466 0.745941916958809

% Digital filter transfer function with desired cut off frequency


Hsz = tf(bz, az,1); % to be checked
Hsz
Hsz =

0.03697
----------------------
z^2 - 1.709 z + 0.7459

Sample time: 1 seconds


Discrete-time transfer function.

13
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

Plotting the desired Digital Butterworth low-pass filter

% Plot the impulse response of the system


figure()
impz(bz,az,[],fs);

% Desired digital frequency response


w = logspace(-1,1);
Hz = freqz(bz,az,w);
magz = abs(Hz);
phasez = angle(Hz);
phasedegz = phasez*180/pi;

figure();
subplot(2,1,1);loglog(w,magz);grid on
title('Magnitude Response of desired digital filter transfer function');
xlabel('Frequency (rad/s)'); ylabel('Magnitude');

subplot(2,1,2);semilogx(w,phasedegz);grid on
title('Phase Response of desired digital filter transfer function');
xlabel('Frequency (rad/s)'); ylabel('Phase (degrees)');

lines = findall(gcf,'type','line');
lines(1).Color ='blue'; lines(2).Color = 'red';

14
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

15
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

Ex4: Design and implementation of IIR low pass digital filter using Bi-linear
transformation:
Design a digital low pass Butterworth filter using impulse-invariant transformation with
pass band and stop band cut off frequencies 0.08*pi and 0.2*pi rad/sec respectively. The
pass band and stop band attenuation are -1.5 dB and -20 dB respectively.

% % Design and implementation of digital low pass filter using Bi-linear


% % transformation
% %%% Developed by Dr. M. Venu Gopala Rao,
% %%% Email: mvgr03@kluniversity.in, mvgr03@gmail.com.
%
clear;close all;clc;
format long

% Digital Filter specifications


rp = -1.5; % Passband ripple
rs = -20; % Stopband ripple

16
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

wp = 0.08*pi; % Passband frequency in rad/sec


ws = 0.2*pi; % Stopband frequency in rad/sec

Pre-warping process: Converting digital frequencies into pre-warped analog frequencies.

% Prewarping analog frequencies


T = 1; fs = 1/T; % Assume
% Prewarping Bilinear
Op = 2/T * tan(wp/2);
Os = 2/T * tan(ws/2);
Op
Op =
0.252658756892216

Os
Os =
0.649839392465813
Determining the order and cut off-frequency of the Butterworth low pass filter.

% Determing the order of the filter


[N,Oc] = buttord(Op,Os,rp,rs,'s')
N =
3
Oc =
0.302134395165487
Determining the normalized low pass Butterworth filter transfer function.

% Determining normalized filter coefficients with cutoff frequency 1 rad


/ sec
Ocn = 1;
[bn,an] = butter(N,Ocn, 's') ;
bn
bn = 1×4
0 0 0 ⋯
an
an = 1×4
1.000000000000000 2.000000000000000 1.999999999999999 ⋯

% Analog filter transfer function with Normalized cut off frequency


Hsn = tf(bn, an) ;
Hsn
Hsn =

1
---------------------

17
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

s^3 + 2s^2 + 2s + 1

Continuous-time transfer function.

Determining the desired low pass Butterworth low pass filter

% Determining desired filter coefficients with desired cutoff frequency Oc


[b,a] = butter(N,Oc, 's') ;
b
b = 1×4
0 0 0 ⋯
a
a = 1×4
1.000000000000000 0.604268790330974 0.182570385484029 ⋯

%Analog filter transfer function with desired cut off frequency


Hs = tf(b, a) ;
Hs
Hs =

0.02758
-------------------------------------
s^3 + 0.6043 s^2 + 0.1826 s + 0.02758

Continuous-time transfer function.


lines(2).Color = 'red';

Design of digital filter with bilinear transformation

% Bilinear Transformation
[bz,az] = bilinear(b,a,fs);
bz
bz = 1×4
0.002551426100714 0.007654278302140 0.007654278302146 ⋯
az
az = 1×4
1.000000000000000 -2.402375809033949 1.970483495648343 ⋯
% Digital filter transfer function with desired cut off frequency
Hsz = tf(bz, az,1);
Hsz
Hsz =

0.002551 z^3 + 0.007654 z^2 + 0.007654 z + 0.002551


---------------------------------------------------
z^3 - 2.402 z^2 + 1.97 z - 0.5477

18
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

Sample time: 1 seconds


Discrete-time transfer function.

Plotting the frequency response of desired digital Butterworth LPF using Bilinear
transformation.

% % Plotting the frequency response of desired digital filter transfer


function
w = logspace(-1,1);
Hz = freqz(bz,az,w);
magz = abs(Hz);
phasez = angle(Hz);
phasedegz = phasez*180/pi;

figure();
subplot(2,1,1);loglog(w,magz);grid on
title('Magnitude Response of desired digital filter transfer function');
xlabel('Frequency (rad/s)'); ylabel('Magnitude');

subplot(2,1,2);semilogx(w,phasedegz);grid on
title('Phase Response of desired digital filter transfer function');
xlabel('Frequency (rad/s)'); ylabel('Phase (degrees)');

lines = findall(gcf,'type','line');
lines(1).Color ='blue'; lines(2).Color = 'red';

19
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

20
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

Pre lab session:

(a) Study and understand the basic theory required for this lab.
(b) Study and prepare the analytical solutions for given examples.

In Lab session:

(a) Run the Matlab scripts of given examples and study the results.
(b) Study the exercise questions and develop Matlab and observe the results.
(c) Note the results and store the necessary figures and data for the lab report.

Practice Laboratory Exercise-3


The students are required to provide the solutions of the following for all the exercise
questions.
(a) Workout analytical solutions initially
(b) Develop corresponding Matlab programs.

21
Digital Signal Processing Lab, Dept. of ECE, KL University. Id. No: 2000040230

Exercise1: Consider the following specifications of an analog Butterworth low pass filter.
Sampling rate of 40 kHz, pass band edge frequency of 4 kHz, stop band edge frequency
of 8 kHz, Pass band ripple of 0.5 dB, and a minimum stop band attenuation of 40 dB.

(i) Find the order and cutoff frequency (ii) Determine the normalized and desired LPF.
(ii) Assume the suitable data.6
Exercise2: Consider the following specifications:

(i)

(ii) 1 dB ripple in the pass-band

At least 40 dB attenuation in the stopband

Design and implement the digital low pass filters using (a) Impulse Invariance
transformation method. (b) Bi-linear transformation method. Assume suitable data.

Exercise3: Design and develop high pass filters for the exercise questions in above.

Post Lab Session:

(a) Complete the lab work in all aspects in the given specified lab time.
(b) Answer the given questions.
(c) Submit the lab report to the lab in-structure and get the signature in time.
(d) Type the complete description of commands used in the lab.

Reference Text Books:

1. Vinay K Ingle and John G. Proakis, ‘Digital Signal Processing using Matlab’,
3rd edition, Cambridge University Press, New York, 2011.
2. Sanjit K. Mitra, Digital Signal Processing: A Computer based Approach,4th
edition.

22

You might also like