You are on page 1of 31

Chapter 5:

Finite Impulse Response (FIR) Filters


So far, we have considered signals and their mathe-
matical representations. In this chapter, we will have
a look at one type of system, called a filter.
A filter is a system that is designed to remove some
component or modify some characteristic of a signal.
Through filtering, we try to minimize noise and/or
interference. Analog or digital filters can be designed.
As an example of digital computation, first we will
learn about digital filtering, in particular, finite im-
pulse response (FIR) filters. In Ch.8, will extend
this to infinite impulse response (IIR) filters.
sampling system: input is CT, output is DT

reconstruction system: input is DT, output is CT

We will study DT systems where both the input


and the output are DT signals.
1
Discrete-Time (Digital) Systems:
A discrete-time system is a computational process
for transforming the input sequence into the output
sequence. Such systems can be implemented using
digital computation and they can be designed to
modify signals in many useful ways.
block diagram representation

input output
sequence sequence
notation:
y[n] = T {x[n]}
ex:
y[n] = x[n] (identity system)
y[n] = αx[n] where α ∈ R (scaling system)
y[n] = αx[n] + β α, β ∈ R
y[n] = x[n − no] no ∈ Z (ideal delay system)
y[n] = |x[n]| (absolute value system)
y[n] = (x[n])2 (squaring system/squarer)
y[n] = min(x[n − 1], x[n])
..
2
Discrete-Time (Digital) System

x(t) x[n] y[n] y(t)


A-to-D COMPUTER D-to-A
input output
sequence sequence
 concentrate on the computer
 operate on x[n] to get y[n] n: the time index
 various processing algorithms
 software: MATLAB
 hardware: DSP chips, VLSI
 DSP: digital signal processing

Digital Filtering

x(t) x[n] y[n] y(t)


A-to-D FILTER D-to-A
input output
sequence sequence
 one type of system is a filter
 focus on digital filters
 process discrete-time sequences
 functions of n: the “time index”
 input sequence: x[n]
 output sequence: y[n]

3
Rockland Digital Filter (1971)

For the price of a small house, you could have one of these.

The TMS32010 (1983)

first PC plug-in board from Atlanta Signal Processors Inc.

4
Digital Cell Phone (ca. 2000)

plays video as well

5
We will start with averaging filters.
When/Why do we perform averaging?
Suppose we have N items xi to average.
These could be students’ grades, temperature, stock
market values, exchange rates on different days, etc.
We can perform simple averaging:
N
1 X
xav = xi
N i=1
where each item is assigned equal importance or weight
(wi = N1 ) or weighted averaging where the items
have different weights wi:
XN XN
xav = wixi where wi = 1
i=1 i=1
Averaging is used when data fluctuate and must be
smoothened prior to interpretation.
Filtered Stock Signal

INPUT

OUTPUT

50-pt averager

6
We will look at running (moving) average fil-
ters where the average of two or more consecutive
values of the input sequence are taken to produce a
new sequence of output values.
Consider 3-point averaging where each value of
the output sequence is the sum of three consecutive
input sequence values divided by three:
1
y[n] = (x[n] + x[n + 1] + x[n + 2]) −∞ < n < ∞
3
Such an equation relating the output sequence of the
filter to its input sequence is called a difference equa-
tion. It provides a complete description of the system
(the filter).

1
for n = 0: y[0] = 3 (x[0] + x[1] + x[2])
1
for n = 1: y[1] = 3 (x[1] + x[2] + x[3])
1
for n = 2: y[2] = 3 (x[2] + x[3] + x[4])
1
for n = 3: y[3] = 3 (x[3] + x[4] + x[5])
..

We will discuss the representation, implementation,


and analysis of discrete-time finite impulse response
(FIR) filters.

7
Consider the following sequence which we will use
as the input sequence to the 3-pt averager:

Discrete-Time Sequence

 x[n] is a LIST of NUMBERS


 INDEXED by “n”

STEM PLOT

finite-length (finite-duration) sequence

support: the time interval over which the sequence


values are nonzero
For the given sequence,
the support is 0 ≤ n ≤ 4 (five units).

8
3-point Averaging System
 add 3 consecutive numbers and divide by 3
 repeat this for each “n”
Make a TABLE

n=0
n=1

input sequence

output sequence

9
The output sequence also has finite support:
−2 ≤ n ≤ 4 (seven units).
It has longer duration than the input sequence
(two more non-zero values).
Also, it is smoother than the input sequence.
In general, averaging has two effects:
• smoothening
• spreading out in time
Smoothening is characteristic of the running av-
erage FIR filter.
The choice of the output indexing is arbitrary. In
the above example, y[n] becomes non-zero before the
input starts. This would be undesirable if the input
sequence values came directly from an A-to-D con-
verter, as is common in audio SP applications.
In general, we can include samples of the input from
the past, present, or future. The current indexing
value of n is considered to be the present.
Based on this, we can design causal versus non-
causal filters. The distinction is based on whether
any future value of the input sequence is being used
in the filter’s difference equation or not.
In a causal filter, only the past and/or present
10
values of the input sequence can be used.
In a non-causal filter, at least one future value of
the input sequence is used. Whether the past and/or
present values are being used is irrelevant.
The distinction is important in real-time applications
where we have only access to past and present data,
but not the future.

Past, Present, Future

“n” is TIME

Is the 3-pt averager we considered above causal?


How can we modify it so that it becomes causal?

11
causal 3-pt averager:
1
y[n] = (x[n] + x[n − 1] + x[n − 2]) −∞ < n < ∞
3

Another 3-pt Averager

 Uses “PAST” VALUES of x[n]


 Important if “n” represents real time
 when x[n] & y[n] are streams of data

This is backward averaging whereas forward


averaging is used in the non-causal 3-pt averager.
However, both of these filters are biased. If n in-
dexes the present time, the non-causal 3-pt averager
takes two samples from the future around the present
value whereas the causal 3-pt averager takes two sam-
ples from the past. The former gives more weight to
the future whereas the latter gives more emphasis to
the past.
12
Can we design a 3-pt averager which is not biased
for the past or the future? If so, how?

centralized 3-pt averager:


1
y[n] = (x[n − 1] + x[n] + x[n + 1]) −∞ < n < ∞
3
Is the above filter causal?

The General FIR Filter Model:


general difference equation:
M
X
y[n] = bk x[n − k]
k=0

in expanded form:

y[n] = bo x[n] + b1 x[n − 1] + b2 x[n − 2] + . . .


. . . + bM −1 x[n − M + 1] + bM x[n − M ]

filter coefficients:
{bk } = {bo, b1, . . . , bM −1, bM } (constants)
M : order of the filter
L: length of the filter
(same as the no. of filter coefficients)
L=M +1 Is this filter causal?

13
General FIR Filter

 slide a window across x[n]

x[n-M] x[n]

• Since future values of the input are not involved,


the filter is causal and the output cannot start before
the input becomes non-zero.
• The causal FIR filter uses x[n] and the past M
values of the input to compute the output. Computa-
tion of y[n] involves x[n], x[n − 1], x[n − 2], . . . , x[n −
M ].
• The filter is completely defined once the filter co-
efficients {bk } are known.
• If the coefficients are not identical, then the model
defines a weighted running average of M + 1 samples.

14
ex: Given the set of filter coefficients
{bk } = {−2, 1, −1, 2, 4}
bo b1 b2 b3 b4
for a causal FIR filter, write the difference equation of
the filter. What is the order and what is the length?

solution: The filter has five coefficients.


Therefore, L = 5 and M = L − 1 = 4.
4
X
y[n] = bk x[n − k]
k=0
= bo x[n] + b1 x[n − 1] + b2 x[n − 2] + b3 x[n − 3] + b4 x[n − 4]
= −2 x[n] + (1) x[n − 1] + (−1) x[n − 2] + 2 x[n − 3] + 4 x[n − 4]
= −2 x[n] + x[n − 1] − x[n − 2] + 2 x[n − 3] + 4 x[n − 4]

Which of the three 3-pt averagers that we have, are


consistent with the above causal FIR filter model?
Only the causal 3-pt averager:
1
y[n] = (x[n] + x[n − 1] + x[n − 2]) − ∞ < n < ∞
3
1 1 1
= x[n] + x[n − 1] + x[n − 2]
3 3 3
1 1 1
{bk } : 3 , 3 , 3
M =2
L = M + 1 = 3 (3 filter coefficients)
15
Recall the following from our overview:
additive-noise signal observation model:
observed signal = true/ideal signal + noise or
interference
This is the most commonly used model to repre-
sent signals contaminated by noise and/or interfer-
ence. There is a component which is the signal of
interest and another component which is not of in-
terest. This second component interferes with the
observation of the desired signal.

ex:
(
1 2πn π
n

(1.02) + cos
2 8 + 4 for 0 ≤ n ≤ 40
x[n] =
0 otherwise
In this example, the desired component is the slowly
increasing exponential component (the first term).
The undesired component is the sinusoidal interfer-
ence (the second term).

16
Filtering Example

 causal 3-point averager


2
1
y 3 [ n ]= ∑
k=0
()
3
x [n−k ]

{b_k}={1/3,1/3,1/3} M=2 L=M+1=3


bo b1 b2 (order) (length)

the effect: reduces A slightly

Applying the 3-pt Averager

USE PAST VALUES

17
Filtering Example

 causal 7-point averager


6
1
y 7 [ n ]= ∑
k=0
()
7
x [ n−k ]

{b_k}={1/7,1/7,1/7,1/7,1/7,1/7,1/7} M=6 L=M+1=7


bo b1 b2 b3 b4 b5 b6 (order) (length)

the effect:
removes cosine by making its amplitude (A) much smaller

Applying the 7-pt Averager

CAUSAL: use previous

LONGER OUTPUT

18
Filtered Stock Signal

INPUT

OUTPUT

50-pt averager

Filters as Building Blocks of Systems

OUTPUT
x[n] + y[n]
FILTER FILTER
INPUT +

FILTER

 build up complicated filters


 from simple modules
 ex: module might be a 3-pt FIR filter

19
Special Input Signals

 x[n] = SINUSOID FREQUENCY RESPONSE (LATER)


 x[n] has only one NON-ZERO VALUE

δ [n]=
UNIT-IMPULSE
{ }
1 n=0
0 n≠0
1

Unit Impulse Sequence δ [n]

n=3
δ[n] is NON-ZERO
when its argument
is equal to ZERO

20
Decomposition of Input


Use shifted & scaled IMPULSES to write x[n]
x [n ]=2δ[n ]+4δ[n−1 ]+6δ[n−2 ]+4δ[ n−3 ]+2δ[n−4 ]

Sum of Shifted & Scaled Impulses

This formula ALWAYS works

21
General FIR Filter

 filter coefficients {bk}


 define the filter M
y [n ]=∑ b k x [ n−k ]
k=0
 for example, b k= {3, −1, 2, 1 }
3
y [ n ]=∑ b k x [ n−k ]
k= 0
3x [ n ]−x [ n−1 ]+2x [n−2 ] +x [ n−3 ]

FIR Impulse Response

 filter coefficients = impulse response

M M
y [n ]=∑ b k x [ n−k ] h[ n ]= ∑ b k δ [n−k ]
k=0 k=0

22
Hardware Structures

M
x[n]
FILTER
y[n]
y [n ]=∑ b k x [ n−k ]
k=0

 internal structure of “filter”


 What components are needed?
 How do we “hook” them together?
 signal flow graph/diagram/chart

Hardware Atoms

 add, multiply, & store M


y [n ]=∑ b k x [ n−k ]
k=0

y [n ]=x 1 [ n ]+x 2 [ n ]
y [n ]=βx [n ]

y[n]=x [n−1 ]

23
FIR Structure
M
 direct form
SIGNAL FLOW GRAPH
y [n ]=∑ b k x [ n−k ]
k=0

System Properties

x[n] y[n]
SYSTEM

 time invariance
 linearity
 causality (“no output prior to input”)
 stability

24
Time Invariance

 key idea:
 time-shifting the input will cause the same
time-shift in the output
 equivalently,
 we can prove that
 the time origin (n=0) is picked arbitrarily

x[n]--->y[n]
x[n-no]--->y[n-no] for all n and all n_o

Testing Time-Invariance

25
Linearity

 Linearity involves two essential properties:


 scaling/homogeneity
 doubling x[n] will double y[n]
 tripling x[n] will triple y[n]
 superposition
 adding two inputs gives an output that is the
sum of the individual outputs

Testing Linearity

26
Linear Time-Invariant (LTI) Systems

 LTI: Linear & Time-Invariant


 completely characterized by:
 impulse response: h[n]
 convolution: y[n] = x[n]*h[n]
 The “rule” defining the system can always be re-
written using a convolution sum.
 FIR example: h[n] is same as bk

27
Cascade Systems

 Does the order of S1 & S2 matter?


 No, LTI systems can be rearranged !!!
 What are the filter coefficients? {bk}

S1 S2

Cascade Equivalent

 Find equivalent h[n] for a cascade:

S1 S2

S2 S1

28
dconvdemo: MATLAB GUI

29
Convolution Example
(Tabular Method)
h[ n ]=δ [n ]−δ [ n−1 ]+2δ[ n−2]−δ [ n−3 ]+δ [n−4 ]
x [n ]=u[n ]
n −1 0 1 2 3 4 5 6 7
x[n] 0 1 1 1 1 1 1 1 ...
h[n] 0 1 −1 2 −1 1 0 0 0
h[ 0]x[ n] 0 1 1 1 1 1 1 1 1
h[ 1] x[ n−1] 0 0 −1 −1 −1 −1 −1 −1 −1
h[ 2]x[ n−2] 0 0 0 2 2 2 2 2 2
h[ 3]x[ n−3] 0 0 0 0 −1 −1 −1 −1 −1
h[ 4] x[n−4] 0 0 0 0 0 1 1 1 1
y[n] 0 1 0 2 1 2 2 2 ...

30
Exercise
 FIR filter is “first difference”
 y[n] = x[n] - x[n -1]
 express the system output as a convolution
 need impulse response

h[ n ]=δ[n ]−δ [ n−1 ]


 then, another way to compute the output:

y [n ]=( δ [ n ]−δ[ n−1] )∗x [n ]

Exercise

FIR filter is “first difference''


 y[n] = x[n] - x[n-1]
 input is “unit-step sequence”

u[ n]= { }
1 n≥0
0 n<0
 find y[n]
y[n ]=u[ n ]−u [n−1 ]=δ [n ]

31

You might also like