You are on page 1of 18

SIGNALS AND SYSTEMS: PAPER 3C1

HANDOUT 8.
Dr David Corrigan1 .
Electronic and Electrical Engineering Dept.
corrigad@tcd.ie www.mee.tcd.ie/corrigad

Difference Equations and Digital


Filters
The last topic discussed was A-D conversion. This handout explores what
becomes possible when the digital signal is processed.
DSP (Digital Signal Processing) rose to signicance in the 70s and has
been increasingly important ever since. The rst enabling breakthrough
was the discovery of the Fast Fourier Transform in the last 1960s (enabling calculation of spectra on digital signals) and then the rise of the
transistor and the CPU in the 1970s and 1980s.
Its rapid rise to signicance culminated in the advent of Digital Television/Media and Mobile Communications toward the end of the 20th
century.
The study of DSP now lies somewhere between Electronic Engineering
(where it started) and Statistics, Mathematics, Computer Science and
even Statistical Physics. The computer and computing science is to DSP
engineers what the hammer and nail is to a carpenter.
In the early part of the 1990s DSP chips for implementation of DSP
algorithms were extremely popular: enabling faster computation times
than general purpose CPUs like the Intel 808x series or Motorola, SUN
or Alpha chips. But as clock speeds have increased and recongurable
hardware has developed, the lines between DSP chips, CPUs and IC
chips, have blurred.
1

This handout is based on the set of notes produced by Prof. Anil Kokaram

3C1 Signals and Systems

www.sigmedia.tv

1 DIFFERENCE EQUATION

Introducing digital lters


A digital lter is a construct used in exactly the same way as an analogue
lter.
Consider the gure below showing the share price of Iona over a number
of days. This is a digital signal.
1200

400

1100

350

1000

300

900

Share Price (Euros)

Share Price (Euros)

450

250
200
150
100

700
600
500
400

50
0
0

800

300

10

20

30

40

200
0

50

20

40

60

Days

80

100

120

140

Days

To calculate the average share price over the last 10 days you could do
something like
[
]
1
yn =
xn + xn1 + xn2 + . . . xn9
10
where n is the day, xn is the share price at day n, and yn is the average
price over 10 days.
This is a digital lter called the moving average lter. It can be applied
to every day n to yield a value for the average share price over the last
10 days.
Applying this lter to the Iona signal yields the following.
450

1200

400
1000

Share Price (Euros)

Share Price (Euros)

350
300
250
200
150

800

600

400

100
200

50
0
0

10

20

30

40

50

Days

3C1 Signals and Systems

0
0

20

40

60

80

100

120

140

Days

www.sigmedia.tv

1 DIFFERENCE EQUATION

Consider what the shape of the output signal looks like compared to the
input. What is the dierence? What has been removed? The signal is
smoothed. The moving average lter is a low pass lter.
What happens if we average over more days?
[
]
1
xn + xn1 + xn2 + . . . xn(N 1)
yn =
N

1200

1200

1000

1000

Share Price (Euros)

Share Price (Euros)

For N = 10, 20, 50 we get

800

600

400

200

0
0

800

600

400

200

20

40

60

80

100

120

0
0

140

20

40

60

Days

80

100

120

140

Days
1200

Share Price (Euros)

1000

800

600

400

200

0
0

20

40

60

80

100

120

140

Days

What is happening? Why?


We can apply this lter N = 5, 10 to the rows of a picture to see a similar
eect.

3C1 Signals and Systems

www.sigmedia.tv

2 DIFFERENCE EQUATION

The Dierence Equation: Impulse and Step Response


The moving average lter is an example of a dierence equation. The
dierence equation is to discrete signal processing what the dierential
equation is to analogue signal processing. This dierence equation represents a Linear Time Invariant system and obeys all the usual properties.
Given the input sequence xn = 270.2806, 257.9545, 268.2720, 272.8098, 0, 0,
calculate the output sequence yn , for n = 0 . . . 4 when xn is put through
the lter below (assume zero initial conditions).
[
]
1
yn = xn + xn1 + xn2
3

3C1 Signals and Systems

www.sigmedia.tv

2 DIFFERENCE EQUATION

[
]
1
y0 = x0 + x01 + x02
3
[
]
1
= x0 + x1 + x2
3
[
]
1
= 270.2806 + 0 + 0
3
= 90.09
[
]
1
y1 = x1 + x11 + x12
3
[
]
1
= x1 + x0 + x1
3
[
]
1
= 257.9545 + 270.2806 + 0
3
= 176.08
[
]
1
y2 = x2 + x21 + x22
3
[
]
1
= x2 + x1 + x0
3
]
[
1
= 268.2720 + 257.9545 + 270.2806
3
= 265.50
[
]
1
y3 = x3 + x31 + x32
3
[
]
1
= x3 + x2 + x1
3
[
]
1
= 272.81 + 268.2720 + 257.9545
3
= 266.34
[
]
1
y4 = x4 + x41 + x42
3
[
]
1
= 0 + 272.81 + 268.2720
3
=
3C1 Signals and Systems

www.sigmedia.tv

2.1 Impulse Response

2.1

2 DIFFERENCE EQUATION

Impulse Response
[
]
1
yn = xn + xn1 + xn2
3

What is the impulse response of this lter? Well, just put an impulse in
and see what comes out!
xn = n = 1, 0, 0, 0, 0, . . .

[
]
1
y0 = x0 + x1 + x2
3
[
]
1
= 1+0+0
3

= 1/3
[
]
1
y1 = x1 + x0 + x1
3
= 1/3
[
]
1
y2 = x2 + x1 + x0
3
= 1/3
[
]
1
y3 = x3 + x2 + x1
3
=0

]
[
1
y4 = x4 + x3 + x2
3
=0
So the impulse response hn = (1/3), (1/3), (1/3), 0, 0, 0, . . ..
Because the impulse response has a nite duration (the non-zero values
do not last forever), this kind of lter is called a Finite Impulse Response
ler. (FIR Filter). Another way to remember this is that the output of
the lter is a function only of past inputs.

3C1 Signals and Systems

www.sigmedia.tv

3 FIR FILTERS AND IMPULSE RESPONSE

FIR Filters and Impulse Response


In the moving average FIR lter, the values that multiply the input values
xn1 etc, are all the same. That is the coecients of the lter are all the
same.
We can generalise the idea of the moving average lter to a kind of moving
weighted average lter. For example
1
1
1
yn = xn + xn1 + xn2
4
2
4
This can be expressed as
yn =

bk xnk

k=0

where the lter length is 3 and coecients are bk = [1, 2, 1]/4


In general we can write an FIR lter in that form i.e. the output is a
linear combination of past inputs. Causal FIR lter:

yn =

N
1

bk xnk

k=0

The impulse response of an FIR lter is in fact a sequence made up from


its coecients. We can see that by setting xn = n = 1, 0, 0, 0 and
working as follows.
h0 =
h1 =
h2 =

N
1

k=0
N
1

k=0
N
1

bk x0k = b0 x0 + b1 x1 + . . . = b0
bk x1k = b0 x1 + b1 x0 + . . . = b1
bk x2k = b0 x2 + b1 x1 + b2 x0 + b3 x1 + . . . = b2

k=0

3C1 Signals and Systems

www.sigmedia.tv

4 IIR FILTERS AND IMPULSE RESPONSE

IIR Filters and Impulse Response


Recursive digital lters can be designed in which the output of the lter
depends both on current and previous inputs as well as previous outputs.
For such lters, the impulse response has innite duration and they are
called Innite Impulse Response (IIR) lters.
The general form of a causal IIR lter is as follows.
M
1

am ynm =

m=0

N
1

bk xnk

k=0

Consider the following recursive lter


[
]
1
yn = yn1 + xn
2

(1)

Thus to calculate the current value yn given the previous value yn1 and
the new input xn , we need to calculate the previous total, and add in the
new input xn , before nding the new average by dividing by 2.
This is a recursive lter. It is an IIR lter.

3C1 Signals and Systems

www.sigmedia.tv

4 IIR FILTERS AND IMPULSE RESPONSE

Given the input sequence xn = 4, 3, 2, 1, 0, 0, calculate the output


sequence yn , for n = 0 . . . 4 when xn is input to the lter with dierence
equation as below (assume zero initial conditions).
[
]
1
yn = yn1 + xn
(2)
2

1
1
y0 = y1 + x0
2
2
1
= 4
2
=2
1
1
y1 = y0 + x1
2
2
3
=2+
2
= 2.5
1
1
y2 = y1 + x2
2
2
= 1.25 + 1
= 2.25
1
1
y3 = y2 + x3
2
2
= 1.125 + 0.5
= 1.625

1
1
2
2
= 0.8125 + 0

y4 = y2 + x4

= 0.8125

3C1 Signals and Systems

www.sigmedia.tv

4.1 IIR Impulse Response

4.1

4 IIR FILTERS AND IMPULSE RESPONSE

IIR Impulse Response

Calculate the impulse response for the system dened through the dierence equation below.
[
]
1
yn = yn1 + xn
2
Put xn = n and turn the handle.
[
]
1
yn = yn1 + xn
2
1
1
1=
2
2
1
1
+0=
2
4
1
1
+0=
4
8
1
1
+0=
8
16
1
1

+0=
16
32
1
1

=
32 64

h0 = 0 +
h1 =
h2 =
h3 =
h4 =
h5 =

1
2
1
2
1
2
1
2
1
2

hn = n+1
2
So the impulse response is hn = 21 ,

1 1
1
1
1
4 , 8 , 16 , 32 , 64 ,

...

Very dierent from the FIR lter !


The impulse response of an IIR lter obeys some recursive relationship
This digital IIR lter is also LTI.

3C1 Signals and Systems

10

www.sigmedia.tv

4.1 IIR Impulse Response

4 IIR FILTERS AND IMPULSE RESPONSE

However...
It is important to note that not all recursively dened lters will be IIR.
Consider the recutsive lter
1
1
yn = yn1 + xn xn2
3
3
It has an impulse response as follows
1
1
10=
3
3
1
1
= +00=
3
3
1
1
= +00=
3
3
1
1
= +0 =0
3
3
=0+00=0

h0 = 0 +
h1
h2
h3
h4

h5 = 0
..
.
It is an FIR lter. In fact it is equivalent to the 3-tap moving average
lter from earlier.

3C1 Signals and Systems

11

www.sigmedia.tv

5 STEP RESPONSE

Step Response
Given a dierence equation, calculating the step response is done using
the same idea as with the impulse response.
Just input a step sequence and turn the handle!
Remember discrete step function un = 1, 1, 1, 1, 1, 1, 1, 1, . . .!
Also similar to the case with analogue signals, the step response is the
running sum of the impulse response.
The discrete step function un is the running sum of the discrete delta
function i.e.
n

un =
n
k=0

Therefore if the running sum of a discrete delta is input into a discrete


system, by the principles of LTI superposition , the output should be the
running sum of the system response to a discrete delta function. (i.e. the
running sum of the impulse response)
Step response gn =

hk

k=0

3C1 Signals and Systems

12

www.sigmedia.tv

5.1 Blocks

5.1

5 STEP RESPONSE

Block Diagrams for dierence equations

In the same way that block diagrams are useful for summarising the operation of analogue systems, block diagrams are useful for digital systems.
The main, new operator needed is a shift in time operator. This we will
denote using a box with T in it. Thus if xn is put into T out comes
xn1 . T is a delay operator and shifts the signal that is input by 1
sample.
[
]
1
yn = xn + xn1 + xn2
3

x[n]

x[n-2]

x[n-1]
T

T
1/3

1/3

1/3

y[n]

1
1
yn yn1 = xn xn3
3
3
x[n]

x[n-1]
T

x[n-2]

x[n-3]

1/3

-1/3

y[n]

+
y[n-1]

3C1 Signals and Systems

13

www.sigmedia.tv

6 DIGITAL CONVOLUTION

Digital Convolution
If we know the impulse response of an LTI system, we can calculate the response to any input using convolution. We showed
this from the principles of LTI systems way back when we were
dealing with analogue signals and systems.
The exact same thing happens for digital lters. But this time
... its alot more straightforward because everything is discrete
anyway.
The idea is the same. We can decompose xn into a sum of n
functions. Each of these then pass through the LTI system to
yield impulse responses delayed in time. The nal output is the
sum of these outputs.

3C1 Signals and Systems

14

www.sigmedia.tv

6 DIGITAL CONVOLUTION
x[n]

h[n]

3.5

3.5

2.5

2.5

1.5

1.5

0.5

0.5

0.5

0.5

1.5
4

1.5
4

10

10

x[0]h [n0]

x[0] [n0]
6

5
2

4
3

2
0

1
1

0
1

2
3
4

3
2

10

10

10

10

10

x[1]h [n1]

x[1] [n1]
6

5
2

4
3

2
0

1
1

0
1

2
3
4

3
2

10

x[2]h [n2]

x[2] [n2]
6

5
2

4
3

2
0

1
1

0
1

2
3
4

3
2

10

x[3]h [n3]

x[3] [n3]
6

5
2

4
3

2
0

1
1

0
1

2
3
4

3
2

3C1 Signals and Systems

10

15

www.sigmedia.tv

6 DIGITAL CONVOLUTION
x[0]h [n0]

x[0] [n0]
6

5
2

4
3

2
0

1
1

0
1

2
3
4

3
2

10

10

10

10

10

10

x[1]h [n1]

x[1] [n1]
6

5
2

4
3

2
0

1
1

0
1

2
3
4

3
2

10

x[2]h [n2]

x[2] [n2]
6

5
2

4
3

2
0

1
1

0
1

2
3
4

3
2

10

x[3]h [n3]

x[3] [n3]
6

5
2

4
3

2
0

1
1

0
1

2
3
4

3
2

10

x[n]

y[n]

3.5
7
3
6
2.5
5
2
4
1.5
3
1
2
0.5
1
0
0
0.5
1
1
2
1.5
4

3C1 Signals and Systems

10

16

www.sigmedia.tv

6.1 Convolution Expression

6.1

6 DIGITAL CONVOLUTION

Digital Convolution: The Expression

Given a system impulse response sequence hn and an input sequence


xn .
We can express any input sequence xn as a sum of discrete delta
functions

xk kn
xn =
k=

Each delta function yields an impulse response as the output


INPUT OUTPUT
n hn
x0n x0hn
x1n1 x1hn1
x0n + x1n1 x0hn + x1hn1

xk kn
xk hnk
k=

k=

HENCE THE CONVOLUTION SUM


yn =

xk hnk

k=

OR
yn =

hk xnk

k=

3C1 Signals and Systems

17

www.sigmedia.tv

6.1 Convolution Expression

6 DIGITAL CONVOLUTION

Looks a lot like the statement for the FIR lter dierence equation: with bk = hk . Hence the impulse response for an FIR lter
is actually its coecients.

yn =

hk xnk

k=

Usual notation : yn = xn hn Obeys all the same rules of linearity,


superposition, associativity as convolution integral.
[xn + gn] hn = xn hn + gn hn
xn hn = hn xn
Usual simplications for causality. System response hn causal
means hn = 0for n < 0. So we can change the lower limit to 0.

yn =
hk xnk
k=0

Signal causal means that xnk = 0 for n k < 0 i.e. for k > n
so we can change the upper limit to n.
yn =

hk xnk

k=0

yn =

hk xnk

k=0

FIR time domain lter implementation is the same as convolution.


When people talk about FIR lter coecients and FIR impulse
response . . . its in fact the same thing.

3C1 Signals and Systems

18

www.sigmedia.tv

You might also like