elen 5346/4304 dsp and filter design fall 2008 1 lecture 11: lti fir filter design instructor: dr....

52
ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: [email protected] Office Hours: Room 2030 Class web site: http://ee.lamar.ed u/gleb/dsp/index.h tm

Upload: baldric-williamson

Post on 23-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

1

Lecture 11: LTI FIR filter design

Instructor: Dr. Gleb V. Tcheslavski

Contact: [email protected]

Office Hours: Room 2030

Class web site: http://ee.lamar.edu/gleb/dsp/index.htm

Page 2: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

2

Preliminary considerations

1

0

( )M

kk

k

H z h z

FIR filter:

unit-pulse responsetransfer function

(11.2.1)

Here M-1 is the filter order.M is the number of filter’s coefficients. Assuming that M is odd:

1

10

00 0

( ) ; 1

Mk

kMk k

kk

b zH z h z a

a

BTW, using our “rational notation”:

(11.2.2)

1 2 ( 2) ( 1)0 1 2 2 1

31 1 112

2 2 21

1022

( ) ... M MM M

MM M MMk k

M k kMk k

H z h h z h z h z h z

z h h z h z

(11.2.3)

Page 3: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

3

Preliminary considerations

3 311 12 2

22 21 1

0 02

311 12

22 21 1

02

( )

M MMM M kk

M k M kk k

MMM M kk

M k M kk

H z z h h z h z

z h h z h z

For an FIR filter to have a linear phase:

*1k M kh h

That means an even symmetry of the coefficients.

(11.3.1)

(11.3.2)

Remember: FIR filters are always stable (no poles other than at the origin)!

Page 4: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

4

Preliminary considerations

Since the filter is stable:3

11 1222 2

1

31 2

21

0

02

2

( )

12 cos

2

( )

k k

MMM M j kj jj

MM

j

M k k

kj h j hM k

k

k

jc

H e

Me

e h h

h h

e e e e

e

k h

R

Here is a real function of frequency.( )jcR e

(11.4.1)

1

2

Mjj j

cH e e R e

As a result of symmetry:

(11.4.2)

Page 5: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

5

Preliminary considerations

Therefore:

10

21

02

jc

j

jc

Mif R e

H eM

if R e

Generalized linear phase

We can use to design ANY amplitude of frequency response: LPF, HPF, BPF,…

jcR e

When changes sign, the phase undergoes an abrupt change of 1800 jcR e

In M is even: 2

2

0

1( ) 2 cos

2

M

jc k k

k

MR e h k h

(11.5.1)

(11.5.2)

Page 6: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

6

Preliminary considerations

*1k M kh h

3

2

0

1( ) 2 sin ;

2

M

js k k

k

MR e h k h M is odd

An FIR filter will also have a linear phase in the case of odd symmetry of filter coefficients (antisymmetric impulse response), i.e.:

It can be shown that

2

2

0

1( ) 2 sin ;

2

M

js k k

k

MR e h k h M is even

(11.6.1)

(11.6.2)

(11.6.3)

1

2

Mj

j jsH e e jR e

Therefore:

(11.6.4)

BTW:

H j differentiator

H j sign Hilbert transformer

(11.6.5)

(11.6.6)

Page 7: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

7

Preliminary considerations

Thus:

10

2 23 1

02 2

js

j

js

Mif R e

H eM

if R e

Generalized linear phase

(11.7.1)

Summarizing, a unit-pulse response of a GLP FIR filter must satisfy:*1k M kh h (11.7.2)

1

0

( )M

kk

k

H z h z

(11.7.3)

1

2, , , ,...

,

jMj cj

js

R e LPF HPF BPF BSFH e e

jR e differentiators Hilbert transformers

(11.7.4)

We only need to specify (M-1)/2 (odd M) or M/2 unique coefficients (even M).

Page 8: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

8

Preliminary considerations

Combining (11.7.2) and (11.7.3), we arrive at:

1

( 1

1 1* * ( 1)1

0 0 0

)1

( 1) * *

0

*

( 1

1

)M M M

k k m Mk M k m

k k m

MM m

mm

M

H z h z h z m M k h z

z h z z H z

(11.8.1)

0jhas a zero at z z re *

0

1 1 jhas a zero at z ez r

-1 -0.5 0 0.5 1

-1

-0.5

0

0.5

1

4

Real PartIm

agin

ary

Par

t

Example: if M = 5:1 2 3 4

0 1 2 3 4( )H z h h z h z h z h z

Has two pairs of reciprocal zeros.

firls(4,[0 0.25],[1 0]);

Page 9: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

9

Preliminary considerations

There are four types of real GLP FIR filters:

indicate “structural zeros”

Type I: symmetric hn, odd M (number of coefficients) – even order.

Type II: symmetric hn, even M

Type III: antisymmetric hn, odd M

Type IV: antisymmetric hn, even M

Page 10: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

10

Preliminary considerations

1. For M = 4, symmetrical pulse response ( Type II FIR):

1 2 3 1 2 30 1 2 3 0 1 1 0( )H z h h z h z h z even symmetry h h z h z h z

1 1 01 0( ) 0z

h hH hz h

2. For M = 4, antisymmetrical pulse response ( Type IV FIR):

1 2 3 1 2 30 1 2 3 0 1 1 0( )H z h h z h z h z odd symmetry h h z h z h z

1 1 01 0( ) 0z

hH h hz h

3. For M = 5, antisymmetrical pulse response ( Type III FIR):

1 2 3 4 1 2 3 40 1 2 3 4 0 1 2 1 0( )H z h h z h z h z h z odd symmetry h h z h z h z h z

0 1 2 1 0 210( ) 0

zh h h h hH z h

1 0 1 2 1 0 2 00( )z

h h hH z h h h

(11.10.1)

(11.10.2)

(11.10.3)

Thi

s is

whe

re s

truc

tura

l zer

os c

ome

from

Page 11: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

11

Preliminary considerations

As a result of structural zeros…

Type II FIR HPF would have a zero at - specs will be violated!Type III FIR HPF would have a zero at - specs will be violated!Type IV FIR LPF would have a zero at 0 - specs will be violated!

If something like tis happens, increase or decrease the FIR order to change the type of your filter.

We need to be careful with selection of filter orders!

Page 12: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

12

1. Least-square error minimization

The desired magnitude response (something we specify):

,j j n

d d nDTFTn

H e h e (11.12.1)

Filter coefficients could be found as:

,

1

2j j n

d n dh H e e d

Example: Ideal LPF

,

2 sin1

2

s

2

i1

n

2

c c c

c

j n j ncj n

Lc

Pc

Fc

n

j ne eh e

n

nd

j n

(11.12.2)

(11.12.3)

Not causal, infinite length!

We need to preserve the main features while making the filter causal.

Page 13: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

13

1. Least-square error minimization

The filter specified by (11.12.3) has an infinite impulse response. Therefore, we need to truncate it at some point to make an FIR filter. As a criterion for such truncation, we need to minimize the approximation error (the difference between the desired and the truncated frequency responses).

The magnitude of the frequency response of the “truncated filter”:

,

Uj j n

t t nn L

H e h e

Where L and U are points at which the pulse response was truncated.

Therefore, the objective is to find a finite-duration impulse response sequence, whose DTFT would approximate the desired frequency response.

(11.13.1)

We need to minimize the least-square integral error of approximation.

Page 14: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

14

1. Least-square error minimization

In particular:

21min

2j j

R t dH e H e d

1

2 2 2

, , , ,

2

1, ,

U L

t n d n dR t n d n n d nn L n n Un

h h h h h h

Apparently, to minimize R (LS error), we select ht,n = hd,n for n = L…U. Moreover, GLP requires symmetry of filter coefficients, therefore L = -U.

The best finite length approximation of the ideal infinite length impulse response in the LS error sense is obtained by truncation.

To make the resulting FIR causal, we need to shift it by L radians.

(11.14.1)

(11.14.2)

Page 15: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

15

1. Least-square error minimization

Relating the point of truncation to the FIR filter order: L = (M – 1)/2

,

1sin

21

2

cc

LP FIR n

c

Mn

hM

n

Note: filter length M (number of filter coefficients) can be both even or odd.

(11.15.1)

-50 0 50-0.1

0

0.1

0.2

0.3

n

h n

0 20 40 60 80 100-0.1

0

0.1

0.2

0.3

n

h n

0 0.2 0.4 0.6 0.8 1-4000

-2000

0

Normalized Frequency ( rad/sample)

Pha

se (

degr

ees)

0 0.2 0.4 0.6 0.8 1-100

-50

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (

dB)

Non-causal Causal

Page 16: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

16

2. Windowing effects

We can view the truncation of the infinite impulse response of an ideal filter as windowing. In frequency domain, this operation is equivalent to convolution of a frequency response of the window function with the frequency response of an ideal filter.

, ,t n d n nh h w

( )1

2j j j

t dH e H e W e d

from the Modulation theorem:

-1 -0.5 0 0.5 1-0.2

0

0.2

0.4

0.6

0.8

1

1.2

/

|Ht()|

|W()|

|Hd()|

(11.16.1)

(11.16.2)

Gibbs phenomenon(comes from truncated

Fourier series)

Ripples of equal magnitude in PB and SB

Transition band – another window artifact

W R:

Page 17: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

17

2. Windowing effects: window types

As discussed previously, different window functions can be used…

Window MLW (4/M) PSL (dB) TB (2/M) Max SB ripple (dB)

Rectangular 0.9 -13 0.9 -21

Hanning 2 -31 3.1 -44

Hamming 2 -41 3.3 -53

Blackman 3 -57 5.5 -74

Window properties Filter properties

Fixed windows:

Page 18: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

18

2. Windowing effects: window types

1, 0,1,... 1RnW n M Rectangular:

Hanning:

Hamming:

21 2 21 cos sin , 0,1,... 1

2 1 1Nn

n nW n M

M M

20.54 0.46cos , 0,1,... 1

1Mn

nW n M

M

2 40.42 0.5cos 0.08cos , 0,1,... 1

1 1Bn

n nW n M

M M

Blackman:

(11.18.1)

(11.18.2)

(11.18.3)

(11.18.4)

Page 19: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

19

2. Windowing effects: window types

2

0

0

21 1

1, 0,1,... 1K

n

nI

MW n M

I

Kaiser window:

(11.19.1)

2

01

2( ) 1

!

m

m

xI x

m

Where: (11.19.2)

Normally, 15-20 terms in the summation are sufficient.

Note: if = 0, WnK = Wn

R.

Adjustable windows:

Page 20: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

20

2. Windowing effects: window types

TB (2/M) Max SB ripple (dB)

2 1.5 -29

3 2.0 -37

4 2.6 -45

5 3.2 -54

7 4.5 -72

8 5.1 -81

Properties:

Kaiser window is the most frequently used for the FIR filter design.

Hanning

Hamming

Blackman

Page 21: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

21

2. Windowing: experimental design

For the given transition band:

2s p

f

Stop-band attenuation: 20lg sA

Order estimate:7.95

114.36

AM

f

Adjustable parameter: 0.4

0.1102 ( 8.7) 50

0.5842 ( 21) 0.07886 ( 21) 21 50

0 21

A A dB

A A A

A

(11.21.1)

(11.21.2)

(11.21.3)

(11.21.4)

M controls transition band, changes ripples.

Note: in practice, ripples in SB and PB are approximately equal. If this does not hold, need to select minimum of s, p.

Page 22: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

22

2. Windowing: experimental design

Example 11.1: design an FIR LPF using a Kaiser window for the following specs:

0.3 ; 0.5 ; 40 minp s A dB SB attenuation

The transition band:0.5 0.3

0.12 2s pf

7.95 40 7.951 1 23.32

14.36 14.36 0.1

AM

f

Order:

0.40.5842 ( 21) 0.07886 ( 21) 3.4A A Parameter:

We select M = 24, = 4. The filter is given by (11.15.1) with the cutoff frequency:

0.42

p sc

The resulting filter is a type II FIR which is ok for LPF.

,

sin;c

t n n

nh w L n L

n

The transfer function:

Page 23: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

23

3. Frequency sampling

The desired frequency response

1

,0

Mj j n

d d nDTFTn

H e h e

can be specified by its frequency samples at equally spaced (discrete) frequencies:

2k k

M

Where

(11.23.1)

(11.23.2)

10,1,... ,

22

0,1,... ,2

MM odd

kM

M even

= 0:

0

0.5

no offset

offset by M

(11.23.3)

(11.23.4)

2/M

2/M/M

= 0.5:

Page 24: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

24

3. Frequency sampling

The sampled frequency response will be:

21 ( )

, ,0

, 0,1,... 1k

M j k nj Md k d d n

n

H H e h e k M

Evaluating IDFT:

21 ( )

,0

1, 0,1,... 1

M j k nM

n d kk

h H e n MM

Therefore, we can compute the filter coefficients from the specified M frequency samples.

(11.24.1)

(11.24.2)

Since hn is real: *k M kH H

Since hn is symmetric, we only need to specify either (M+1)/2 (M is odd) or M/2 (M is even) frequency samples to determine the pulse response.

(11.24.3)

Page 25: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

25

3. Frequency sampling

We can rewrite the FIR filter frequency response (11.7.4) as:

1

21

1

2 21

,

, V

Mjj

r n M nj

Mj

jr n M n

H e e symmetric h h typesH e

H e e antisymmetric h h types

2 ; 0,1,... 1k

kk M

M

Sampled at the frequencies

the response becomes:

2 1

2 22M

j kM

k rH H k eM

(11.25.1)

(11.25.2)

(11.25.3)

Page 26: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

26

3. Frequency sampling

Here:0 n

n

symmetric h

antisymmetric h

For simplicity, we specify the following set of real frequency samples:

21 ; 0,1,... 1k

k rG H k k MM

Therefore: 2 1

2 2

Mj k

Mj kk kH G e e

0 0; 4 ...

1 2different cases

(11.26.1)

(11.26.2)

(11.26.3)

Page 27: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

27

3. Frequency sampling

Case 1: 0

0 : 2n

k

symmetric h

no offset k M

2 1 2

2 2

M M kj k j k jj k j kM M Mk

k

Mkk

j

k G e e GH Ge e e e

2 2 2 21 1 1

0 0 0 1

2 ( ) 2( )

01 1

2 1 2 1

20

1

1 1 1

1

1

k k kM M U Mj kn j j kn j j kn j j knM M M M M M M

k k k kk k k k U

k M kU Uj j kn j j M k nM M M M

k M kk k

U j k n j k nM

n

Mk k

k

H e G e e G e e G e eM M M

G G e e G e eM

G G e G eM

h

22

0

1

1

2 1

1 2 12 cos ; 0,1,...

2

1

1

;

U

kk

Uj j n j j n

k

G G

e

k n n MM M

e e e

(11.27.1)

(11.27.2)

Page 28: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

28

3. Frequency sampling

21k

k rG H kM

Since hn is real:*

k M kH H

2 1 2 1*2 2

2 2M Mj k j M kM M

r rH k e H M k eM M

Since Hr is real:

2 1 2 1

2 2

2 212 2

2 2

2 2 2

2 21 1

M Mj k j M kM M

r r

Mj j j M

r r r

k kj M k j k jr r

H k e H M k eM M

H k H M k e e H M k eM M M

H k H M k e e eM M

(11.28.1)

(11.28.2)

(11.28.3)

(11.28.4)

Page 29: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

29

3. Frequency sampling

Therefore:k M kG G (11.29.1)

The number of coefficients (frequency samples) to be specified:

1;

2

1;2

Modd M

UM

even M

- forced zero at z = -1(11.29.2)

ˆ 0jnH e DFT h

Since the unit-pulse response is already evaluated, we can estimate the corresponding frequency response as its zero-padded DFT:

and check whether the specifications are satisfied.

Page 30: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

30

3. Frequency sampling

Case 2: 0

1 2 : 2 ( 0.5)n

k

symmetric h

ffset k M

0.5

2 11

2k

k rG H kM

0.50

2 2 1 12sin ; 0,1,... 1

2 2

U

n kk

h G k n n MM M

1;

2

1;2

Modd M

UM

even M

(11.30.1)

(11.30.2)

(11.30.3)

The desired frequency samples:

Page 31: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

31

3. Frequency sampling

Case 3: 1

0 : 2n

k

antisymmetric h

no ffset k M

0.5

21k

k r

kG H

M

2 2

1

21

1 2 11 2 sin ;

2

Mn

n M kk

h G G k n M is evenM M

(11.31.1)

(11.31.2)

The desired frequency samples:

1 2

1

2 2 1sin ;

2

M

n kk

kh G n M is odd

M M

(11.31.3)

Page 32: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

32

3. Frequency sampling

0.50

2 2 1 1cos ; 0,1,... 1

2 2

U

n kk

h G k n n MM M

Case 4:

1

0.5 : 2 0.5n

k

antisymmetric h

ffset k M

0.5

2 0.51k

k r

kG H

M

(11.32.1)

The desired frequency samples:

3;

2

1;2

Modd M

UM

even M

(11.32.2)

(11.32.3)

Page 33: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

33

3. Frequency sampling

0 0.1 0.2 0.3 0.4 0.50

0.2

0.4

0.6

0.8

1

1.2

fractional frequency

|H(

)|

actual

specified

We specify the desired response in the SB and the PB only…

The stopband attenuation in this case (only SB and PB samples are given) is approximately -20 dB.

0 0.1 0.2 0.3 0.4 0.50

0.2

0.4

0.6

0.8

1

1.2

fractional frequency

|H(

)|

actual

specified

Alternatively, we can add transition sample(s) and make the frequency response smoother.

The stopband attenuation would be: for one TB sample: approximately -40 dB.for two TB sample: approximately -60 dB.for three TB sample: approximately -80 dB.

Page 34: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

34

3. Frequency sampling

The transition band sample(s) “optimized” experimentally are:

# of TB samples Sample(s) value(s) SB attenuation, dB

T1 0.3789795 – if = 00.3570496 – if = 0.5

~ 40

T2 [0.1065 0.5886] ~ 60

T3 [0.025779 0.251635 0.723071][0.030957 0.27557 0.744348]Note: only one of them is correct.

~ 80

T4 [0.006061 0.09324 0.4082 0.82097] ~ 100

Effects of adding TB sample(s) are increased SB attenuation and wider TB. These samples must be optimized for the situation.Selection of the offset can help too.Note: we can specify any desired frequency response at the samples but not in between! Ultimately, we can view all frequency samples as the TB samples, which leads to an optimal (equiripple) design.

Page 35: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

35

4. Optimal equiripple design

We are interested in a LP filter satisfying the following requirements:

1 1 ;

;

jp r p

js r s

H e PB

H e SB

Considering four FIR types:

Type 1: symmetric pulse response, odd M. 1n M nh h

The real-valued frequency response:

13

2

0

2

01

2

1 12 co

2s

2cs o

M

jr

M

kM

nknH e a k

M Mh h n k n

1

2

1

2

, 0

12 , 1,2,...

2

M

k

Mk

h k

a Mh k

(11.35.1)

(11.35.2)

(11.35.3)

(11.35.4)

Page 36: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

36

4. Optimal equiripple design

Type 2: symmetric pulse response, even M. 1n M nh h

The real-valued frequency response:

2

2 2

0 1

1 2 12 cos cos

2 2 2

M M

jr n k

n k

M MH e h n k n b k

2

12 , 1,2,...

2k Mk

Mb h k

(11.36.1)

(11.36.2)

(11.36.3)

1

2

0

cos cos2

M

jr k

k

H e b k

0 1

1

12 2

0.5

2 ; 1,2,... 22

2

k k k

M M

b b

Mb b b k

b b

Or:

Where:

(11.36.4)

(11.36.5)

Page 37: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

37

4. Optimal equiripple design

Type 3: antisymmetric pulse response, odd M.

The real-valued frequency response:

3 1

2 2

0 1

1 12 sin sin

2 2

M M

jr n k

n k

M MH e h n k n c k

1

2

12 , 1,2,...

2k Mk

Mc h k

(11.37.1)

(11.37.2)

(11.37.3)

3

2

0

sin cos

M

jr k

k

H e c k

3 1

2 2

1 1

0 2 1

2 ; 2 5 2

0.5

M M

k k k

c c

c c c k M

c c c

Or:

Where:

(11.37.4)

(11.37.5)

1n M nh h

Page 38: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

38

4. Optimal equiripple design

Type 4: antisymmetric pulse response, even M.

The real-valued frequency response:

2

2 2

0 1

12 sin sin

2 2

M M

jr n k

n k

M MH e h n k n d k

2

2 , 1,2,...2k M

k

Md h k

(11.38.1)

(11.38.2)

(11.38.3)

2

2

0

sin cos2

M

jr k

k

H e d k

3

2 2

1

0 1 1

2

2 ; 2 3 2

0.5

M M

k k k

d d

d d d k M

d d d

Or:

Where:

(11.38.4)

(11.38.5)

1n M nh h

Page 39: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

39

4. Optimal equiripple design

Therefore, we can express the frequency response for all FIR types as:

j j jrH e Q e P e

Where:

Filter type Q(ej) P(ej)

1: M odd 1

2: M even

3: M odd

4: M even

1n M nh h

1n M nh h

1n M nh h

1n M nh h

cos2

sin2

sin

1 2

0

cosM

kk

a k

2 2

0

cosM

kk

b k

3 2

0

cosM

kk

c k

2 2

0

cosM

kk

d k

(11.39.1)

0

cosL

jk

k

P e k

(11.39.2)

Page 40: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

40

4. Optimal equiripple design

The desired frequency response:

1

0j

dr

in PBH e

in SB

We can compute and compare it to . Adjusting P() and

selecting filter type, we can obtain the desired frequency characteristic.

jdrH e j

rH e

We introduce the weighting function on the approximation error:

1j

s p

in SBW e

in PB

If s < p – bigger error in the passband is allowed.

(11.40.1)

(11.40.2)

Page 41: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

41

4. Optimal equiripple design

The weighted approximation error:

ˆ ˆ

j j j j j j jdr r dr

jdrj j j

j

j

j j jdr

W e H e H e W e H e Q e P e

H eW e Q e P e

E e

W e H e P eQ e

(11.41.1)

Where the modified weighting function and the modified desired frequency response are:

ˆ j j jW e W e Q e

ˆj

drjdr j

H eH e

Q e

(11.41.2)

(11.41.3)

Page 42: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

42

4. Optimal equiripple design

For the given error function E(e j), the Chebyshev (mini-max) approximation problem is to determine the filter parameters k that minimize the maximum absolute error over the frequency bands of interest:

0

ˆ ˆmin max min max cosk k

Lj j j

dr kover overS S

k

E e W e H e k

(11.42.1)

Usually, the frequency bands of interest are specified as:

S PB SB (11.42.2)

a disjoint union of the passband and the stopband: 0 - p and s - (for a LPF). That is we “ignore” the transition band. More precisely speaking, error over the TB will not be optimized.

The solution of this problem can be found via the alternation theorem.

Page 43: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

43

4. Optimal equiripple design

The alternation theorem

A necessary and sufficient conditions for to be

unique and best approximation to in S is that the error function

E(e j) exhibit at least L + 2 extremal frequencies in S. That is, there must

exist at least L + 2 frequencies {i}, such that:

0

cosL

jk

k

P e k

ˆ j

drH e

1 2 2... L

max , 1,2,..., 2ij j

SE e E e i L

1i ij jE e E e

I.e., error alternates in sign between two successive extremal frequencies.

(11.43.1)

(11.43.2)

(11.43.3)

Page 44: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

44

4. Optimal equiripple design: Example

Example 11.2: design a LPF. Since both the desired frequency response Hdr and the weighting function W are piecewise constants:

0

j jrj j j

dr r

dE e dH edW e H e H e

d d d

Consequently, the frequencies {i} that correspond to the peaks of the error function E(e j) also correspond to the peaks of Hr(e j), i.e., where the frequency response meets the specified error tolerance. Since Hr(e j) is a polynomial of degree L:

0 0 0 0

cos cos cosL L k L

n kjr k k nk k

k k n k

H e k

(11.44.1)

(11.44.2)

Hr(e j) has at most L-1 local minima and maxima and, therefore, at most L+1 extremal frequencies (bandages) since we add = 0 and = . Furthermore, the band-edge frequencies p and s are also extrema of the error function. Therefore, E(e j) has at most L+3 extremal frequencies.

Page 45: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

45

4. Optimal equiripple design: Example

However, from the alternation theorem, there are at least L+2 extremal frequencies in E(e j). Thus the error function for the LPF design will have either L+2 or L+3 (extra ripple filters) extremal frequencies.

At the specified extremal frequencies n:

ˆ ˆ 1 ; 0,1,... 1n n nnj j j

drW e H e P e n L

Here represents the maximum value of the error function E(e j).

alternations

1 ˆ 0,1,... 1ˆ

n n

n

n

j jdrj

P e H e n LW e

0

1 ˆcos 0,1,... 1ˆ

n

n

nLj

k n drjk

k H e n LW e

or alternatively:

(11.45.1)

(11.45.2)

(11.45.3)

Page 46: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

46

4. Optimal equiripple design: Example

We can consider the {k} and as the unknown (to be determined) design parameters for the given extremal frequencies. Therefore:

0 0

1 1

11

00 0 0

11 1 1

1

1 1 1

ˆ ˆ1 cos cos 2 cos 1

ˆ ˆ1 cos cos 2 cos 1

ˆˆ1 cos cos 2 cos 1

L

LL

j jdr

j jdr

LL jj

drL L L

L W e H e

L W e H e

H eL W e

(11.46.1)

Note: initially, both the design parameters and the extremal frequencies are unknown. The above system can be solved by the iterative algorithm (Remez exchange algorithm):1)Guess the set of L + 1 extremal frequencies;2)Solve for {k} and ;3)Determine the error function as in (11.39.1);4)Determine the new set of L + 1 extremal frequencies and go to 2)…Keep running until E(e j) - convergence.

Page 47: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

47

4. Optimal equiripple design

Alternatively, we can compute analytically [Rabiner ‘75]:

0 1 1

0 1 1

0 1 1

10 1 1

ˆ ˆ ˆ...

( 1)...

ˆ ˆˆ

L

L

j j jdr dr L dr

LL

j j j

H e H e H e

W e W eW e

where:

1

0

1

cos cos

L

kn k nn k

(11.47.1)

(11.47.2)

Therefore, the initial guess of the L + 2 extremal frequencies allows us to compute the maximum value of the error . Thus:

0

, cosL

j kk

k

P e x x

(11.47.3)

Page 48: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

48

4. Optimal equiripple design

Since we know that the polynomial at the points xn = cos n has the values:

( 1)ˆ , 0,1,... 1ˆ

n n

n

nj j

dr jP e H e n L

W e

the Lagrange interpolation formula can be used, which leads to

0

0

k

Lj

k kj k

L

k kk

P e x xP e

x x

Here: cos

cosk k

x

x

0

1L

kn k nn kx x

(11.48.1)

(11.48.2)

(11.48.3)

(11.48.4)

(11.48.5)

Page 49: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

49

4. Optimal equiripple design

Having the solution for P, we can compute the error function:

ˆ ˆj j j jdrE e W e H e P e

on a dense set of frequency points. Usually, 16M frequency points are sufficient. If the error exceeds the estimated tolerance , we select a new set of frequencies corresponding to the L+2 largest peaks of error function and the procedure starts from (11.45.1). New set of critical frequencies will lead to increased . As a result, the algorithm produces the optimal solution with equal ripples in the PB and the SB for the given M.

The order of the filter can be estimated as:

20lg 13

ˆ 114.6 2

s p

s p

M

(11.49.1)

(11.49.2)

Page 50: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

50

Summary

Historically, the window-based algorithm was the first proposed method for FIR design. Its major disadvantage is the lack of precise control of the critical frequencies, such as s and p. These values, in general, depend on the type of the window and the filter length M.

The frequency sampling method is attractive since it specifies an arbitrary frequency response at the uniformly spaced frequencies and the transition band is a multiple of 2/M. However, no control for the response in between the samples.

The Chebyshev approximation method provides a total control of the filter specifications and may lead to an equiripple design. This way, the approximation error is spread evenly across the PB and SB, which leads to an optimal filter. This method is usually preferred.

Page 51: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

51

Remarks and conclusions

Since orders of FIR filters can be quite high, these filters can introduce a considerable group delay, which is approximately M/2.

The following Matlab functions are handy for FIR design:fir1 – FIR filter design using the windowing methodfir2 – FIR filter design via the frequency sampling methodfirpm – Parks-McClellan optimal equiripple FIR designfirpmord - Parks-McClellan optimal equiripple FIR order estimator

Page 52: ELEN 5346/4304 DSP and Filter Design Fall 2008 1 Lecture 11: LTI FIR filter design Instructor: Dr. Gleb V. Tcheslavski Contact: gleb@ee.lamar.edu gleb@ee.lamar.edu

ELEN 5346/4304 DSP and Filter Design Fall 2008

52

Appendix: the ideal transfer functions

LPF:

,

sin,c

LP n

nh n

n

HPF: ,

1 , 0

sin, 0

c

HP n c

n

h nn

n

2 1,

sin sin, 0c c

BP n

n nh n

n n

2 1

,

1 2

1 , 0

sin sin, 0

c c

BS n

c c

nh

n nn

n n

BPF:

BSF:

(11.52.1)

(11.52.2)

(11.52.3)

(11.52.4)