0% found this document useful (0 votes)
48 views32 pages

We Should Forget About Small Efficiencies, Say About 97% of The Time: Premature Optimization Is The Root of All Evil. - D. Knuth

The document discusses a lecture on digital filter design. It covers FIR and IIR filter design, different types of filters, and MATLAB's digital filter design tool. It also discusses the direct form and transposed direct form implementations of FIR filters, comparing their hardware implementations and computational complexities. An example of a running average FIR filter is provided.

Uploaded by

Bala Murugan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views32 pages

We Should Forget About Small Efficiencies, Say About 97% of The Time: Premature Optimization Is The Root of All Evil. - D. Knuth

The document discusses a lecture on digital filter design. It covers FIR and IIR filter design, different types of filters, and MATLAB's digital filter design tool. It also discusses the direct form and transposed direct form implementations of FIR filters, comparing their hardware implementations and computational complexities. An example of a running average FIR filter is provided.

Uploaded by

Bala Murugan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Lecture 8

Today: FIR filter design


IIR filter design
Filter roundoff and overflow sensitivity

Announcements: Team proposals are due tomorrow at 6PM


Homework 4 is due next thur.
Proposal presentations are next mon in 1311EECS.

References: See last slide.

Please keep the lab clean and organized.


Last one out should close the lab door!!!!

We should forget about small efficiencies, say about 97% of the time: premature
optimization is the root of all evil. — D. Knuth

EECS 452 – Fall 2014 Lecture 8 – Page 1/32 Thurs – 10/4/2012


Proposal presentations: Mon Sept 29

Schedule
I Presentations will occur from 6PM to 10:00PM in EECS 1311.
I Your team spokesperson must sign the team up for a 30 minute slot
(20 min presentation).
I All team members must take part in their team’s presentation.
I You may stay for any or all other portions of the presentation
meeting.
I Team should arrive at least 20 minutes before their time slot.
I Team must use powerpoint or other projectable media for your
presentations.
I The presentation must cover each section of the proposal.
I You should put your presentation on a thumb drive and/or email
copy to hero before the meeting.

EECS 452 – Fall 2014 Lecture 8 – Page 2/32 Thurs – 10/4/2012


Digital filters: theory and implementation

I We have seen the need for several types of analog filters in A/D
and D/A
I Anti-aliasing filter
I Reconstruction (anti-image) filter
I Equalization filter
I Anti-aliasing and reconstruction require cts time filters
I Discrete time filters are used for spectral shaping
post-digitization.
I There will be round-off error effects due to finite precision.

EECS 452 – Fall 2014 Lecture 8 – Page 3/32 Thurs – 10/4/2012


Different types of filter transfer functions

öeEÑFö äçïé~ëë öeEÑFö ÜáÖÜé~ëë

M Ñ M Ñ

Ä~åÇ=êÉàÉÅí
öeEÑFö Ä~åÇé~ëë öeEÑFö
EåçíÅÜF

M Ñ M Ñ

EECS 452 – Fall 2014 Lecture 8 – Page 4/32 Thurs – 10/4/2012


Matlab’s fdatool for digital filter design

Figure: Lowpass, highpass, bandpass, bandstop (notch) in Matlab’s fdatool

EECS 452 – Fall 2014 Lecture 8 – Page 5/32 Thurs – 10/4/2012


FIR vs IIR Digital filters
Output depends on current and previous M input samples.

y[n] = b0 x[n] + b1 x[n − 1] + b2 x[n − 2] + · · · + bM x[n − M ] .

This is a FIR moving sum filter.


Output depends on current input and previous N filter outputs.

y[n] = x[n] − a1 y[n − 1] − a2 y[n − 2] − · · · − aN y[n − N ] .

This is an IIR all-pole or autoregressive filter.


Output depends on current and previous M input samples and the
previous N filter outputs.

y[n] = b0 x[n] + b1 x[n − 1] + b2 x[n − 2] + · · · + bM x[n − M ] −


a1 y[n − 1] − a2 y[n − 2] − · · · − aN y[n − N ] .

This is the general pole-zero IIR digital filter equation.

EECS 452 – Fall 2014 Lecture 8 – Page 6/32 Thurs – 10/4/2012


Filter design procedure

I Specification of filter requirements.


I Selection of FIR or IIR response.
I Calculation and optimization of filter coefficients.
I Realization of the filter by suitable structure.
I Analysis of finite word length effects on performance.
I Implementation.
I Testing/validation.

The above steps are generally not independent of each other. Filter
design is usually an iterative process. The FIR–IIR response
selection step is a major design choice.

EECS 452 – Fall 2014 Lecture 8 – Page 7/32 Thurs – 10/4/2012


FIR block diagram (again)
0

-1
Y = (b0 + b1 z −1 + b2 z −2 + · · · + bM z −M )X
= b0 X + b1 (z −1 X) + b2 (z −2 X) + · · · + bM (z −M X)

-1

Y 2
= b0 + b1 z −1 + b2 z −2 + · · · + bM z −M
X

This is sometimes referred to as the direct form (DF).




This implements well in a DSP with one or two MAC


units. Can do all the MACs accumulating into a bit- -1
rich accumulator. Once all the sums are formed trun-
cate/round then saturate and finally use/store the re-
sult.
Well suited to a pipelined implementation
EECS 452 – Fall 2014 Lecture 8 – Page 8/32 Thurs – 10/4/2012
Transposed FIR block diagram

ñ ÄM ó
Y = (b0 + b1 z −1 + b2 z −2 + · · · + bM z −M )X
= b0 X + (b1 X)z −1 + (b2 X)z −2 + · · · + (bM X)z −M
òJN
ÄN
Y
= b0 + b1 z −1 + b2 z −2 + · · · + bM z −M
X
òJN
This is sometimes referred to as the transposed direct
form (TDF) or the broadcast form. ÄO

Well suited for cascade implementation.

ÄjJN

òJN
Äj
EECS 452 – Fall 2014 Lecture 8 – Page 9/32 Thurs – 10/4/2012
FIR Direct form hardware implementation

Xilinx Application Note XAPP219 (v1.2) October 25, 2001

EECS 452 – Fall 2014 Lecture 8 – Page 10/32 Thurs – 10/4/2012


FIR Transpose form hardware implementation

Xilinx Application Note XAPP219 (v1.2) October 25, 2001

EECS 452 – Fall 2014 Lecture 8 – Page 11/32 Thurs – 10/4/2012


Run time complexity?
Q. How many MULT and ADD operations are needed to calculate

y[n] = b0 x[n] + b1 x[n − 1] + · · · + bN −1 x[n − N ]?

A. Could be as high as N ADDs and N + 1 MULTs. However


simplifications can occur
I May be able to group certain operations to reduce
computations.
I Some coefficients may be equal, e.g., b0 = b1 = . . . = bN

y[n] = b0 (x[n] + x[n − 1] + . . . + x[n − N ])

Only a single MULT required.


I Values of coefficients or data may be integer powers of two, e.g.
bn = 2qn . In this case MULTs can be performed by register
shifts.

EECS 452 – Fall 2014 Lecture 8 – Page 12/32 Thurs – 10/4/2012


The running average filter
Running average filter (b0 = b1 = b2 = · · · = bN = 1/(N + 1)) has
transfer function

1 + z −1 + · · · + z −N
H(z) = .
N +1

This is the sum of a geometric series so has closed form

1 − z −(N +1) 1
H(z) =
1 − z −1 N + 1

Expressing this in (digital) frequency domain (z = ej2πf ) gives

1 − e−j2π(N +1)f 1 sin[π(N + 1)f ] 1


H(f ) = −j2πf
= e−jπN f .
1−e N +1 sin(πf ) N +1

Because of the periodicity of ej2πf we need only focus on range


−1/2 ≤ f < 1/2.
Note that H(f ) has linear phase
EECS 452 – Fall 2014 Lecture 8 – Page 13/32 Thurs – 10/4/2012
Running average filter magnitude
sin(πP f/fs )
P sin(πf/fs )
1

0.8

Number of FIR filter coeffi-


magnitude, P=2

0.6

0.4
cients:
0.2

0
P = N + 1.
−0.5 −0.4 −0.3 −0.2 −0.1 0 0.1 0.2 0.3 0.4 0.5

1
Distance to first zero: 1/P .
0.8 Nominal bandwidth: 1/P .
0.6 First side peak at: 3/(2P ).
magnitude,P=4

0.4
First lobe level:
0.2

0
P dB
-0.5 -0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5

4 -11.4
1

0.8
8 -13.0
0.6 16 -13.3
magnitude,P=8

0.4
∞ -13.5
0.2

0
-0.5 -0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5
f/f s

EECS 452 – Fall 2014 Lecture 8 – Page 14/32 Thurs – 10/4/2012


More general FIR filter design

Recall our equiripple design example (Lecture 2):


I Low pass filter.
I fs =48000 Hz.
I Bandpass ripple: ±0.1 dB.
I Transition region 3000 Hz to 4000 Hz.
I Minimum stop band attenuation: 80 dB.

EECS 452 – Fall 2014 Lecture 8 – Page 15/32 Thurs – 10/4/2012


fdatool’s solution

EECS 452 – Fall 2014 Lecture 8 – Page 16/32 Thurs – 10/4/2012


fdatool’s magnitude, phase and group delay

EECS 452 – Fall 2014 Lecture 8 – Page 17/32 Thurs – 10/4/2012


Impulse response (coefficient values)

The filter impulse response has a delayed ”peak”


Delay of peak is approximately 1.7 msecs
Delay corresponds to 80 integer units (1/2 of total length of filter). Note
that the impulse response is symmetric about the peak

EECS 452 – Fall 2014 Lecture 8 – Page 18/32 Thurs – 10/4/2012


FIR filters can be designed with linear phase

Objective: design FIR filter whose magnitude response |H(f )|


meets constraints.
Can design filter to have linear phase over passband.

There are four FIR linear-phase types depending upon

I whether the number of coefficients is even or odd,


I whether the coefficients are even or odd symmetric.

EECS 452 – Fall 2014 Lecture 8 – Page 19/32 Thurs – 10/4/2012


Linear phase and FIR symmetry
Given M -th order FIR filter h[n]. Assume that h[n] has even or
odd symmetry about an integer m:
Even symmetry condition: There exists an integer m such
that h[m − n] = h[n].
Odd symmetry condition: There exists an integer m such
that h[m − n] = −h[n].

Then h[n] is a linear phase FIR filter with transfer function.

H(f ) = |Hm (f )|e−j2πf m+jφ

where Hm (f ) is the transfer function associated with


hm [n] = h[n + m] and φ = 0 if even symmetric while φ = π/2 if odd
symmetric.

Why? Because, Hm (f ) is the DTFT of a sequence {hm [n]}n that is


symmetric about n = 0.
Note: Symmetry condition cannot hold for (causal) IIR filters.
EECS 452 – Fall 2014 Lecture 8 – Page 20/32 Thurs – 10/4/2012
IIR filters

B(z) b0 + b1 z −1 + · · · + bM z −M
H(z) = =
A(z) 1 + a1 z −1 + · · · + aN z −N

1
= (b0 + b1 z −1 + · · · + bM z −M ) ×
1 + a1 z −1 + · · · + aN z −N

1
= × (b0 + b1 z −1 + · · · + bM z −M )
1 + a1 z −1 + · · · + aN z −N

Without loss of (much) generality we will set M = N .

EECS 452 – Fall 2014 Lecture 8 – Page 21/32 Thurs – 10/4/2012


Comments on IIR

Most authors use bi ’s as the numerator coefficients and ai ’s as the


denominator coefficients.

Writing the transfer function numerator first suggests implementing the


zeros (the FIR part) first followed by the poles. Such a implementation is
called direct form 1.

Writing the transfer function denominator first suggests implementing


the poles (the IIR or feedback part) first followed by zeros. Such an
implementation is called direct form 2.

EECS 452 – Fall 2014 Lecture 8 – Page 22/32 Thurs – 10/4/2012


Direct forms 1 and 2
Direct Form 1 (DF1) Direct Form 2 (DF2)
H(z) = B(z) × 1 H(z) = 1 × B(z)
A(z)
A(z)
0 0

n, d, d, n,
-1 -1 -1 -1

n,1 d,1 d,1 n,1

n,2 d,2 d,2 n,2


-1 -1 -1 -1

n, d, d, n,


2 2 2 2

   

n, d, d, n,
-1 -1 -1 -1

n, d, d, n,

EECS 452 – Fall 2014 Lecture 8 – Page 23/32 Thurs – 10/4/2012


Canonical direct form 2
0 0

d, n,
-1 -1 -1

d,1 n,1

d,2 n,2 2
-1 -1 -1

d, n, 2 2
2 2 2

  - 

d, n,
-1 -1 -1

d, n,

a) Non-canonical Direct Form 2. b) DF2 in canonical form.

EECS 452 – Fall 2014 Lecture 8 – Page 24/32 Thurs – 10/4/2012


Comments on canonical form

Have assumed N = M . If M > N then append a FIR filter of


the necessary size. If M < N then set the appropriate b
values equal to zero.

The canonical form is canonical in the sense that it uses the


minimum number of delay stages.

We will often simply assume that direct form 2 filters are in


canonical form.

EECS 452 – Fall 2014 Lecture 8 – Page 25/32 Thurs – 10/4/2012


Stability and minimum phase
I The transfer function (TF) is stable if the zeros (the transfer
function poles) of

1 + a1 z −1 + · · · + aN z −N

lie within the unit circle in the z-plane.


I The locations of the zeros of

b0 + b1 z −1 + · · · + bM z −M

do not affect the stability of the TF. The zeros can lie
anywhere on the z-plane.
I A TF that has all of its numerator zeros inside of the unit
circle is said to have minimum phase.
I Minimum phase TFs are useful when designing inverse filters,
e.g. FM pre-emphasis and de-emphasis.

EECS 452 – Fall 2014 Lecture 8 – Page 26/32 Thurs – 10/4/2012


IIR in Z-domain and time domain

Fig. 6.14 from Lyons, ”Understanding DSP”

EECS 452 – Fall 2014 Lecture 8 – Page 27/32 Thurs – 10/4/2012


IIR vs FIR. Which is better?
All pole IIR lowpass filter (requires 5 multiply-adds):

y[n] = 1.194y[n−1]−0.436y[n−2]+0.0605x[n]+0.121x[n−1]+0.0605x[n−2]

Fig. 6.14 from Lyons, ”Understanding DSP”

EECS 452 – Fall 2014 Lecture 8 – Page 28/32 Thurs – 10/4/2012


IIR vs FIR. Which is better?(ctd)

Use fdatool:
5th order IIR lowpass filter (requires 10 multiply-adds):
10 tap FIR lowpass filter (requires 10 multiply-adds)
Magnitude (dB) and Phase Responses
Magnitude (dB) and Phase Responses 0 0.0164

0 −0.145 −10 −0.770

−20 −1.557
−10 −0.8635
−30 −2.343

Magnitude (dB)
−20 −1.5819

Phase (radians)
Magnitude (dB)

−40 −3.130

−30 −2.3003 −50 −3.917

−60 −4.703
−40 −3.0188
−70 −5.490
−50 −3.7372 −80 −6.277

−60 −4.4556 −90 −7.064

0 5 10 15 20 0 5 10 15 20
Frequency (kHz) Frequency (kHz)
,

Left: FIR equiripple 10 tap. Right: IIR elliptical 5th order.

EECS 452 – Fall 2014 Lecture 8 – Page 29/32 Thurs – 10/4/2012


Comments

I Both filters have passband cutoff freq fs /10 = 4800 and unity
average magnitude response over passband.
I Both filters have the same number of multiply-adds.
I IIR has flatter passband, steeper rolloff, and lower sidelobes.
I Q. So why not always use IIR designs?
I A. IIR have disadvantages
I (causal) IIR filters have non-linear phase response.
I IIR filters can be very sensitive to coefficient quantization.
I IIR filters can suffer from severe arithmetic overflow at internal
nodes.

EECS 452 – Fall 2014 Lecture 8 – Page 30/32 Thurs – 10/4/2012


Summary of what we covered today

I FIR filter forms (Direct Form and Transposed Direct Form) and
linear phase
I IIR filters forms (Direct Form 1, Direct Form 2 and Canonical
forms)
I IIR vs FIR filter designs

EECS 452 – Fall 2014 Lecture 8 – Page 31/32 Thurs – 10/4/2012


References

”Transposed Form FIR Filters,” Vikram Pasham, Andy Miller, and


Ken Chapman, Xilinx Application Note XAPP219 (v1.2), Oct 25,
2001.
”Understanding digital signal processing,” R. Lyons, 2006.
”Digital signal processing,” Proakis and Manolakis, 3rd Edition.

EECS 452 – Fall 2014 Lecture 8 – Page 32/32 Thurs – 10/4/2012

You might also like