Sei sulla pagina 1di 45

DESIGN

AND
IMPLEMENTATION OF
IIR FILTER
By-
SAURABH SHUKLA
M.Tech (CE)
ICE2012005
CONTENTS
Introduction
Two Approaches
The Main Problem
Characteristics of Prototype Analog Filters
Design of IIR Filter from Analog Filter
Different Methodologies to Design IIR Filter
Finite Difference Approximation Technique
Impulse Invariance Transformation
Bilinear Transformation
The Matched z- Transform
Different IIR Filters Design Using MATLAB
GUI For Digital Filter Design
Implementation of IIR Filter
References
2
INTRODUCTION
IIR filter have infinite-duration impulse responses,
hence they can be matched to analog filters, all of
which generally have infinitely long impulse
responses.

The basic technique of IIR filter design transforms
well-known analog filters into digital filters using
complex-valued mappings.

The advantage of this technique lies in the fact that
both analog filter design (AFD) tables and the
mappings are available extensively in the literature.
3
The basic technique is called the A/D filter
transformation.

However, the AFD tables are available only for low
pass filters. We also want design other frequency-
selective filters (high pass, band pass, band stop, etc.)

To do this, we need to apply frequency-band
transformations to low pass filters. These
transformations are also complex-valued mappings.
4
TWO APPROACHES
Design analog
lowpass filter
Apply Freq. band
transformation
s-->s
Apply filter
transformation
s-->z
Desired
IIR filter
Design analog
lowpass filter
Apply filter
transformation
s-->z
Apply Freq. band
transformation
z-->z
Desired
IIR filter
Approach 1, used in Matlab
Approach 2, study
5
THE MAIN PROBLEM
We have no control over the phase characteristics
of the IIR filter.

Hence IIR filter designs will be treated as
magnitude-only designs.

It doesnt mean that we consider the phase
response unimportant.

We specify the desired magnitude characteristics
and accept the phase response that is obtained
from the design methodology.
6
CHARACTERISTICS OF PROTOTYPE ANALOG
FILTERS
IIR filter design techniques rely on existing analog
filter to obtain digital filters. We designate these
analog filters as prototype filters.

Three prototypes are widely used in practice
Butterworth lowpass
Chebyshev lowpass (Type I and II)
Elliptic lowpass
7
IIR Filter Types
Butterworth Chebyshev Type I
Elliptic
Chebyshev Type II
8
Basic idea behind the conversion of into is to
apply a mapping from the s-domain to the z-domain so that
essential properties of the analog frequency response are
preserved.

Thus mapping function should be such that

Imaginary ( ) axis in the s-plane be mapped onto the
unit circle of the z-plane.(Thus there will be a direct
relationship b/w the two frequency variables in the two
domains. )

A stable analog transfer function should be mapped into
a stable digital transfer function (the left half of s-plane
should map into the inside of unit circle in the z-plane)
9
) (s H
a
) (z H
O j
DESIGN OF IIR FILTER FROM ANALOG FILTER
An analog filter can be described by


-----(1)


where and are the filter coefficient.

An analog filter can also be described by the linear constant
coefficients differential equation


----(2)

where x(t) denotes the input signal and y(t) denoted the output of
the filter.


10

=
=
= =
N
k
k
k
M
k
k
k
a
s
s
s A
s B
s H
0
0
) (
) (
) (
o
|
{ }
k
o
{ }
k
|

= =
=
M
k
k
k
k
N
k
k
k
k
dt
t x d
dt
t y d
0 0
) ( ) (
| o
Maximum passband deviation=
maximum stopband magnitude = 1/A
Pass band Frequency (normalized)
Stop band Frequency (normalized)
11
2
1
1
c +
s
p
p
F
O
= e
s
s
s
F
O
= e
DIFFERENT METHODOLOGIES TO DESIGN IIR
FILTER
The transformations are derived by preserving different
aspects of analog and digital filters.

Finite difference approximation technique
Convert a differential eq. representation into a
corresponding difference eq.

Impulse invariance transformation
Preserve the shape of the impulse response from A to
D filter

Bilinear transformation
Preserve the system function representation from A to
D domain

The Matched Z transformation
Try to match the impulse response from A to D filter.
12
1-FINITE DIFFERENCE APPROXIMATION
TECHNIQUE
One of the simplest methods for converting an analog
filter into digital filter.
For the derivative at time t=nT. we do,





In this we replace

13
T
T nT y nT y
dt
t dy
nT t
) ( ) ( ) (
=
=
T
n y n y ) 1 ( ) (
=
dt
t dy ) (
k
k
T
z
s
|
|
.
|

\
|

=
1
1
Thus

and if we substitute s=j in the above eq. we find


As varies from - to , the corresponding locus of points in the
z-plane is a circle of radius and with a center z= as shown
below









14
sT
z

=
1
1
T j
z
O
=
1
1
(

=
= O
frequency digital
frequency analog
e
The mapping takes points in the LHP of the s-plane
into corresponding points inside the circle in the z-
plane and points in the RHP of the s-plane are
mapped into outside this circle.

Thus this mapping has the desirable property that a
stable analog filter is transformed into a stable digital
filter.

The possible location of poles of the digital filter are
confined to relatively small frequencies and the
mapping is restricted to design of lowpass filters and
a bandpass filters having relatively small resonant
frequencies.
15
2-IMPULSE INVARIANCE TRANSFORMATION
Our objective to design an IIR filter having a unit sample
response h(n), that is the sampled version of the impulse
response of the analog filter.
h(n)=h(nT) n=0,1,2,..
where T is the sampling interval.

for mapping




Thus for <0 (i.e. LHP) 0<r<1 & >0 (i.e. RHP) r>1.

When =0 (imaginary axis) r=1.

Therefore the LHP in s is mapped inside the unit circle in z and
the RHP in s is mapped outside the unit circle in z.
16
T
e e e r
T j j T
O =
= =
O
e
e o

and
sT
e z =
T j T j
e e re
O
=
o e

Also s=j axis is mapped into the unit circle in z.
We have the following transformation from the s-plane to the
z-plane: z=e
sT


Many s to one z mapping: many-to-one mapping
Every semi-infinite left strip (so the whole left plane) maps
to inside of unit circle.
Since is unique over the range (-,), the mapping
=T implies in general


17

=
|
.
|

\
|
=
k
a
k
T
j s H
T
z H
t 2 1
) (
Frequency-domain aliasing
formula
T k T k / ) 1 2 ( / ) 1 2 ( t t + s O s
Causality and Stability are the same without changing.

Aliasing occur if filter not exactly band-limited

So, The digital filter impulse response is similar to that of a
frequency-selective analog filter.

Advantages
It is a stable design and the frequencies and w are linearly
related.

Disadvantage
We should expect some aliasing of the analog frequency
response, and in some cases this aliasing is intolerable.

Consequently, this design method is useful only when the
analog filter is essentially band-limited to a lowpass or
bandpass filter in which there are no oscillations in the stopband.

18
MATLAB PROGRAM FOR IMPULSE INVARIANCE
TRANSFORMATION
Program-1
[b,a] = butter(4,0.3,'s');
[bz,az] = impinvar(b,a,10);
sys = tf(b,a);
impulse(sys);
hold on;
impz(10*bz,az,[],10);

19
Zooming the resulting
plot shows that the
analog and digital
impulse responses are
the same.
Program-2
clc
disp(' Impulse invariance transformation'); disp(' ');
Wp = input('Enter passband edge frequency in rad/sec = '); %1500
Rp = input('Enter passband ripple in dB = '); %.5
Ws = input('Enter stopband edge frequency in rad/sec = '); %3000
Rs = input('Enter stopband ripple in dB = '); %60
Fs = input('Enter the sampling frequency = '); %7000
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,'s');
disp('The order of the filter is n = ');
disp(n); %display order of the filter%
[num,den] = cheby1(n,Rp,Wn,'s'); % calculates coefficients of analog filter%
[b,a] = impinvar(num,den,Fs) %applies IIT%
freqz(b,a,512,Fs); %frequency response %
grid on;
xlabel('Frequency in Hz');
ylabel('Gain in dB');
title('Frequency Response of the filter'); 20
21
3- BILINEAR TRANSFORMATION
The above two discussed design techniques have severe
limitation in that they are appropriate only for LPF and a limited
class of BPF.

This bilinear transformation is a mapping that transforms the j
axis into the unit circle in the z-plane only once.

Thus it avoids aliasing of frequency components.

Furthermore all points of the LHP of s are mapped inside the
unit circle in the z-plane and all points in the RHP of s are
mapped into corresponding points outside the unit circle in z-
plane.

This mapping is the best transformation method.

22
23
The complex plane mapping is shown as below-









Relation of to is nonlinear-
=2tan(/2)/T = 2tan-1(T/2)

Therefore due to this highly nonlinear mapping, we observe a
frequency compression or frequency warping.


2 / 1
2 / 1
1
1 2
1
1
sT
sT
z
z
z
T
s

+
=
+

The entire range in is mapped only once into the range








Frequency Warping
Because of the non linear mapping, the amplitude response of
digital IIR filter is expanded at lower frequencies and compressed
at higher frequencies in comparison to analog filter.



24
t e t s s
The H
a
(j) compressed in frequency by this
transformation.

But the characteristics of H
a
(j) are preserved in H(z).

If |H
a
(j)| is equiripple in passband or stopband, then
|H(z)|is also. This property is the most important feature of
bilinear transformation and made it most widely employed
transformation for classical designs.

Advantages
It is a stable design.
There is no aliasing.
There is no restriction on the type of filter that can be
transformed.

25
MATLAB PROG FOR BILINEAR TRANSFORMATION
Program-1
clc
Wp = input('Enter passband edge frequency in rad/sec = ');
Rp = input('Enter passband ripple in dB = ');
Ws = input('Enter stopband edge frequency in rad/sec = ');
Rs = input('Enter stopband ripple in dB = ');
Fs = input('Enter the sampling frequency = ');
[n,Wn] = buttord(Wp,Ws,Rp,Rs,'s');
disp('The order of the filter is n = ');
disp(n); %display order of the filter%
[num,den] = butter(n,Wn,'s'); %calculates coefficients of analog filter%
[b,a] = bilinear(num,den,Fs) % apply bilinear transformation%
freqz(b,a,512,Fs); %frequency response %
grid on;
xlabel('Frequency in Hz');
ylabel('Gain in dB');
title('Frequency Response of the filter'); 26

27
4-THE MATCHED Z TRANSFORM
In the matched z-transform digital filter design method we
try to match the impulse response of the analog filter with
that of the digital filter being designed.

To match the impulse responses, we take the inverse
Laplace transform of the analog filter H(s)h(t), then
sample the impulse response h(t)h[n], then take the z-
transform of the sampled impulse response to get the z-
transform transfer function h[n]H(z).
28
Example-



And

thus

Note-
Poles obtained from the matched z-transformation are
identical to the poles obtained with the impulse invariance
method.

But the two techniques results in different zero location

29
s
s H
1
) ( =
) ( ) ( t u t h = ] [ ] [ n u n h =
1
1
1
) (

=
z
z H
1
1
1
) (
) (
) (

= =
z z X
z Y
z H
) ( ] 1 )[ (
1
z X z z Y =

] [ ] 1 [ ] [ n x n y n y =
DIFFERENT IIR DIGITAL FILTERS DESIGN USING
MATLAB
Program-1 (Elliptic IIR Lowpass Filter Design)
%---N-filter order& Wn= Frequency scaling factor---%
Wp = input('Normalized passband edge = ');
Ws = input('Normalized stopband edge = ');
Rp = input('Passband ripple in dB = ');
Rs = input('Minimum stopband attenuation in dB = ');
[N,Wn] = ellipord(Wp,Ws,Rp,Rs)
[b,a] = ellip(N,Rp,Rs,Wn);
[h,omega] = freqz(b,a,256);
plot (omega/pi,20*log10(abs(h)));grid;
xlabel('\omega/\pi'); ylabel('Gain, dB');
title('IIR Elliptic Lowpass Filter');

(in case of elliptic filter Wn=Wp)
30
31
Program-2 (Type-1 Chebyshev IIR HPF Design)

Wp = input('Normalized passband edge = ');
Ws = input('Normalized stopband edge = ');
Rp = input('Passband ripple in dB = ');
Rs = input('Minimum stopband attenuation in dB = ');
[N,Wn] = cheb1ord(Wp,Ws,Rp,Rs)
[b,a] = cheby1(N,Rp,Wn,'high');
[h,omega] = freqz(b,a,256);
plot (omega/pi,20*log10(abs(h)));grid;
xlabel('\omega/\pi'); ylabel('Gain, dB');
title('Type I Chebyshev Highpass Filter');
32

33
Program-3 (Butterworth IIR BPF Design)

Wp = input('Passband edge frequencies = ');
Ws = input('Stopband edge frequencies = ');
Rp = input('Passband ripple in dB = ');
Rs = input('Minimum stopband attenuation = ');
[N,Wn] = buttord(Wp, Ws, Rp, Rs);
[b,a] = butter(N,Wn);
[h,omega] = freqz(b,a,256);
gain = 20*log10(abs(h));
plot (omega/pi,gain);grid;
xlabel('\omega/\pi'); ylabel('Gain, dB');
title('IIR Butterworth Bandpass Filter');
Note-
(the i/p data are the vector of passband edges Wp= [0.45 0.65], the vector of
stop band edges Ws=[0.3 0.75])
34

35
Program-4 (Butterworth IIR LPF/HPF Design)
clc;
clear all;
close all;

disp('enter the IIR filter design specifications');
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband freq');
ws=input('enter the stopband freq');
fs=input('enter the sampling freq');

w1=2*wp/fs; w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
c=input('enter choice of filter 1. LPF 2. HPF \n ');
if(c==1)
disp('Frequency response of IIR LPF is:');
[b,a]=butter(n,wn,'low','s');
end
CONTD..
36
if(c==2)
disp('Frequency response of IIR HPF is:');
[b,a]=butter(n,wn,'high','s');
end

w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);

figure,subplot(2,1,1);plot(om/pi,m);
title('magnitude response of IIR filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('phase response of IIR filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');

37

38

39
GUI FOR DIGITAL FILTER DESIGN
There are some inbuilt function in MATLAB i.e. fdatool,
sptool, fvtool.
Filter Design with FDATOOL-
40
GUI Window -2
41
IMPLEMENTATION OF IIR FILTER
1- Through TMS-320 C6713 DSP starter KIT
Set up the DSK kit as shown below and load with the c-program
(implementing IIR HPF with 7kHz cutoff Frequency) and the i/p is
given by function generator sinusoid of 11kHz and the o/p is also
shown below:-
42
2- By LABVIEW Digital Filter Design Toolkit
The following figure illustrates the magnitude responses of a
typical LPF designed by the four IIR filter design methods. Each
filter has the same numerator and denominator order values.

43
REFERENCES
Digital Filters and Signal Processing: 3
rd
edition- By Leland B. Jackson
Digital signal processing: 3
rd
edition by John G. Proakis & Manolakis.
Digital Signal Processing-A computer based approach: 2
nd
Edition- by Sanjit
K Mitra
Multirate System & Filter Banks- By P.P. Vaidhyanathan
Digital Signal Processing- By R A Barapate
http://nptel.iitm.ac.in/video.php?subjectId=117102060 (NPTEL Online Video
Course)
Mathworks Webpage
(http://www.mathworks.in/products/signal/description4.html)
Mikroelektronika Webpage
(http://www.mikroe.com/chapters/view/73/chapter-3-iir-filters/)
TMS-320 C6713 DSP Starter KIT User Manual
Wikipedia
National Instrument (http://zone.ni.com/reference/en-XX/help/371325F-
01/lvdfdtconcepts/design_methods/)
EE TIMES (http://eetimes.com/electronics-news/4164517/Practical-
applications-of-digital-filters)
44
45