Finite Impulse Response Filters
Finite Impulse Response Filters
Lecture 5 http://www.ece.utexas.edu/~bevans/courses/realtime
Outline
• Many Roles for Filters
• Convolution
• Z-transforms
• Linear time-invariant systems
Transfer functions
Frequency responses
• Finite impulse response (FIR) filters
Filter design with demonstration
Cascading FIR filters demonstration
Linear phase
5-2
Many Roles for Filters
• Noise removal Bandpass Spectrum In Noise
• Spectral shaping
x[m] System r[m]
Data conversion (lectures 10/11) Model Equalizer
Channel equalization (slide 16-7) (Filter)
Goal is to make
Carrier frequency/phase recovery cascade all-pass
Timing recovery (slide 13-17 & 16-10)
5-3
Spectral Analysis
• Analysis: decompose signal into frequency bands
Graphic equalizer: apply separate gain to each band
Compression: spend more bits on more important
• Synthesis: combine bands into one signal
• Example: Two-band filter bank / wavelet
LPF – averaging: x0[m] = ½ x[m] + ½ x[m-1]
HPF – first-order difference: x1[m] = ½ x[m] - ½ x[m-1]
Exact reconstruction of x[m] is possible through synthesis
x0[m] x0[m] x[m]
x[m] LPF +
x1[m] x1[m]
HPF
5-4
Analysis Synthesis
Finite Impulse Response (FIR) Filter
• Same as discrete-time tapped delay line (slide 3-15)
x[n-1]
x[n] z-1 z-1 … z-1
S y[n]
M-1
Discrete-time
y[n] =å h[m] x[n - m] 5-5
convolution
m=0
Review
Convolution Comparison
• Continuous-time convolution of x(t) and h(t)
y t x t h t x h t d h x t d
t t t
0 Ts 0 Ts Ts 2Ts
Z-transform Definition
• For discrete-time systems, z-transforms play same
role as Laplace transforms do in continuous-time
Bilateral Forward z-transform Bilateral Inverse z-transform
1
H ( z) h n z n h[n] H ( z ) z n 1
dz
n 2 j R
n
Region of convergence: entire a
a n z n
n0 z
z-plane n 0
1 a
• h[n] = d[n-1]
a
if
z
1
1
1 z
H z n 1 z
n
n
n 1 z n z 1
n 1 Region of convergence for
Region of convergence: entire summation: |z| > |a|
z-plane except z = 0 |z| > |a| is the complement
h[n-1] z-1 H(z) of a disk (see next slide)
Region of Convergence
• Region of the complex z- • Four possibilities (z = 0 is
plane for which forward z- special case that may or
transform converges may not be included)
Im{z} Im{z}
Entire Disk
plane Re{z} Re{z}
Im{z} Im{z}
Intersection
Complement of a disk and
of a disk Re{z} complement Re{z}
of a disk
5 - 11
Review
n n 0
n 0
5 - 12
Example: Ideal Delay
• Continuous Time • Discrete Time
Delay by T seconds Delay by 1 sample
x(t) y(t) x[n] y[n]
T z 1
| H | 1 | H | 1
H T H 5 - 13
Linear Time-Invariant Systems
• Fundamental Theorem of Linear Systems
If a complex sinusoid were input into an LTI system, then
output would be input scaled by frequency response of LTI
system (evaluated at complex sinusoidal frequency)
Scaling may attenuate complex sinusoid and shift it in phase
(complex sinusoids are eigenfunctions of LTI systems)
Continuous-time example: see handout F (lowpass RC filter)
Discrete-time derivation: Input x[n] = e j w n into LTI system
¥ ¥
y[n] = å e ( )
å
j w n- m jw n
h[m] e - j w m =e
jw n
h[m] =e H (w )
m=- ¥ m=- ¥
w w
-wstop -wp wp wstop
d
passband delay ( ) H ( ) kdelay
d
Lowpass filter: passes low and attenuates high frequencies
Linear phase / constant group delay: FIR filter whose impulse
response is symmetric or anti-symmetric about its midpoint
• Not all FIR filters exhibit linear phase 5 - 16
FIR Filter Design
• Specify desired piecewise Lowpass Specification
constant magnitude resp. dB
forbidden
Apass
• Lowpass filter example
0
w [0, wpass], magdB [-Apass, Apass] -Apass forbidden
w [wstop, p], magdB ≤ Astop
Achtung!
Transition band unspecified but forbidden
should not amplify Astop
• Symmetric (linear phase) w
wpass wstop p
FIR filter design methods Passband Transition Stopband
Windowing band
Least squares Apass passband tolerance (dB)
Remez (Parks-McClellan) Astop stopband attenuation (dB)
AdB = 20 log10(A) 5 - 17
Example: Two-Tap Averaging Filter
• Input-output relationship h[n] Two-tap averaging filter
1 1
y[ n] x[n] x[n 1]
2 2 ½
• Impulse response
1 1
n
h[n] [n] [n 1] 1 2 3
2 2
• Frequency response x[n-1]
1 1
H e j x[n] z-1
2 2
1 j 2 j 2 j
1 1 1
H e e
e 2
h[0] h[1]
2
j 2
1
H cos e S y[n]
linear phase
2
1
Ð H (w ) =- w 5 - 18
magnitude 2
Example: First-Order Difference
• Input-output relationship h[n] First-order difference
1 1
y[ n] x[n] x[ n 1]
2 2 ½
• Impulse response
1 1
n
h[n] [n] [n 1] 2 3
2 2 -½
• Frequency response
1 1
H e j
2 2 generalized
p 1
1 j 2 j 2 j Ð H (w ) = - w
1 1 1
H e
linear phase
e e 2 2 2
2
p 1 æ ö
æw ö - j 1w æw ö j
p
- j
1
w æw ö jç - w ÷
H w =sin ç ÷j e 2 =sin ç ÷e 2 e 2 =sin ç ÷ e è 2 2 ø
( ) è2 ø è2 ø è2 ø
5 - 19
amplitude
Complementary Frequency Responses
Magnitude
response
Phase
response
Apply 1-D five-tap filter across each row to produce 256 x 260 image
and then apply the same 1-D five-tap filter down each column of 256
x 260 image to produce a 260 x 260 image
Cascading FIR Filters Demo
• DSP First, 2nd ed, ch. 6, cascading FIR Filters
http://dspfirst.gatech.edu/chapters/06firfreq/demos/blockd/index.html
From lowpass filter to highpass filter:
original image blurred image sharpened/blurred image
From highpass to lowpass filter:
original image sharpened image blurred/sharpened image
• Frequencies that are zeroed out can never be
recovered (e.g. DC is zeroed out by highpass filter)
• Order of two LTI systems in cascade can be switched
under the assumption that computations are
performed in exact precision
5 - 23
Cascading FIR Filters Demo
• Input image is 256 x 256 matrix
Each pixel represented by eight-bit number in [0, 255]
0 is black and 255 is white for monitor display
• Each filter applied along row then column
Averaging filter adds five numbers to create output pixel
which requires 3 extra bits (worst case) for each pass
Difference filter subtracts two numbers to create output pixel
which requires 1 extra bit (worst case) for each pass
• Full output precision 16 bits/pixel is maintained
Demonstration uses double-precision floating-point data and
arithmetic (53 bits of mantissa + sign; 11 bits for exponent)
5 - 24
Cascading FIR Filters Demo
• How to compare images pixel by pixel?
Input image is 256 x 256 and output image is 261 x 261
• Unit sample delay example
If observing output y[n], how to x[n] 1
y[n]
z
recover input x[n] exactly?
x[n] y[n]
3 3
2 2
… …
1 1
n n
0 1 2 0 1 2 3
• FIR filters in demo have constant group delay
Remove first 2 rows/columns and last 3 rows/columns 5 - 25
Importance of Linear Phase
• Speech signals • Linear phase crucial
Use phase differences in Audio
arrival to locate speaker Images
Once speaker is located, ears Communication systems
are relatively insensitive to •
Linear phase response
phase distortion in speech
from that speaker Need FIR filters
Used in speech compression Realizable IIR filters
(in cell phones) cannot achieve linear
phase response over all
d = c t
frequencies
5 - 26
Importance of Linear Phase
code
• For images, vital visual information in phase