design and implementation of iir filter

45
DESIGN AND IMPLEMENTATION OF IIR FILTER By- SAURABH SHUKLA M.Tech (CE) ICE2012005

Upload: saurabh-shukla

Post on 12-Apr-2015

117 views

Category:

Documents


2 download

DESCRIPTION

IIR FILTER

TRANSCRIPT

Page 1: Design and Implementation of IIR Filter

DESIGN AND

IMPLEMENTATION OF

IIR FILTER

By-

SAURABH SHUKLA

M.Tech (CE)

ICE2012005

Page 2: Design and Implementation of IIR Filter

2

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

Page 3: Design and Implementation of IIR Filter

3

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.

Page 4: Design and Implementation of IIR Filter

4

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.

Page 5: Design and Implementation of IIR Filter

5

TWO APPROACHES

Design analoglowpass filter

Apply Freq. bandtransformation

s-->s

Apply filtertransformation

s-->z

DesiredIIR filter

Design analoglowpass filter

Apply filtertransformation

s-->z

Apply Freq. bandtransformation

z-->z

DesiredIIR filter

Approach 1, used in Matlab

Approach 2, study

Page 6: Design and Implementation of IIR Filter

6

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 doesn’t 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.

Page 7: Design and Implementation of IIR Filter

7

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 practiceButterworth lowpassChebyshev lowpass (Type I and II)Elliptic lowpass

Page 8: Design and Implementation of IIR Filter

8

IIR Filter Types

Butterworth Chebyshev Type I

Elliptic

Chebyshev Type II

Page 9: Design and Implementation of IIR Filter

9

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)

)(sH a )(zH

j

DESIGN OF IIR FILTER FROM ANALOG FILTER

Page 10: Design and Implementation of IIR Filter

10

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.

N

k

kk

M

k

kk

a

s

s

sA

sBsH

0

0

)(

)()(

k k

M

kk

k

k

N

kk

k

k dt

txd

dt

tyd

00

)()(

Page 11: Design and Implementation of IIR Filter

11

Maximum passband deviation= maximum stopband magnitude = 1/A Pass band Frequency (normalized) Stop band Frequency (normalized)

21

1

s

pp F

s

ss F

Page 12: Design and Implementation of IIR Filter

12

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.

Page 13: Design and Implementation of IIR Filter

13

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

T

TnTynTy

dt

tdy

nTt

)()()(

T

nyny )1()(

dttdy )(

k

k

T

zs

11

Page 14: Design and Implementation of IIR Filter

14

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

sTz

1

1

Tjz

1

1

frequency digital

frequency analog

Page 15: Design and Implementation of IIR Filter

15

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.

Page 16: Design and Implementation of IIR Filter

16

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.

T

eeer TjjT

and

sTez TjTj eere

Page 17: Design and Implementation of IIR Filter

17

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=esT

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

ka k

TjsH

TzH

21)(

Frequency-domain aliasing formula

TkTk /)12(/)12(

Page 18: Design and Implementation of IIR Filter

18

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.

Page 19: Design and Implementation of IIR Filter

19

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);

Zooming the resulting plot shows that the analog and digital impulse responses are the same.

Page 20: Design and Implementation of IIR Filter

20

Program-2clc

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');

Page 21: Design and Implementation of IIR Filter

21

Page 22: Design and Implementation of IIR Filter

22

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.

Page 23: Design and Implementation of IIR Filter

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

121

1

sT

sTz

z

z

Ts

Page 24: Design and Implementation of IIR Filter

24

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.

Page 25: Design and Implementation of IIR Filter

25

The Ha(jΩ) compressed in frequency by this transformation.

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

If |Ha(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.

Page 26: Design and Implementation of IIR Filter

26

MATLAB PROG FOR BILINEAR TRANSFORMATION

Program-1clc

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');

Page 27: Design and Implementation of IIR Filter

27

Page 28: Design and Implementation of IIR Filter

28

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).

Page 29: Design and Implementation of IIR Filter

29

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

ssH

1)(

)()( tuth ][][ nunh

11

1)(

zzH

11

1

)(

)()(

zzX

zYzH

)(]1)[( 1 zXzzY ][]1[][ nxnyny

Page 30: Design and Implementation of IIR Filter

30

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)

Page 31: Design and Implementation of IIR Filter

31

Page 32: Design and Implementation of IIR Filter

32

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');

Page 33: Design and Implementation of IIR Filter

33

Page 34: Design and Implementation of IIR Filter

34

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])

Page 35: Design and Implementation of IIR Filter

35

Page 36: Design and Implementation of IIR Filter

36

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…..

Page 37: Design and Implementation of IIR Filter

37

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-->');

Page 38: Design and Implementation of IIR Filter

38

Page 39: Design and Implementation of IIR Filter

39

Page 40: Design and Implementation of IIR Filter

40

GUI FOR DIGITAL FILTER DESIGN There are some inbuilt function in MATLAB i.e.

“fdatool, sptool, fvtool”. Filter Design with FDATOOL-

Page 41: Design and Implementation of IIR Filter

41

GUI Window -2

Page 42: Design and Implementation of IIR Filter

42

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:-

Page 43: Design and Implementation of IIR Filter

43

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.

Page 44: Design and Implementation of IIR Filter

44

REFERENCES Digital Filters and Signal Processing: 3rd edition- By Leland B. Jackson Digital signal processing: 3rd edition by John G. Proakis & Manolakis. Digital Signal Processing-A computer based approach: 2nd 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)

Page 45: Design and Implementation of IIR Filter

45