Es3c5 2021 Notes v1 5
Es3c5 2021 Notes v1 5
Es3c5 2021 Notes v1 5
Version 1.5
Dr Adam Noel
adam.noel@warwick.ac.uk
School of Engineering
University of Warwick
Autumn 2020
Contents
Acknowledgements 2
Preface 3
1 Introduction 9
ii
CONTENTS iii
V Appendices 191
A Mathematical Background 192
These notes are Version 1.5 for the 2020-2021 academic year.
• 1.4: Corrected the notation of Example 18.2 to clarify that the M th order FIR
filter has M + 1 (and not M ) unknown filter coefficients.
• 1.3: Reworded objective of Lesson 6 Question 2 to state that we want the am-
plitude of a complex exponential component of the output and not a trigono-
metric component.
• 0.0: Initial version copied from notes for 2019-2020 academic year.
1
Acknowledgements
These notes were developed with the support of materials from previous offerings of
this and similar modules in the School of Engineering at the University of Warwick:
• Lecture slides for ES3C5 by Prof Weisi Guo and Dr Christos Mias.
2
Preface
0.2 Welcome
Welcome to ES3C5: Signal Processing. This document is the official set of notes to
supplement the lecture videos. It is written as a series of lessons that correspond
to the lectures. Each lesson will align with one to several video lectures. The video
lectures focus on highlighting the main theoretical ideas and presenting example
problems that are worked on in the videos. These notes are intended to provide
a precise, self-contained presentation of all technical material needed for ES3C5,
including formal definitions and descriptions of the theoretical ideas. These notes
also present additional applications, example problems, code snippets, etc.
This raises two important questions:
1. Do you need to read these notes if you watch the video lectures?
2. Do you need to watch the video lectures if you read these notes?
In practice, depending on your personal approach to learning, you may find the
videos more helpful than the notes, or vice versa. Nevertheless, it is recommended
that you use both.
A few reasons to watch the video lectures:
• Keep on top of the material. While you may have been exposed to many of
the mathematical concepts in previous modules, ES3C5 covers a lot of ground
and ties together a lot of ideas from a design perspective. The video lectures
will help you keep up.
3
4 CONTENTS
• Emphasize what’s most important. The video lectures won’t cover all of
the material in the same detail as the notes, but they will highlight the most
important content and the most challenging ideas that you will be assessed
on.
• Preview lecture material. The notes can help set the stage for what will
be covered in the video lectures.
• The notes are self-contained. There will be no concept that you need to
know for the exam that isn’t in the notes (though the coursework may require
you to do some additional research). This can make the notes very useful for
exam revision.
• More accessible than the textbooks. Although the notes are self-contained,
they are written to be more concise and accessible than the module textbooks.
Furthermore, the scope of the module is larger than what can be found in any
one of the module textbooks.
• Additional study aides. The notes include many example problems; many
but not all of these will be covered during video lectures and revision classes.
Example 0.1
Examples will be clearly labelled as such and will appear inside a rounded
box.
Extra content will be clearly labelled as such and will appear inside a blue
box. Any content inside of a blue box is beyond the scope of the module. Con-
tent might include advanced topics, extended applications, or just tangential
comments that are provided for insight or reference.
These notes were originally written for the 2019-2020 academic year and have
been updated for the 2020-2021 academic year. Feedback on the content and sug-
gestions for future years are welcome.
6. Evaluate signals and systems using laboratory test and measurement equip-
ment.
The learning objectives mention signals but not what kinds of signals (besides
deterministic vs random). This module and these notes are organized according
to the signal type. We will consider deterministic analog signals, deterministic
digital signals, and random digital signals. Although most practical signals have a
random component, we first consider deterministic signals because they are simpler
to analyse. We also focus on signal processing systems that are filters, which are
broadly applicable to a very wide range of signal processing applications.
This module will not teach you everything there is or everything you will ever
need to know about signal processing. But it will help you to develop a skill set to
understand signal processing, design (relatively) simple signal processing systems,
and be aware of some more advanced signal processing techniques.
0.3.2 Textbooks
The following textbooks are the most relevant for this module:
• “Essentials of Digital Signal Processing,” B.P. Lathi and R.A. Green, Cam-
bridge University Press, 2014. Lathi has authored several popular textbooks
on signals and systems. This recent text is quite accessible and features strong
integration with MATLAB.
sources for MATLAB, including the official software documentation (go to the
help browser within the software or visit https://uk.mathworks.com/help/
matlab/index.html). While this book has only a very brief chapter on signal
processing, it is good for a broad overview of MATLAB if you are seeking a
general reference. It is also up to date as of MATLAB release 2018b.
• Curve sketching
The following topics are also useful and we assume that you are familiar with
them:
• Basic electrical circuits (passive elements, ideal op-amps)
8 CONTENTS
• Frequency responses
If you need to remind yourself of any of these topics, or if you have not been
exposed to them previously, some mathematical background is provided in Ap-
pendix A. Furthermore, we will recall some concepts as needed when we go through
sample problems.
Lesson 1
Introduction
This lesson establishes some basic definitions and provides examples of signals and
signal processing systems. The distinction between analogue vs digital signals will
divide the first two parts of this module.
9
10 LESSON 1. INTRODUCTION
1. Continuous-time signals – signals that are specified for every value of time
t (e.g., sound level in a classroom).
2. Discrete-time signals – signals that are specified at discrete values of time
(e.g., the average daily temperature). The times are usually denoted by the
integer n.
In amplitude we have:
1. Analogue signals – signals can have any value over a continuous range (e.g.,
body temperature).
2. Digital signals – signals whose amplitude is restricted to a finite number of
values (e.g., the result of rolling a die).
While we can mix and match these classes of signals, in practice we most of-
ten see continuous-time analogue signals (i.e., many physical phenomena) and
discrete-time digital signals (i.e., how signals are most easily represented in a
computer); see Fig. 1.1. However, digital representations of data are often difficult to
analyse mathematically, so we will usually treat them as if they were analogue. Thus,
the key distinction is actually continuous-time versus discrete-time, even though for
convenience we will refer to these as analogue and digital. The corresponding math-
ematics for continuous-time and discrete-time signals are distinct, and so they also
impose the structure of this module.
x(t) x[n]
3 3
2 2
1 1
t n
0 1 2 3 4 5 6 7 8 9 0 5 10 15
−1
(a) (b)
Although many signals are not naturally in an electrical form, we can convert
them to electrical form using transducers. We do this because most physical signal
processing is done electrically (whether in analogue electronics or digital electronics).
1.3. WHAT IS SIGNAL PROCESSING? 11
1.4 Summary
• Signals are quantities that vary to convey information.
• This module will focus on continuous-time analogue signals, which are
continuous in both time and amplitude, and discrete-time analogue sig-
nals, which are discrete in both time. For convenience we will usually refer to
these as just analogue signals and digital signals.
• Signal processing applies mathematical operations to a signal. There are
many engineering fields that make use of it.
1. Refer to the top-level examples of signal processing in Section 1.3. Can you
infer what the signals might be and how they would be classified?
13
Lesson 2
The first part of this module is the study of Analogue systems and signals.
As discussed in Lesson 1, most practical physical phenomena can be represented as
continuous-time analogue signals. In this lesson, we present the notion of Laplace
transforms (which should be a review from previous modules) and how they can
be applied to linear time invariant (LTI) systems. This forms the basis for all of
the analysis of analogue signal processing that we will perform in this part of the
module.
2. Apply properties of the Laplace transform and the inverse Laplace transform.
6. Apply the Laplace transform and inverse Laplace transform to find the system
dynamic response to an input.
14
2.2. LINEAR TIME INVARIANT SYSTEMS 15
y (t − τ ) = F {x1 (t − τ )} . (2.3)
In other words, delaying the input by some constant time τ will delay the
output and make no other changes.
Part of the convenience of working with LTI systems is that we can derive the
output y (t) given the input x (t), if we know the system’s impulse response h (t).
The impulse response is the system output when the input is a Dirac delta, i.e.,
Given the impulse response h (t) of a system, the output is the convolution of
the input signal with the impulse response, i.e.,
Z t
y (t) = x (τ ) h (t − τ ) dτ = x (t) ∗ h (t) = h (t) ∗ x (t) . (2.5)
0
16 LESSON 2. LAPLACE TRANSFORMS AND LTI SYSTEMS
The definition above for the Laplace transform is formally for the unilateral
Laplace transform and is specifically for causal signals. But what if our
function f (t) is not causal, i.e., what if it is non-zero for some negative values
of t? In this case, we should use the bilateral Laplace transform, which is
defined as Z ∞
F (s) = f (t) e−st dt. (2.7)
t=−∞
Why would we not always use this form, since it is more general? The bi-
lateral transform is more involved than the unilateral transform, particularly
when evaluating its inverse, because we need to consider its Region of Con-
vergence. Since we are generally more interested in causal signals, and your
Engineering data book only provides a table for unilateral Laplace transforms
anyway, we will just assume that all Laplace transforms in this module are
unilateral. For additional details, refer to Section 1.10 of Lathi and Green.
2.3. THE LAPLACE TRANSFORM 17
You will likely have already seen the Laplace transform in previous modules
(hopefully!). The notation may have been slightly different, but we will present it
consistently here. While we will formally write the transform as F (s) = L {f (t)},
we will also show conversion between the time and Laplace domains with a double
arrow, i.e., by writing
f (t) ⇐⇒ F (s) . (2.8)
The double arrow suggests that we can also reverse the transform to go from the
Laplace domain back to the time domain, and this is true. The inverse Laplace
transform L−1 {·} is defined as follows:
Z γ+jT
−1 1
L {F (s)} = f (t) = lim F (s) est ds, (2.9)
2πj T →∞ s=γ−jT
which converts the complex function F (s) into the causal (t > 0) time-domain signal
f (t).
e−st ∞ 1
=− = , s 6= 0. (2.11)
s 0 s
for real constant a. Using the definition of the Laplace transform, we can
write
Z ∞
F (s) = f (t) e−st dt
t=0
Z ∞ Z ∞
at −st
= e e dt = e(a−s)t dt
t=0 t=0
1 (a−s)t ∞ 1
= e = , s 6= a. (2.13)
a−s 0 s−a
So far, it is not easy to appreciate the benefit of using the Laplace transform
over a convolution to study systems. However, the Laplace transform is almost
entirely bijective (and for this module we will always assume that it is bijective),
which means there is a one-to-one mapping between the time-domain function f (t)
and its transform F (s), i.e., a time-domain function has a unique Laplace domain
function and vice versa. Common function pairs are published in tables and there
is a Laplace transform table in the Engineering Data Book; a brief list of common
transform pairs is presented here in Example 2.3.
f (t) F (s)
1
1 ⇐⇒
s
1
eat ⇐⇒
s−a
n!
tn , n ∈ {1, 2, 3, . . .} ⇐⇒ n+1
s
s
cos(at) ⇐⇒
s + a2
2
a
sin(at) ⇐⇒
s 2 + a2
of a function f (t).
Z ∞
0
L {f (t)} = f 0 (t) e−st dt
t=0
∞
Z ∞
−st
= e f (t) + se−st f (t) dt
0
Z t=0
∞
= 0 − f (0) + s e−st f (t) dt
t=0
= sF (s) − f (0)
In general and ignoring initial conditions (i.e., at time t = 0), the Laplace
transform of the nth order derivative is
Laplace transform. The Laplace transform of the convolution of two functions is the
product of the Laplace transforms of the two functions, i.e.,
Although this series of steps may seem difficult, it is often easier than doing
convolution in the time domain. Furthermore, as we will see in the following lectures,
we can gain a lot of insight about a system by analysing it in the Laplace domain. We
refer to the Laplace transform H (s) of the system impulse response as the system’s
transfer function.
There are two special cases of system response that we will regularly see.
1. When the input is a delta function, i.e., x (t) = δ(t), then we know that
X (s) = 1 and so we immediately have Y (s) = H (s). This can also be
proven in the time domain, i.e., y (t) = h (t), using convolution.
2. When the input is a step function, i.e., x (t) = u(t), then we know
that X (s) = 1/s and so Y (s) = H (s) /s. This can be proven in the
time domain from convolution and the integral property of the Laplace
transform.
22 LESSON 2. LAPLACE TRANSFORMS AND LTI SYSTEMS
We want to prove that L {x (t) ∗ h (t)} = X (s) H (s). We will start with the
definition of the Laplace transform of y (t) and apply a change of variables.
Z ∞ Z t
−st
L {x (t) ∗ h (t)} = Y (s) = e x (τ ) h (t − τ ) dτ dt
Zt=0
∞ Z ∞
τ =0
= e−st x (τ ) h (t − τ ) dtdτ
Zτ =0 t=τ
∞ Z ∞
= e−s(α+τ ) x (τ ) h (α) dαdτ
τZ=0∞ α=0 Z ∞
−sτ −sα
= e x (τ ) dτ e h (α) dα
τ =0 α=0
= X (s) H (s) ,
We can also re-arrange the product Y (s) = X (s) H (s) to write the definition of
the system transfer function H (s) from the time-domain input and output, i.e.,
L {y (t)}
H (s) = , (2.23)
L {x (t)}
which is valid for a linear system when the initial conditions are zero. We will
commonly see this kind of formulation in circuit analysis, where the input and
output are currents or voltages associated with the circuit.
Consider the capacitive circuit in Fig. 2.1. What is the transfer function of
this circuit? Assume that the input is the voltage v(t) and the output is the
current i(t).
2.4. TRANSFER FUNCTIONS 23
i(t)
v(t) C
1 t
Z
v(t) = i(τ )dτ
C 0
I(s)
=⇒ V (s) =
sC
I(s)
=⇒ H(s) = = sC
V (s)
Generally, we will find it helpful to know the voltage potential drops across the
3 common passive circuit elements in the Laplace domain. Given the current I(s)
through the element, the potential drop V (s) across the element is:
1. V (s) = RI(s) across resistance R.
2. V (s) = sLI(s) across inductance L.
I(s)
3. V (s) = sC
across capacitance C.
i(t) R
+
vi (t) C vo (t)
Consider the capacitive circuit in Fig. 2.2. What is the transfer function of
this circuit? Assume that the input is the voltage vi (t) and the output is the
voltage vo (t).
Using result of the previous example we already have
I(s)
Vo (s) = .
sC
From Kirchoff’s circuit law we can also write
1
=
sRC + 1
2.5 Summary
• The output of a linear time invariant (LTI) system can be found by con-
volving the input with the system impulse response.
• We can use the Laplace transform to convert an LTI system into the Laplace
domain, where the impulse response is known as the transfer function. Con-
volution in the time domain is equivalent to multiplication in the Laplace
domain, so we can more readily find the output of a system in the Laplace
domain.
3. Solve the differential equation f 00 (t) − 3f 0 (t) + 2f (t) = 0, given that f (0) = 0
and f 0 (0) = 1.
1
4. Use Euler’s formula and the transform eat ⇐⇒ s−a
to prove that the Laplace
s
transform of cos(ωt) is s2 +ω 2
5. Use the Laplace transform of the first order derivative of a function to prove
that the Laplace transform of the second order derivative is L {f 00 (t)} =
s2 F (s) − sf (0) − f 0 (0)
6. Find the time-domain output y (t) of an LTI system defined by transfer func-
tion
1
H (s) =
1 + τs
when the input x (t) is i) A step function, and ii) A ramp function, i.e., x (t) =
t.
Vo (s)
7. Find the transfer function H (s) = Vi (s)
for the circuit in Figure 2.3
Vo (s)
8. Find the transfer function H (s) = Vi (s)
for the circuit in Figure 2.4
9. Assume that the operational amplifier in Fig. 2.5 is perfect. Find the transfer
function H (s) = VVoi (s)
(s)
for the circuit.
26 LESSON 2. LAPLACE TRANSFORMS AND LTI SYSTEMS
i1 (t) R1 i2 (t) L
+
vi (t) C R2 vo (t)
R1
C1 R2
vi (t) vo (t)
C2
R2
C R1
−
+ +
vi (t) +
v0 (t)
−
−
27
28 LESSON 3. POLES, ZEROS, AND STABILITY OF ANALOGUE SYSTEMS
then the order of the numerator polynomial must be no greater than the order of
the denominator polynomial, i.e., M ≤ N .
Eq. 3.1 may look intimidating, but it is general. If we factorize Eq. 3.1 into its
roots, then we can re-write H (s) as a ratio of products, i.e.,
(s − z1 )(s − z2 ) . . . (s − zM )
H (s) = K (3.2)
(s − p1 )(s − p2 ) . . . (s − pN )
QM
i=1 s − zi
= K QN (3.3)
i=1 s − pi
where we emphasise that the coefficient on each s is 1. Eq. 3.1 has several key
definitions:
• The roots z of the numerator are called the zeros. When s is equal to any zi ,
the transfer function H (s) = 0.
• The roots p of the denominator are called the poles. When s is equal to any
pi , the transfer function H (s) will be infinite (and we will soon see that this
relates to stability. . . )
• K is the overall transfer function gain.
Note: later in this module we will see the z-transform. It will be important to
not confuse it with the zeros of a transfer function. Unfortunately, due to the names
of the terms, re-use of variables is unavoidable here.
We will often find it useful to plot the poles and zeros of a transfer function on
the complex domain of s, which we call a pole-zero plot. The convention is to
plot zeros as circles (o for 0, i.e., don’t fall in the hole!) and poles as “x”s (i.e., stay
away from these!).
horizontal axis and the imaginary components of s lie along the vertical axis.
The plot is shown in Fig. 3.1.
Im {s}
2
Re {s}
−2 −1 0 1 2
−1
−2
More generally, poles and zeros are complex, i.e., they do not need to lie on the
horizontal axis of the s-plane. In the following, we focus on the features of analogue
systems with real and complex poles.
and see that the time-domain output signal y (t) is scaled constant plus a sum of
30 LESSON 3. POLES, ZEROS, AND STABILITY OF ANALOGUE SYSTEMS
Example 3.2
1. Find the system’s poles and zeros and sketch a pole-zero plot.
2. Find the dynamic response in the time domain, subject to a step input.
3. Sketch the dynamic response and comment on the role of the poles and
zeros.
et e−t
h (t) = − .
2 2
The Laplace transform gives the transfer function:
1 1 1
H (s) = − = .
2(s − 1) 2(s + 1) (s − 1)(s + 1)
Thus, there are no zeros and 2 poles at p = ±1. Also, the gain is K = 1. See
the pole-zero plot in Fig. 3.2.
3.3. POLES AND DYNAMIC RESPONSES 31
1
If there is a step input, then we know X (s) = s
and hence the output is
1
Y (s) = H (s)
s
1 1
=
s (s − 1)(s + 1)
1 1 1
= − +
2(s − 1) s 2(s + 1)
e−t et
=⇒ y (t) = −1 + +
2 2
A plot of this output is shown in Fig. 3.3. We see that the +1 exponent
dominates for time t > 0 (in fact this system is unstable; we will soon see
why), and the −1 exponent dominates for t < 0 (just that this isn’t actually
a real system!).
Im {s}
2
Re {s}
−2 −1 0 1 2
−1
−2
y (t)
7.5
5
e−t et
2.5 y (t) = −1 + 2 + 2
t
−3 −2 −1 0 1 2 3
h (t)
De−αt
D
De−αt sin(βt + φ)
t
0
(a) α > 0
h (t)
De−αt
D
t
0
De−αt sin(βt + φ)
(b) α < 0
h (t) D
D
t
0
D sin(βt + φ)
−D
(c) α = 0
Figure 3.4: Impulse response of system with complex poles for different values of α.
Im {s}
(-1,0) (1,0)
Re {s}
Figure 3.5: Pole-zero plot showing the stability region for poles with shaded cross
hatches.
Lathi and Green define stability from a slightly different perspective. They
call a system bounded-input bounded-output (BIBO) stable if and only
if every bounded (finite) input x (t) results in bounded output y (t). A system
is asymptotically stable if bounded initial conditions result in bounded
output. In practice for most systems, these two definitions are equivalent
and also equal to our definition based on the impulse response. Under all 3
definitions, a system whose transfer function’s poles are all to the left of the
imaginary s-axis is stable and having poles to the right of the imaginary s-
axis makes the system unstable. The details vary for poles on the imaginary
s-axis.
3.4 Summary
• The zeros are the roots to the transfer function’s numerator in the Laplace
domain.
• The poles are the roots to the transfer function’s denominator in the Laplace
domain.
• A system is stable if the impulse response tends to zero with increasing time.
3.5. FURTHER READING 35
(1 + 0.04s)(1 + 11s)
H (s) = .
0.44s2 + 13.04s + 1
3. Determine the s-domain transfer function H (s) of the system with the pole-
zero plot shown in Fig. 3.6. Is this system stable?
4. Determine the poles of each of the following transfer functions and state
whether they represent a stable system:
1
(a) H (s) = s−1
ω
(b) H (s) = s2 +ω 2
3
(c) H (s) = s2 +2s+10
36 LESSON 3. POLES, ZEROS, AND STABILITY OF ANALOGUE SYSTEMS
Im {s}
2
Re {s}
−2 −1 0 1 2
−1
−2
37
38 LESSON 4. ANALOG FREQUENCY RESPONSE
• Telephone technologies are designed for processing the frequency ranges com-
monly used by a human voice.
• Different radio frequency bands are licensed (or open) to different technologies.
Wifi commonly operates at 2.4GHz and 5GHz; other bands are reserved for
specific use such as television transmissions or the military.
To find the frequency response, recall the definition of the Laplace transform:
Z ∞
F (s) = f (t) e−st dt, (4.1)
t=0
for s = σ + jω. Let us ignore the real component of s and only consider the Laplace
transform on the imaginary s-axis, such that s = jω. We can then re-write the
Laplace transform as Z ∞
F (jω) = f (t) e−jωt dt. (4.2)
t=0
This form of H (jω) (which we may also simply write as H (ω)) is incredibly
useful for determining the frequency response of a system. We can treat H (jω) as a
function of vectors from the system’s poles and zeros to the imaginary jω-axis (i.e.,
each pole and zero corresponds to 1 vector; effectively a line from that pole or zero
to the jω-axis at frequency ω). Thus, from a pole-zero plot, we can geometrically
determine the magnitude and phase of the frequency response.
4.3. FREQUENCY RESPONSE EXAMPLES 39
Recall that the phasor form of a complex number separates it into its magnitude
and phase, i.e.,
6 H(jω)
H (jω) = |H (jω) |ej , (4.5)
such that the magnitude component has a phase of 0 and the phase component has
a magnitude of 1. First we consider the magnitude. We can take the magnitude of
both sides of Eq. 4.4 as follows:
QM
i=1 |jω − zi |
|H (jω) | = |K| QN . (4.6)
i=1 |jω − p i |
In words, the magnitude of the frequency response (MFR) |H (jω) | is equal
to the gain multiplied by the magnitudes of the vectors corresponding to the zeros,
divided by the magnitudes of the vectors corresponding to the poles.
The phase depends on the sign of K. If K > 0, then
M
X N
X
6 H (jω) = 6 (jω − zi ) − 6 (jω − pi ). (4.7)
i=1 i=1
We will consider filters in greater detail in Lesson 5, but for now consider this
transfer function of a simple low pass filter:
1
H (s) = .
1 + τs
We first re-write H (s) to match the form of Eq. 4.4 so that the coefficients
40 LESSON 4. ANALOG FREQUENCY RESPONSE
Im {s} 6 H (jω)
ω ω
0
|H (jω) |
(− τ1 ,0) θp 1 − π4
Re {s}
0
ω −π
2
for positive real constants α and ω0 . This transfer function has no zeros, but
a pair of complex conjugate poles at s = −α ± jω0 . There are now two pole
vectors to deal with and they do not lie on the real s-axis. The corresponding
pole-zero plot is in Fig. 4.2(a).
The magnitude of the 2 pole vectors has a minimum value at ω = ±ω0
(or just ω = ω0 when assuming ω > 0). The magnitude rises monotonically
as the frequency moves away from ω0 . The frequency response magnitude of
the system will do the opposite and decrease as we move away from ω0 , as
shown in Fig. 4.2(b). This is referred to as a band pass filter because it
passes signals with frequencies that are near the frequency ω0 and attenuates
signals at higher and lower frequencies.
By symmetry, the phase of the frequency response is 0 at ω = 0. As ω
increases, the angle associated with one pole vector increases while the other
decreases, which results in a slow net decrease of the system phase, until
both vector angles increase and the system phase decreases to −π, as shown
in Fig. 4.2(c).
We have not used actual numbers for the pole coordinates in this example,
but you will see if you try substituting different values of α that a smaller α
results in a more pronounced peak in the magnitude of the frequency response.
|H (jω) |
Im {s} 6 H (jω)
ω
ω 0 ω0
(−α,ω0 )
− π2
Re {s}
0
(−α,−ω0 ) ω
ω0 −π
(a) Pole-zero plot. (b) Magnitude plot. (c) Phase plot.
6 H (jω)
Im {s}
π
|H (jω) |
ω
1
(-a,0)
Re {s}
0 (a,0)
ω ω
0 0
(a) Pole-zero plot. (b) Magnitude plot. (c) Phase plot.
4.4 Summary
• The frequency response of a system is its response to an input with unit
magnitude and a fixed frequency. The response is given by the magnitude and
phase of the system output as a function of the input frequency.
• The continuous Fourier transform is the Laplace transform evaluated on
the imaginary s-axis at some frequency s = jω.
• The frequency response can be found geometrically by assessing the vectors
made by the poles and zeros of the system’s transfer function to the imaginary
4.5. FURTHER READING 43
s-axis.
1. Sketch the pole-zero plot, magnitude of the frequency response, and phase of
the frequency response of the system with the transfer function:
s
H (s) = ,
s+1
2. Sketch the pole-zero plot, magnitude of the frequency response, and phase of
the frequency response of the system with the transfer function:
1
H (s) = ,
s2 + 3s + 2
3. Consider the all pass filter from Example 4.3. The transfer function is
s−a
H (s) = ,
s+a
for real positive constant a. Prove mathematically that the magnitude of the
frequency response is always 1, and that the phase of the frequency response
is given by
ω
6 H (jω) = π − 2 tan−1 .
a
Lesson 5
In Lesson 4 we started to talk about some types of simple filters and their frequency
responses. Filtering is a very common use of signal processing and practically any
signal processing system will include some form of filtering. In this lesson, we focus
on some of the practical details of filter design and how to design an analogue filter
to meet target specifications (i.e., how to engineer a filter . . . did you wonder when
engineering would appear in this module?).
44
5.2. IDEAL FILTER RESPONSES 45
|H (jω) | |H (jω) |
1 1
ω ω
ωc ωc
1 1
ω ω
ω1 ω2 ω1 ω2
• Low pass filters pass frequencies less than cutoff frequency ωc and reject
frequencies greater than ωc .
• High pass filters reject frequencies less than cutoff frequency ωc and pass
frequencies greater than ωc .
• Band pass filters pass frequencies that are within a specified range, i.e., be-
tween ω1 and ω2 , and reject frequencies that are either below or above the
band.
• Band stop filters reject frequencies that are within a specified range, i.e.,
between ω1 and ω2 , and pass all other frequencies.
Unfortunately, none of these filters are realisable. We can show this mathemat-
ically in a very important example.
46 LESSON 5. ANALOGUE FILTER DESIGN
Consider an ideal low pass filter, which acts as a rectangular pulse in the
Laplace domain. We will focus on its double-sided frequency response, so we
consider that it passes signals within the range −ωc < ω < ωc . Is it realisable?
Let’s apply the inverse Fourier transform to determine the impulse response.
Z ∞
1
h (t) = H (jω) ejωt dω
2π ω=−∞
Z ωc
1
= ejωt dω
2π ω=−ωc
1 jωt ω=ωc
= e ω=−ωc
2πjt
1 jωc t
− e−jωc t
= e
2πjt
1 ωc t
= sin(ωc t)
πt ωc t
ωc
= sinc(ωc t).
π
Thus the impulse response is a scaled sinc function, which has non-zero
values for t < 0 as shown in Fig. 5.2. This means that the system starts to
respond to an input before that input is applied, so this filter is unrealisable .
In fact, none of the ideal filters are realisable.
|H (jω) |
hi (t)
ωc
π
1
ω
−ωc ωc t
− 2π
ωc
− ωπc π
ωc
2π
ωc
ωc ωc ωc
π π π
t t t
τ τ Td
Are we done? Not quite. Truncation can cause unexpected problems in the
frequency domain, so we also usually apply windowing, which scales the non-
truncated impulse response to improve the frequency response behaviour. We won’t
worry about windowing for analogue systems, but we will re-visit this idea for digital
systems. A more serious issue is the actual physical implementation of a filter with
a truncated impulse response, which do not generally produce a rational transfer
function H (s). However, fortunately, there are families of practical filters that have
48 LESSON 5. ANALOGUE FILTER DESIGN
rational transfer functions, which make them implementable with standard electric
circuit components. We will see some examples of these in the following section.
Note: the transfer function gain K that appears in the pole-zero factorization
form of H (s) is different from the filter gain G that refers to the magnitude of the
frequency response at a particular frequency. Unfortunately, naming conventions
mean that we need to refer to both of them as gains.
Pass Band
Gp
|H (jω) |
Transition Band
Stop Band
Gs
ωp ωs
ω
Figure 5.4: Frequency response magnitude of realizable analogue low pass filter.
the filter. The transfer function of an N th order Butterworth low pass filter is
ωcN
H (s) = QN , (5.3)
n=1 (s − pn )
where pn is the nth pole and ωc is the half-power √ cutoff frequency, i.e., the
frequency at which the filter gain is Glinear = 1/ 2 or GdB = −3dB. The poles are
located at
jπ
pn = jωc e 2N (2n−1) (5.4)
π(2n − 1) π(2n − 1)
= −ωc sin + jωc cos , (5.5)
2N 2N
for n = {1, 2, . . . , N }. So, given a desired filter order N and cutoff frequency ωc , we
can use Eq. 5.5 to find the poles and then Eq. 5.3 to determine the transfer function.
You would find that the poles form a semi-circle to the left of the imaginary s-axis.
In practice the magnitude of the Butterworth filter frequency response is more
common. It is
1
|H (jω) | = r 2N . (5.6)
ω
1 + ωc
1
N =1
N =2
√1 N =3
|H (jω) |
2
N =4
ωc
ω
Figure 5.5: Frequency response magnitude of Butterworth low pass filter for different
orders.
Our design of practical filters has focused on low pass filters and converting
between different filter specifications. This is not an inherent limitation be-
cause we can also convert between different types of filters. For example, we
can replace s with 1/s to convert a low pass filter transfer function into a
corresponding high pass filter transfer function. More complex conversions
exist for band pass and band stop filters. More details can be found in Section
2.6 of Lathi and Green.
For a given Butterworth filter specification, we have the following steps to find
a corresponding filter that meets the specification:
1. Translating pass band and stop band requirements (via Gp , ωp , Gs , ωs ) to a
suitable order N .
where d·e mean that we have to round up (i.e., so that we over-satisfy and not
under-satisfy the specification) and the gains are in dB. Given the order, we have
two ways to determine the cut-off frequency ωc :
ωp
ωc = 1 (5.9)
(10−Gp /10 − 1) 2N
ωs
ωc = 1 , (5.10)
(10−Gs /10 − 1) 2N
such that we meet the pass band specification exactly in the first case and we meet
the stop band specification exactly in the first case. Due to component imperfections,
we may choose a cut-off frequency that is in between these two cases.
To scale the normalised frequency in Eq. 5.7, we just replace ω with ω/ωc .
Let us demonstrate the validity of Eqs. 5.8, 5.9, and 5.10. We can write Gp (in
dB) as a function of ωp by converting to linear gain and using the definition
of the Butterworth filter frequency response, i.e.,
Gp = 20 log10 |H (jωp ) |
1
= 20 log10
r
2N
ωp
1+ ωc
2N !
ωp
= 10 log10 1 +
ωc
which we can re-arrange to solve for ωc and arrive at Eq. 5.9. Similarly, we
can write Gs (in dB) as a function of ωs and re-arrange to solve for ωc and
arrive at Eq. 5.10. By setting Eqs. 5.9 and 5.10 equal to each other, we can
re-arrange and arrive at Eq. 5.8. The ceiling function in Eq. 5.8 comes from
52 LESSON 5. ANALOGUE FILTER DESIGN
the fact that we need an integer order and rounding down will make the filter
unable to meet the specification.
Given Eqs. 5.8, 5.9, and 5.10 (which you would not be expected to memorise),
we can design Butterworth filters to meet target specifications. We see this in the
following example.
Design a Butterworth filter with a pass band gain no less than −2 dB over
0 ≤ ω < 10 rad
s
, and a stop band gain no greater than −20 dB for ω > 20 rad
s
.
rad
From the specification, we have Gp = −2 dB, ωp = 10 s Gs = −20 dB,
and ωs = 20 rad
s
. From Eq. 5.8, we find that N = 3.701. We need an integer
order, so we choose N = 4. We are then free to choose whether to exactly
meet the pass band or stop band specification. If we choose to satisfy the
pass band specification, then we solve Eq. 5.9 and get ωc = 10.69 rad s
. If
we choose to satisfy the stop band specification, then we solve Eq. 5.10 and
get ωc = 11.26 rad s
. We could leave a “buffer” on both bands and choose
10.69 s < ωc < 11.26 rad
rad
s
.
5.5 Summary
• The common classifications of filters are low pass, high pass, band pass,
and band stop. They are defined according to ideal transitions between pass
bands and stop bands.
• Ideal filter magnitude responses are not realisable but we can obtain practical
filter designs to approximate ideal responses.
3. Design the lowest order low pass Butterworth filter that meets the specification
ωp ≥ 10 rads
, Gp ≥ −2 dB, ωs ≤ 30 rad s
, Gs ≤ −20 dB. Find the order and
feasible range of cut-off frequencies.
54 LESSON 5. ANALOGUE FILTER DESIGN
55
56 LESSON 6. PERIODIC ANALOGUE FUNCTIONS
A key point here is that a trigonometric function has an exponential form, and
vice versa. Generally, the exponential form is more compact, and we have seen from
Laplace and Fourier transforms that system responses to exponential signals are
much easier to determine and manipulate than responses to trigonometric signals.
However, there is a trade-off; complex exponential signals are more difficult to visu-
alise. Thus, it is often more convenient to use exponential forms for mathematical
manipulations and trigonometric forms for plots and intuition.
The exponential form of the Fourier series represents the period signal x (t) as a
sum of complex exponentials. There is an underlying fundamental frequency f0 , such
that all frequencies contained in the signal are multiples of f0 . The corresponding
fundamental period is T0 = 1/f0 . The Fourier series is written as
∞
X
x (t) = Xk ejkω0 t , (6.4)
k=−∞
A very important Fourier series is that for the periodic square wave. Consider
that shown in Fig. 6.1, which is centred around t = 0, has amplitude A, and
within a period remains high for τ seconds. We wish to write the function
as a Fourier series and plots its magnitude. The period of the wave is by
definition the fundamental T0 . We can then find the Fourier coefficients as
6.2. REPRESENTING PERIODIC ANALOGUE SIGNALS 57
follows:
Z
1
Xk = x (t) e−jkω0 t dt
T0 T0
Z τ
1 2
= Ae−jkω0 t dt
T0 − τ2
τ
A −e−jkω0 t 2
=
T0 jkω0 − τ
2
jkω0 τ −jkω0 τ2
A e 2 − e
=
T0 jkω0
2A sin kω0 τ2 τ2
= τ
T0 kω0 2
Aτ τ
= sinc kω0 ,
T0 2
which we note is an even function as expected for a real x (t). In this partic-
ular case, the Fourier coefficients are also real (though generally they can be
complex).
The signal x (t) as a Fourier series is then
∞
X Aτ τ jkω0 t
x (t) = sinc kω0 e ,
k=−∞
T0 2
which we could also equivalently write by converting the sinc back to expo-
nential form or converting the complex exponential to trigonometric form.
More importantly, let us consider the magnitudes of the Fourier coefficients
for different values of T0 relative to τ , i.e., for different fundamental frequen-
cies. For T0 = 2τ , we note that ω0 = π/τ , and thus
Aτ πτ A kπ
Xk = sinc k = sinc ,
2τ τ2 2 2
x (t)
A
− T20 T0
2
t
−T0 − τ2 τ
2
T0
Xk
A/2
ω
−2ω0 −ω0 ω0 2ω0
(a) T0 = 2τ .
Xk
A/5
ω
−5ω0 −ω0 ω0 5ω0
(b) T0 = 5τ .
Figure 6.2: Fourier coefficients for periodic square wave in Example 6.1.
of sinusoids for the system input. Fortunately, besides the increase in complexity,
there is no fundamental difference in the analysis. Due to the superposition property
of LTI systems, the system will produce an output for each corresponding input,
based on the frequency response at the corresponding frequency. In other words,
the system will change the amplitude and the phase of each frequency in the input.
Thus, we can write
∞
X
y (t) = H (jkω0 ) Xk ejkω0 t , (6.7)
k=−∞
or in other words
Yk = H (jkω0 ) Xk . (6.8)
Consider passing the periodic square wave in Fig. 6.1, with T0 = 2τ , as the
input into an ideal low pass filter with gain 1 for 0 ≤ ω < 1.5 πτ . What is the
output of this filter in trigonometric form?
If T0 = 2τ , then the fundamental frequency is ω0 = π/τ . The filter will
attenuate any sinusoids with frequencies outside of −1.5π/τ < ωc < 1.5π/τ ,
so the only terms remaining in the summation are k ∈ {−1, 0, 1}. Therefore,
the output is
1
X
y (t) = H (jkω0 ) Xk ejkω0 t
k=−1
π π
= X0 + X−1 e−jk τ t + X1 ejk τ t
π jπt
A −π − jπt
= 1 + sinc e τ + sinc eτ
2 2 2
2 − jπt 2 jπt
= 1+ e τ + e τ
π π
A 4 πt
= 1 + cos .
2 π τ
signal components that passed through the filter without being attenuated.
Xk
A/2 Low Pass Filter
ω
−2ω0 −ω0 ω0 2ω0
A/2
ω
−2ω0 −ω0 ω0 2ω0
(b) Output spectra with T0 = 2τ . Here ω0 = π/τ .
y (t)
A
− T20 T0
2
t
−T0 − τ2 τ
2
T0
We can show that the Fourier series has many properties that are similar
to those for the Fourier transform. However, since we will place a bigger
emphasis on digital analysis, we will not elaborate on these here. You can
find more discussion of these in Section 1.9 of Lathi and Green.
6.4. SUMMARY 61
6.4 Summary
• The Fourier Series is used to model signals with multiple frequency compo-
nents in the frequency domain.
• The output of an LTI system due to a signal with multiple frequency com-
ponents can be found by superposition of the outputs due to the individual
frequency components.
2. Consider passing the periodic square wave in Fig. 6.1, with T0 = 2τ , as the
input into a low pass Butterworth filter of the 3rd order and cut-off frequency
ωc = 3/τ . What is the output amplitude of the complex exponential compo-
nent of frequency π/τ ?
Lesson 7
This lesson is the end of Part 1 of these notes. Our time to focus on purely analogue
signals and systems is coming to a close. Here we shift our attention from primar-
ily mathematical analysis to computing and applications. Analogue systems are by
definition not digital systems, but we still find it useful to represent them on com-
puters to help with design and analysis. In this lesson, we will see how MATLAB
can be used as a computing tool for analogue systems. We should emphasise that
MATLAB is not the only tool available for such purposes, as there are comparable
features available in other platforms such as Mathematica, and also in programming
languages. We use MATLAB since you may have used it in other modules and it
has a relatively low learning curve for programming.
The computing examples are implementations and demonstrations of tasks that
we’ve done “by hand” in previous lessons, so they should be helpful as a learning tool,
e.g., to help verify your calculations and plots, and to investigate systems that are
too complex to readily do so manually. Furthermore, the MATLAB functions used
for digital systems are very similar (or sometimes the same) as those for analogue
systems, so understanding the code here will offer some additional return later.
62
7.2. ANALOGUE SIGNALS IN MATLAB 63
Let’s now discuss how to create and study analogue systems in MATLAB. These
is not a definitive discussion, as there is often more than one way to do something
in MATLAB, but this will give you some ways to get started. Some particularly
relevant toolboxes are the Symbolic Math Toolbox the Signal Processing Tool-
64 LESSON 7. COMPUTING WITH ANALOGUE SIGNALS
box, and the Control Systems Toolbox, although they can be used independently
from each other.
We can now write expressions using s or t and they will be stored as symbolic
functions that can be evaluated analytically. For example, we can create a time-
domain input signal as a function of t and a Laplace-domain transfer function as a
function of s. We can translate between the two domains using the laplace and
ilaplace functions. Similar, we can use the fourier and ifourier functions for
the Fourier and inverse Fourier transforms, respectively. There are a large number
of pre-built functions available, such as rectangularPulse, dirac, heaviside (step
function), cos (and other trigonometric functions as you might expect), and sign.
You can also write your own functions.
Find the output of a simple low pass filter with transfer function
1
H (s) = ,
s+1
when the input is a cosine x (t) = cos (ωt). Using our knowledge of LTI
systems, we can find the answer in a short function using symbolic math.
function y = lowpassOutput(omega)
% Find output to my low pass filter
If you call this function with frequency ω = 5, then the output will be y
= cos(5*t)/26 - exp(-t)/26 + (5*sin(5*t))/26.
This works for either the time or s-domain, but only for real values of s.
The figure is shown in Fig. 7.1. The argument w is a vector of (radial) frequencies,
but if you make it scalar instead then it defines the number of frequency points are
determined automatically. Importantly, freqs plots the magnitude and phase of
the frequency response on a logarithmic scale (for both the frequencies and for
the magnitude). If you want to evenly space the data points along the domain of
each plot, then you can use the logspace function to create these for you (e.g.,
logspace(1,2,10) will create 10 logarithmically spaced points between 101 and
102 ).
If you assign freqs to an output argument, then it will store the complex fre-
quency response values for each of the frequencies. If you append a semi-colon ;
66 LESSON 7. COMPUTING WITH ANALOGUE SIGNALS
10 0
Magnitude
10 -1
10 -1 10 0 10 1
Frequency (rad/s)
0
Phase (degrees)
-50
-100
10 -1 10 0 10 1
Frequency (rad/s)
The figure is shown in Fig. 7.2. For this particular system the result is rather
boring as there is a single pole and no zeros.
Pole-Zero Map
1
0.8
0.6
Imaginary Axis (seconds-1 )
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
-1 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0
Real Axis (seconds -1 )
more. The corresponding function names are somewhat intuitive but we list them
here:
• Butterworth: butter
• Chebyshev: cheby1 (i.e., type 1)
• Inverse Chebyshev: cheby2 (i.e., type 2)
• Elliptic: ellip
• Bessel (i.e., Bessel-Thomson): besself
The syntax and use of these functions are consistent, so we will focus on using
the butter function. The default input arguments are the order of the filter and
the cut-off frequency. By default the filter will be low pass, but a third optional
argument can indicate whether the filter is to be a different type, i.e., one of ’low’,
’high’, ’bandpass’, or ’stop’. To actually make this an analogue filter instead
of a digital one is to make the final argument ’s’. For the output, we will consider
one of 2 formats. If you define two input arguments then they will be of the form
[b,a], i.e., the coefficients of the transfer function’s numerator and denominator
polynomials, respectively. If you define three input arguments then they will be of
the form [z,p,k], i.e., you will get the poles, zeros, and the transfer function gain
K. From our knowledge of transfer functions, either of these two forms are sufficient
to fully define the transfer function. You can also convert between the two forms
using the zp2tf or tf2zp functions.
68 LESSON 7. COMPUTING WITH ANALOGUE SIGNALS
Design a 4th order analogue low pass Butterworth filter with cutoff frequency
ωc = 50 rad
s
. What are its poles and zeros? Plot its frequency response and a
pole-zero plot.
We can complete all of these tasks directly in a script.
[z,p,k] = butter(4,50,’low’,’s’) % Omitting semi-colon will
print output
[b,a] = zp2tf(z,p,k); % Convert to [b,a] form for freqs
figure; freqs(b,a) % Plot frequency response
H = tf(b,a);
figure; pzplot(H) % Pole-zero plot
The output states that there are no zeros and 4 poles. The generated
plots are shown in Fig. 7.3.
Pole-Zero Map
10 0 50
40
Magnitude
10 -2
30
Imaginary Axis (seconds-1 )
10 -4
20
-6 10
10
10 0 10 1 10 2 10 3
Frequency (rad/s) 0
200 -10
Phase (degrees)
100 -20
0 -30
-100 -40
-200 -50
10 0 10 1 10 2 10 3
-50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0
Frequency (rad/s) Real Axis (seconds -1 )
7.4 Summary
• We can analytically represent analogue systems in computing platforms, ei-
ther formally using symbolic math or indirectly with vectors that represent
system components.
7.5. FURTHER READING 69
2. The butter function requires the target order N and cut-off frequency ωc .
Write a function that will calculate these from the more general low pass filter
specifications (i.e., from the pass band and stop band gains and frequencies).
Part II
70
Lesson 8
The second part of this module is the study of Digital systems and signals.
Although most practical physical phenomena can be represented as continuous-
time analogue signals, most modern signal processing is done in the digital domain.
Not surprisingly, we need to be able to convert between the analogue and digital
domains. This lesson provides an overview of the main steps involved in signal
conversion in both directions, i.e., analogue-to-digital and digital-to-analogue. We
describe conversion within the context of the end-to-end workflow of digital signal
processing.
71
72LESSON 8. SIGNAL CONVERSION BETWEEN ANALOGUE AND DIGITAL
While there are also isolated systems that are almost entirely digital, such as
computer simulations and virtual currencies, there are usually analogue interfaces
for humans to monitor these systems.
We covered analogue filtering in the first part of this module. Later lessons in
this part will cover signal processing within the digital domain. The rest of this
lesson on the ADC and DAC processes.
x [n]
n
Ts
The challenge with sampling is to determine the best sampling rate, but this is
straightforward if we know something about the frequencies present in the signal
that we are sampling. If we over-sample, i.e., sample too often, then we are using
more complexity than we need and we are wasting energy. However, if we under-
sample, then we may get aliasing of our signal, which happens when multiple
signals of different frequencies yield the same data when sampled. We show an
example of this visually in the time-domain in Fig. 8.3. If we sample the black
sinusoid at the times indicated with the blue marker, it could be mistaken for the
red dashed sinusoid. This happens when under-sampling, and lower frequency signal
is called the alias. The alias makes it impossible to recover the original data.
74LESSON 8. SIGNAL CONVERSION BETWEEN ANALOGUE AND DIGITAL
Amplitude
Time
ω ω ω
−ωB ωB −ωB ωB −ωB ωB
(a) Original signal. (b) Sampling ωs < 2ωB . (c) Sampling at ωs = 2ωB .
We will see that discrete-time signals have repeating spectra. This means that
when we sample f (t) with sampling frequency ωs = 2πfs , we get infinite copies of
the spectra, each separated by the sampling frequency ωs . When ωs is too small, as
shown in Fig. 8.4(b), the spectra overlap and we get aliasing. However, if we have
ωs ≥ 2ωB , then the spectra remain distinguishable. Thus, the minimum anti-aliasing
sampling frequency is ωs = 2ωB or equivalently fs = 2fB . This minimum frequency
is also known as the Nyquist rate.
The sampling theorem is the formalisation of the minimum sampling idea.
It states that for a continuous-time analogue signal with frequency components
less than fB , the signal can be adequately represented by a sampled version if the
8.4. QUANTISATION 75
sampling rate exceeds fs ≥ 2fB . Otherwise, aliasing will occur. Thus, we need to
sample at a frequency that is at least twice the highest frequency of the signal. In
practice we may try to sample higher since low pass filters are not ideal, however
the opposing constraint is the cost and complexity of faster sampling (i.e., we need
to collect samples faster and store more of them in memory).
If we have music that ranges from 0 to 100 kHz, but the highest audible
frequency is about 20 kHz, what is the ideal sampling frequency to enable
re-construction of the audible frequencies?
By ideal sampling frequency, we mean the minimum sampling frequency.
This would be twice the audible bandwidth, so we sample at fs = 2fB =
40 kHz .
where we use index n instead of time t. We can refer to x [n] as a sequence because
of the discrete sampling times.
8.4 Quantisation
Our discussion here is important from a practical perspective but will not have
a significant impact on the derivations in the rest of this part of the module, as
mathematical manipulation is generally easier to apply to signals with continuous
amplitude. Thus, we will be brief.
Digital systems are based on a binary representation of data, where discrete bits
of memory are used to store values. Quantisation is the mapping of continuous
amplitude levels to a binary representation. If we are coding with W bits, then
there are 2W quantisation levels available and we say that the ADC word length is
W . Continuous amplitude levels must be approximated to their nearest level (e.g.,
by rounding), and the resulting error between the nearest level and the actual level
is known as quantisation noise.
76LESSON 8. SIGNAL CONVERSION BETWEEN ANALOGUE AND DIGITAL
Amplitude
3
2
x [n]
1 x (t)
Time
0
−1
Figure 8.5: Analogue signal x (t) that is sampled and quantised to the nearest integer
to give digital signal x [n].
There are many variations of quantisation, including where to start the map-
ping and how to separate the levels. Signals that vary by orders of mag-
nitude, such as human speech, can benefit from non-uniform quantisa-
tion. By giving smaller separation between the lower amplitude levels, we
can capture more detail than if we had equal separation between all levels,
i.e., uniform quantisation. Double precision floating point numbers use
non-uniform quantisation.
Let’s say that we have a uniform ADC with W = 3 bits and the range of
possible values is 0 to 2. What is the separation between quantisation levels?
There are 2W = 23 = 8 levels. The range of values has a length of 2, and
there will be 8 − 1 = 7 intervals. Thus, the separation between levels is 2/7 .
y (t)
The simplest hold circuit is also known as a zero-order hold. This is because
if we write the signal f (t) between times t = nTs and t = (n + 1)Ts as a power
series, then the term f (t) = f (nTs ), for nTs ≤ t ≤ (n + 1)Ts , is the first term
in the series. The transfer function for the zero-order hold circuit can be
found to be
1 1 −sTs Ts
F (s) = − e ≈ .
s s 1 + sTs
The approximation of this response matches that of a simple low pass
filter, as we saw in Lesson 4. Thus, we can see that the zero-order hold helps
to repress higher order harmonics.
Two commonly defined DAC parameters are the resolution and dynamic
range. The resolution refers to the space between the levels, and it is often repre-
sented as a percentage. For a W -bit DAC with uniform levels, the DAC resolution
is then 21W × 100%. The dynamic range describes the range of signal amplitudes
that the DAC can resolve between its smallest and largest (undistorted) values. It
is calculated as 20 log10 2W ≈ 6W dB.
8.6 Summary
• The basic end-to-end signal processing workflow includes an input low pass
filter, an ADC, the DSP chip, a DAC, and an output low pass filter.
For analogue systems we used the Laplace transform to transform LTI signals and
systems to the Laplace domain. For digital systems, we have a different class of
signal and we need a different kind of transform. In this lesson, we present linear
shift invariant (LSI) systems and the Z-transform. This forms the basis for all of the
analysis of digital signal processing that we will perform in this part of the module.
Many of the ideas will seem familiar from our analogue analysis, so in some sense
we are translating everything from the analogue domain, but beware that there
are distinct differences between continuous-time and discrete-time analysis, so it’s
important to not confuse the two.
3. Understand what a Linear Shift Invariant (LSI) system is and its common
components.
4. Analyse LSI systems to find their transfer function and time-domain output.
79
80 LESSON 9. Z-TRANSFORMS AND LSI SYSTEMS
F {·} acting on discrete-time input signals (or sequences) x1 [n] and x2 [n], where n
is the discrete-time sampling index, the following properties hold:
1. The system is linear, meaning that:
(a) The system is additive, i.e.,
In other words, shifting (i.e., delaying) the input by some constant number of
time steps k will delay the output and make no other changes.
x2 [n]
x [n] y [n]
b [1]
x1 [n] y [n] x [n] y [n]
+ D
Consider the LSI circuit shown in Fig. 9.2. Write the output y [n] as a function
of the input x [n].
We see the x [n] is added to a delayed version of itself, and then the sum
is scaled by 1/2. Therefore, the output is
x [n] + x [n − 1]
y [n] = .
2
This is a simple moving average filter.
x [n] 1 y [n]
+ 2
Given an LSI system’s impulse response h [n], the output is the discrete con-
volution of the input signal with the impulse response, i.e.,
∞
X
y [n] = x [k] h [n − k] = x [n] ∗ h [n] = h [n] ∗ x [n] . (9.5)
k=−∞
Just as we did for the Laplace transform, we are actually using the definition
of the unilateral Z-transform which is specifically for causal signals. Once
again, we will not be concerned with using the more general bilateral Z-
transform. Furthermore, we are not going to write out the formal definition
of the inverse Z-transform, because it involves a contour integral. You can
read more about the bilateral Z-transform in Section 3.7 of Lathi and Green,
and more about the inverse Z-transform in Section 3.9.
F (z) = 2z 0 + z −1 + 4z −2 + 0z −3 + 4z −4
= 2 + z −1 + 4z −2 + 4z −4
F (z) = 1 − z −4
Just as with the Laplace transform, there are transform pairs between the time
and z-domains, and furthermore many of them are similar to Laplace transform
pairs. Common function pairs are published in tables and there is a Z-transform ta-
ble in the Engineering Data Book; a brief list of common transform pairs is presented
here in Example 9.5.
We take the Z-transform of the left and right sides and get
1 = F (z) − z −1 F (z)
1
=⇒ F (z) =
1 − z −1
where H (z) is referred to as the pulse transfer function, as it is also the system
output when the time-domain input is a unit impulse. However, by our convention
we will just refer to H (z) as the transfer function.
So, we can find the time-domain output y [n] of an LSI system by
Find the transfer function H (z) of the LSI system described by the following
difference equation:
1
y [n] = − y [n − 2] + x [n] + x [n − 1]
2
We take the Z-transform of both sides and re-arrange as follows:
1
Y (z) = − z −2 Y (z) + X (z) + z −1 X (z)
2
Y (z) 1 + z −1 z2 + z
=⇒ H (z) = = = .
X (z) 1 + 21 z −2 z 2 + 12
9.5 Summary
• The output of a linear shift invariant (LSI) system can be found by con-
volving the time-domain input with the system impulse response.
• We can use the Z-transform to convert an LSI system into the z-domain, where
the impulse response is known as the transfer function. Convolution in the
discrete time-domain is equivalent to multiplication in the z-domain.
3. Given f1 [n] = {5, 4, 3, 2, 1} and f2 [n] = {0, 5, 4, 3, 2, 1}, show that F2 (z) =
z −1 F1 (z).
6. Find the transfer function H (z) corresponding to the moving average system
in Example 9.1.
7. Find the difference equation and transfer function corresponding to the discrete
integrator LSI circuit shown in Fig. 9.3.
x [n] y [n]
Ts +
1. Use a digital system’s transfer function to identify its poles and zeroes.
where for notational purposes we find it useful to write the transfer function with
negative powers of z. We still have that the numerator is a M th order polynomial
with coefficients b [n], and the denominator is a N th order polynomial with coef-
ficients a [n], but generally we have a [0] = 1 (which we will also see why in later
lessons). We will find that coefficient indexing in the form of b [n] and a [n] is more
88
10.2. DIGITAL POLES AND ZEROS 89
convenient for digital systems than the form bn and an . Unlike analogue systems,
we have no constraint on the values of M and N for a system to be real, but in
practice we often assume that M = N .
If we factorize Eq. 10.1 into its roots, then we can re-write H (z) as a ratio of
products, i.e.,
(z − z1 )(z − z2 ) . . . (z − zM )
H (z) = K (10.2)
(z − p1 )(z − p2 ) . . . (z − pN )
QM
i=1 z − zi
= K QN (10.3)
i=1 z − pi
where we emphasise that the coefficient on each z in this form is 1. We now see
poles pi and zeros zi . They carry the same meaning as for analogue system. When
z is equal to any zi , the transfer function H (z) = 0. When z is equal to any pi , the
transfer function H (z) will be infinite. Unfortunately, the symbols for the variable
z and the zeros zi are very similar, so we will need to be very careful to be sure that
the meaning is clear for a given context.
We will find it insightful to plot poles and zeros on the z-domain, i.e., to make
pole-zero plots.
(z − 0.9)(z 2 − z + 0.5)
H (z) =
(z − 0.2)(z 2 + z + 0.5)
First we need to figure out the poles and zeros, i.e., the roots of the transfer
function. We can see that the numerator is zero when z = 0.9 or z = 0.5±0.5j,
and the denominator is zero when z = 0.2 or z = −0.5 ± 0.5j.
We draw a 2D axes, where the real components of z lie along the horizontal
axis and the imaginary components of z lie along the vertical axis. The
convention is also to draw a circle of radius 1 that is centred around the
origin, i.e., where |z| = 1 (the motivation for doing so will soon be clear).
The plot is shown in Fig. 10.1.
90 LESSON 10. STABILITY OF DIGITAL SYSTEMS
Im {z}
-1 1 Re {z}
-1 |z| = 1
In Lesson 3, we tried to infer information about the time-domain output y (t) based
on the locations of the poles and zeros. Here, this will not be as necessary, as we
can already write the output y [n] as a difference equation. However, the notion of
stability is still important, and the poles once again play a role.
We stated in Lesson 3 that a system is considered to be stable if its impulse
response tends to zero in the time domain. However, for digital systems, it is more
convenient for us to describe stability from the context of the input signal x [n]
and output signal y [n]. Therefore, we will use the notion of bounded input and
bounded output (BIBO) stability. A system is BIBO stable if a bounded input
sequence yields a bounded output sequence. An input sequence x [n] is bounded if
each element in the sequence is smaller than some value A. An output sequence
y [n] corresponding to x [n] is bounded if each element in the sequence is smaller
than some value B.
Our practical criterion for BIBO stability is as follows. A system is BIBO stable
if all of the poles lie inside the |z| = 1 unit circle (hence why we draw the circle on a
z-domain pole-zero plot!). If there is at least 1 pole directly on the unit circle, then
the system is said to be conditionally stable (as it will depend on the input used).
We show the digital system stability criterion visually in Fig. 10.2. The motivation
for using the unit circle for stability in the z-domain will become clearer once we
discuss the frequency response of digital systems in Lesson 11.
10.4. SUMMARY 91
Im {z}
(0,1)
(1,0)
Re {z}
|z| = 1
Figure 10.2: Pole-zero plot highlighting where poles must be located for system to
be stable. There is pole on the |z| = 1 circle in this example, so this system is
conditionally stable.
10.4 Summary
• Digital filters also have the concept of poles and zeros.
• We use the BIBO stability criterion for digital systems, such that a system
is stable if any bounded input leads to a bounded output.
• We can infer stability of a digital system from whether all of its poles lie inside
the |z| = 1 unit circle.
Determine the poles and zeros of the system, draw a pole-zero plot, and state
whether it is stable.
92 LESSON 10. STABILITY OF DIGITAL SYSTEMS
2. Draw a pole-zero plot and comment on the stability for the transfer function
of the moving average system:
1+z
H (z) = .
2z
3. Draw a pole-zero plot and comment on the stability for the transfer function
of the discrete integrator:
Ts z
H (z) = .
z−1
4. Determine the z-domain transfer function H (z) of the LSI system described
by the pole-zero plot in Fig. 10.3. State whether the system is stable.
Im {z}
(1.3,0)
-1 1 Re {z}
-1 |z| = 1
In Lesson 10, we saw how a LSI system’s pole-zero plot enabled us to describe
the stability of a system. Unlike analogue systems, the stability of digital systems
relies on the magnitude of the poles. In this lesson, we will focus on the behaviour
of LSI systems in response to periodic inputs of a particular frequency. This will
enable our discussions of digital filters in Lesson 12, and will also help to justify
the digital stability criterion. Similar to how we converted between the Laplace and
Fourier transforms for analogue systems, we will find it convenient to introduce the
discrete-time Fourier transform from the Z-transform. Once again, this translation
is straightforward, and we can then use the z-domain pole-zero plot to determine
the frequency response of a system.
93
94 LESSON 11. DIGITAL FREQUENCY RESPONSE
magnitude and 1 for the phase) as a function of the input frequency. System
design typically targets a specific frequency or range of frequencies.
To find the digital frequency response, we recall the definition of the Z-transform:
∞
X
F (z) = f [k] z −k , (11.1)
k=0
for complex z. Let us specify z is polar coordinates, such that z = rejΩ , i.e., we fix
the magnitude to r and the angle Ω. We can then re-write the Z-transform as
∞
X
F rejΩ = f [k] r−k e−jkΩ . (11.2)
k=0
When we set r = 1, then any point z = ejΩ lies on the unit circle, and this
special case of the Z-transform is known as the Discrete-Time Fourier Transform
(DTFT), i.e.,
∞
X
jΩ
f [k] e−jkΩ .
F e = (11.3)
k=0
The angle Ω is the angle of the unit vector measure from the positive real z-axis.
rad
It denotes digital radial frequency and is measured in radians per sample ( sample ).
jΩ
We refer to F e as the spectrum of f [n] or as its frequency response. Our
convention for writing the DTFT will include F ejΩ or simply F (Ω). We can also
write the inverse DTFT as
Z π
1
F ejΩ ejkΩ dΩ.
f [k] = (11.4)
2π −π
We recall from Lesson 10 that we can write an LSI system’s transfer function
H (z) as a ratio of products that included its poles and zeros. We can now re-write
the transfer function using z = ejΩ as
QM jΩ
jΩ
i=1 e − zi
H e = K QN . (11.5)
jΩ − p
i=1 e i
the approach for calculating the frequency response is the same. Thus, we find the
magnitude of the frequency response as
QM jΩ
jΩ i=1 |e − zi |
|H e | = |K| QN . (11.6)
|ejΩ − p |
i=1 i
In words, the magnitude of the frequency response (MFR) |H ejΩ | is
equal to the gain multiplied by the magnitudes of the vectors corresponding to the
zeros, divided by the magnitudes of the vectors corresponding to the poles.
If we assume that the gain K > 0, then the phase of the frequency response is
M N
X X
6 H ejΩ = 6 (ejΩ − zi ) − 6 (ejΩ − pi ). (11.7)
i=1 i=1
In words, the phase angle of the frequency response (PAFR) 6 H ejΩ is
equal to the sum of the phases of the vectors corresponding to the zeros, minus the
sum of the phases of the vectors corresponding to the poles.
Notably, both the magnitude and phase of the frequency response repeat every
2π. This is clear to see using Euler’s formula:
Furthermore, due to usual symmetry of poles and zeros about the real z-axis,
the frequency response is also symmetric about Ω = π. Thus, we only need to find
the magnitude and phase over one interval of π. It is sometimes common (e.g.,
in MATLAB) to normalise the frequency response by π, such that the normalised
frequency range is 0 to 1.
We recall that sampling resulted in “infinite” copies of our spectrum in the
frequency domain. One perspective to understand this is that, as we increase Ω,
we cycle around and around the unit circle. If we sample an analogue signal fast
enough to avoid aliasing (i.e., at double the signal bandwidth), then we guarantee
that we encounter all of the unique signal components within one half circle.
11.4 Summary
• The frequency response of a system is its response to an input with unit
magnitude and a fixed frequency. The response is given by the magnitude and
phase of the system output as a function of the input frequency.
Im {z}
1
z = ejΩ
θz
θp
Re {z}
-1 1
-1
|z| = 1
|H ejΩ |
H ejΩ
6
4 π
2
3
2 π
4
1
Ω π
Ω
0 π 0 π
2 2
• Sections 6.1, 6.2, and 7.6 of “Essentials of Digital Signal Processing,” B.P.
Lathi and R.A. Green, Cambridge University Press, 2014.
98 LESSON 11. DIGITAL FREQUENCY RESPONSE
2. Understand and Compare finite impulse response (FIR) and infinite im-
pulse response (IIR) filters.
99
100LESSON 12. FILTER DIFFERENCE EQUATIONS AND IMPULSE RESPONSES
and the real coefficients b [·]s and a [·]s are the same as those that appear in Eq. 12.1
(and we note that a [0] = 1 so that there is no coefficient corresponding to y [n]).
So, rather than use the time-domain impulse response h [n], it is usually easier to
convert directly between the transfer function H (z) (written with negative powers
of z) and the difference equation for the output y [n]. This is particularly suitable
when we seek an implementation of the system.
Example 12.1: Proof that y [n] can be Obtained Directly from H (z)
Let’s prove using the Z-transform that Eq. 12.1 can lead us directly to Eq. 12.2.
Recall that H (z) = Y (z) /X (z). We can substitute this into Eq. 12.1 and
cross-multiply to get
we tend to work through the steps in this proof for a specific H (z) to find
the corresponding y [n].
Given Eq. 12.2, and what we know about LSI implementations, the general
implementation of a difference equation is presented in Fig. 12.1 where we have
assumed that M = N . For a particular system, if there is a coefficient b [k] = 0 or
a [k] = 0, then we simply omit the corresponding multiplier and its wiring from the
implementation. We immediately see that a higher N or M increases the complexity
(and hence the cost) of the implementation by requiring more components. We refer
to the order of a filter as the greater of N and M . The number of taps in a filter is
the minimum number of unit delay blocks required, which is also equal to the order
of the filter.
x [n]
b [N ] b [1] b [0]
y [n]
+ D + D +
−a [N ] −a [1]
Let’s say that we need to implement a 2nd order filter. How many delay
blocks will we need?
A 2nd order filter is a 2-tap filter and will need 2 unit delays. This is a
rather simple example, but we emphasise the reuse of delay blocks for both
the inputs and delayed outputs, as shown with adders in Fig. 12.1. While
102LESSON 12. FILTER DIFFERENCE EQUATIONS AND IMPULSE RESPONSES
it would also be possible to instead use 2 unit delays for the inputs and 2
separate unit delays for the outputs, this would use more components and
hence be more expensive (more space, more energy, and more money).
We see from the use of delay blocks in Fig. 12.1 that digital filter implemen-
tations have memory stored in them. We can refer to the states of internal
memory using state variables, with one corresponding to the output at each
delay block. It is possible to write equations for states as functions of other
states and the system input and not explicitly include the function output.
While relevant for digital computing, this concept is not necessary for our
understanding of filters in this module.
Use the tabular method to find the step response of the filter implementation
in Fig. 12.2.
By inspection, we write the difference equation of this filter as
We complete a table for the output in Table 12.1, and sketch the output
in Fig. 12.3.
x [n] y [n]
+
0.6 D
-0.5 D
x [n] y [n − 2] y [n − 1] y [n]
1 0 0 1
1 0 1 1.6
1 1 1.6 1.46
1 1.6 1.46 1.08
1 1.46 1.08 0.92
1 1.08 0.92 1.01
1 0.92 1.01 1.15
104LESSON 12. FILTER DIFFERENCE EQUATIONS AND IMPULSE RESPONSES
y [n]
n
0 1 2 3 4 5 6
x [n]
-5
y [n]
+ D +
0.995
and the implementation is just the “upper half” of Fig. 12.1, as shown in Fig. 12.5.
Since there is no feedback, we can readily write the impulse response h [n] as
and this is what we show in Fig. 12.5 to emphasise that the impulse response comes
directly from the knowledge of the numerator coefficients.
106LESSON 12. FILTER DIFFERENCE EQUATIONS AND IMPULSE RESPONSES
x [n]
h [N ] h [1] h [0]
y [n]
D + D +
FIR filters are “finite” because their impulse response is finite in length and
strictly zero beyond that, i.e., h [n] = 0 for n > M . Thus, the number of filter taps
dictates the length of an FIR impulse response.
The pole-zero plot of an FIR filter is easy to identify and leads us to a universal
property about FIR filter stability. To see this, let’s simplify the transfer function
in Eq. 12.1 for an FIR filter:
Find the impulse response and transfer function of the FIR filter given by the
implementation in Fig. 12.6. Write the transfer function with positive powers
of z.
12.4. FINITE IMPULSE RESPONSE FILTERS 107
y [n] = x [n] + 2x [n − 1] + x [n − 2] ,
from which we could then also go on to find the pole-zero plot and frequency
response.
x [n]
y [n]
D + D +
Our method for realising LSI implementations is taken directly from the dif-
ference equation. It is the most direct approach but not the only one. Sec-
tion 7.5 of Lathi and Green discusses several methods of implementation,
and there is further discussion specific to IIR and FIR filter realisations in
Sections 8.1.5 and 8.2.2, respectively. For example, it is common to partially
factor the transfer function and then implement a filter by cascading two or
more filters together.
108LESSON 12. FILTER DIFFERENCE EQUATIONS AND IMPULSE RESPONSES
• Low pass filters pass frequencies less than cutoff frequency Ωc and reject
frequencies greater than Ωc .
• High pass filters reject frequencies less than cutoff frequency Ωc and pass
frequencies greater than Ωc .
• Band pass filters pass frequencies that are within a specified range, i.e., be-
tween Ω1 and Ω2 , and reject frequencies that are either below or above the
band within [0, π].
• Band stop filters reject frequencies that are within a specified range, i.e.,
between Ω1 and Ω2 , and pass all other frequencies within [0, π].
These ideal responses appear to be fundamentally different from the ideal ana-
logue responses that we considered in Lesson 5. However, we only really care about
the behaviour over the fundamental band [−π, π), over which the behaviour of ideal
digital filters is identical to that of ideal analogue filters.
|H ejΩ | |H ejΩ |
1 1
Ω Ω
Ωc π 2π − Ωc 2π Ωc π 2π − Ωc 2π
Ω
Ω1 Ω2 π 2π − Ω2 2π − Ω1 2π
Ω
Ω1 Ω2 π 2π − Ω2 2π − Ω1 2π
is somewhat easier for digital filters than for analogue filters because we only need
to consider the response over the fixed and finite frequency band [−π, π).
It’s helpful to keep a few concepts in mind:
• To be physically realisable, complex poles and zeros need to be in conjugate
pairs.
• We can place zeros anywhere, so we will often place them directly on the unit
circle when we need a frequency or range of frequencies to be attenuated.
• Poles on the unit circle should generally be avoided. If we can keep all of
110LESSON 12. FILTER DIFFERENCE EQUATIONS AND IMPULSE RESPONSES
the poles at the origin, then our design is FIR; otherwise it is IIR and there
is feedback. Poles are used to amplify the response in the neighbourhood of
some frequency.
From these concepts, and what we know about the ideal filter responses, we can
have the following intuition for each kind of filter:
• Low pass – place zeros at or near Ω = π. Poles near Ω = 0 can amplify the
maximum gain or be used at a higher frequency to increase the size of the pass
band.
• High pass – literally the inverse of low pass. Place zeroes at or near Ω =
0. Poles near Ω = π can amplify the maximum gain or be used at a lower
frequency to increase the size of the pass band.
• Band pass – place zeros at or near both Ω = 0 and Ω = π; such a filter must
be at least second order. Place poles if needed to amplify the signal in the
neighbourhood of the pass band.
• Band stop – place zeros at or near the stop band. These zeros must be
complex so such a filter must be at least second order. Place poles at or near
both Ω = 0 and Ω = π if needed.
We will now highlight these ideas in an example.
Design a high pass FIR filter with 1 tap, a gain of 1 at high frequency, and a
gain of 0 at low frequency. Sketch the pole-zero plot and LSI implementation.
Since there is only one tap, we can have no more than one pole and one
zero. It makes sense to place a zero on the unit circle at frequency Ω = 0.
Since the filter is FIR, the pole must be at the origin. With this orientation
of pole and zero, we know that the magnitude of the frequency response at
Ω = π is 2. So, we need to include a multiplier in the implementation that
imposes a gain of K = 0.5. The transfer function is then
z−1
H (z) = 0.5 = 0.5(1 − z −1 ),
z
so we know that the numerator coefficients are b [0] = 1 and b [1] = −1. We
sketch the pole-zero plot and LSI implementation in Fig. 12.8. We emphasise
that we don’t need a multiplier for b [0] = 1 because it has a value of 1.
Consider what we could do if the design were IIR. We would then have
12.7. SUMMARY 111
flexibility to place the pole somewhere besides the origin. This would be
helpful if we have a specific multiplier available.
Im {z} x [n]
1
-1
-1 1 Re {z}
y [n]
D + 0.5
-1 |z| = 1
12.7 Summary
• The difference equation of a digital filter can be obtained directly from the
z-domain transfer function.
• The two major classes of digital filters are infinite impulse response (IIR)
filters and finite impulse response (FIR) filters. IIR filters have feedback.
FIR filters have no feedback and are always stable.
• We can design simple digital filters of any of the major filter types by starting
with a pole-zero plot.
Even when not explicitly asked in one of the following problems or previous exam-
ples, you can consider all of the representations and analysis of a given system. This
makes for excellent practice.
1. Consider the filter LSI implementation in Fig. 12.9. Determine the transfer
function of the filter. Is it FIR or IIR? Sketch a pole-zero plot and state the
type of filter (low pass, high pass, band pass, or band stop). Compare the
implementation with that in Fig. 12.6. Comment on the difference (if any) in
filter type.
x [n]
-2
y [n]
D + D +
2. Consider the pole-zero plot in Fig. 12.10. Is the filter FIR or IIR? Determine
the magnitude of the filter’s frequency response. What type of filter is it (low
pass, high pass, band pass, or band stop), and is it an effective filter of that
type? Why or why not?
3. Consider the pole-zero plot in Fig. 12.11. Is the filter FIR or IIR? Determine
the magnitude of the filter’s frequency response. What type of filter is it (low
pass, high pass, band pass, or band stop)? Comment on the quality of the
filter.
4. Consider an LSI system in the form of Fig. 12.1 where b [0] = 1, b [1] = 1,
b [2] = 0.5, a [1] = −1, and a [2] = 0.5. Sketch the pole-zero plot, state the
type and order of filter, and comment on its stability.
Im {z}
(-0.5,0)
-1 1 Re {z}
-1 |z| = 1
Im {z}
|z| = 1 1
(0.5,0.866)
-1 1 Re {z}
-1 (0.5,-0.866)
In this lesson, we build upon the digital filter fundamentals that we introduced in
Lesson 12. We discuss practical digital filter design, including the roles of truncation
and windowing for effective and efficient FIR filters. As with analogue filters, we
focus our discussion on the implementation of low pass filters.
114
13.2. REALISING THE IDEAL FILTER RESPONSE 115
Let us consider the ideal low pass filter response that we presented in Les-
son 12 and attempt to transform this response into the time domain to assess
its realisability. Using the inverse DTFT, the ideal impulse response is as
follows:
Z π Z Ωc
1 jΩ
jnΩ 1
hi [n] = H e e dΩ = 1 × ejnΩ dΩ
2π −π 2π −Ωc
Ω=Ωc
1 ejnΩ
=
2π jn Ω=−Ωc
1 jnΩc 1 nΩc
− e−jnΩc =
= e sin (nΩc )
j2πn πn nΩc
Ωc
= sinc (nΩc )
π
This is analogous to the inverse Fourier transform of the ideal analogue
low pass frequency response that we performed in Example 5.1. We have
a sampled scaled sinc function, which has non-zero values for n < 0. This
implies that the ideal system needs to respond to an input before that input
is applied, so this ideal response (and all ideal responses) is unrealisable .
We can plot hi [n] over discrete-time samples without knowing the sam-
pling frequency ωs , however ωs would be needed if we wanted to indicate the
actual time between samples of h [n]. We plot hi [n] for Ωc = π/3 in Fig. 13.1.
In the rest of this Lesson, we focus on FIR filter design using the windowing
method, which tries to match the ideal filter response in the time domain. It
is also possible to take a frequency domain approach, which is more intuitive
for complicated frequency responses, but the steps are more involved and are
thus outside the scope of this module. You can read more about the frequency
domain approach in Section 8.2.6 of Lathi and Green.
There are also IIR filter implementations. These relate nicely to analogue
filter design, because it is common for digital IIR filters to start with a realis-
able analogue filter (e.g., Butterworth) and then convert it into an equivalent
116 LESSON 13. FIR DIGITAL FILTER DESIGN
hi [n]
1
3
n
-6 -5 -4 -3 -2 -1 1 2 3 4 5 6
Figure 13.1: Impulse response hi [n] of ideal low pass digital filter in Example 13.1
for Ωc = π/3.
digital filter. This conversion uses the bilinear transform, which is outside
the scope of this module but will be discussed in Lesson 16. You can read
more about realising IIR filters in Section 8.1 of Lathi and Green.
• We window the response, which scales each sample in the impulse response
according to a particular window w [n]. For example, a rectangular window
is simply truncation alone, but other windows try to mitigate the negative
effects of truncation.
13.3. PRACTICAL DIGITAL FILTERS 117
We refer to the above approach as the window method, as our design process
is starting with an ideal hi [n] and windowing this infinite time-domain response
to obtain a realisable h [n] that we can then immediately implement following the
guidance of Lesson 12.
If we use a simple rectangular window (i.e., just truncate), then we are multi-
plying the ideal response by a rectangle function in the time domain. While we
will not go into the mathematical details, the discrete-time rectangle function corre-
sponds to a sinc function in the spectral domain (see Fig. 13.2), and multiplication
in time corresponds to convolution in frequency, so we end up with non-ideal stop
band behaviour. Nevertheless, the rectangle window is simple and is also known as
the Fourier series method, because the windowed filter coefficients that remain
are the first Fourier series coefficients that describe the ideal frequency-domain be-
haviour.
|Hrect ejΩ |
Main Lobe
Side Lobe
π
Ω
−π − 4π − 2π 2π 4π
L L L L
To discuss and compare windows, we need to understand lobes. The main lobe
is the largest portion of the frequency response magnitude, and for a low pass filter
is centred around the origin Ω = 0. The side lobes are all of the other portions of
the magnitude response. Picture the response in Fig. 13.2 where we have labelled
the main lobe and one of the side lobes, and consider how it compares to the ideal
response for a low pass filter. We observe a rather gradual roll-off in the pass band as
the magnitude of the main lobe goes to 0, and all of the side lobes are contributing
non-zero responses in the stop bands. Thus, the criteria that we are interested in
are:
1. Main lobe width – the width in frequency of the main lobe (4π/L for the
rectangular window).
2. Roll-off rate – how sharply the main lobe decreases, measured in dB/dec
(i.e., dB per decade).
118 LESSON 13. FIR DIGITAL FILTER DESIGN
3. Peak side lobe level – the peak magnitude of the largest side lobe relative
to the main lobe, measured in dB.
Given these criteria, we are able to compare different window designs. We list
several common windows and their (approximate) performance criteria in Table 13.1.
We observe that the rectangular window, while simple, has a much poorer peak side
lobe level than the other windows. The other windows have larger main lobe widths,
which means that longer filters are needed to maintain a comparable pass band.
The Hann and Hamming windows have very similar forms but different trade-offs
between the roll-off rate and the peak side lobe level. The Blackman window has
the best combination of roll-off rate and peak side lobe level but the largest main
lobe width (thus requiring the longest implementation for given cut-off and sampling
frequencies).
Table 13.1: Common FIR Window Functions. Windows are w [n] = 0 outside of
0 ≤ n ≤ L − 1.
4π
Rectangular 1 L
-20 -13.3
1 2πn 8π
Hann 2
1 − cos L−1 L
-60 -31.5
2πn 8π
Hamming 0.54 − 0.46 cos L−1 L
-20 -42.7
2πn 4πn 12π
Blackman 0.42 − 0.5 cos L−1
+ 0.08 cos L−1 L
-60 -58.1
With the use of Table 13.1, combined with our knowledge of the ideal filter
realisation and the discrete-time Fourier transform (DTFT), we can compare the
time-domain implementations of practical filters with their spectra to visualise both
their implementations and their performance.
Design a low pass FIR filter for a cut-off frequency of Ωc = π/2 using L =
7 coefficients with a rectangular window. Compare the time-domain and
magnitude spectra with that of a Hamming window.
From Ωc = π/2, we know that the ideal time domain response is hi [n] =
1 nπ
2
sinc 2
. We need L = 7 coefficients from this function. They should be
centred about n = 0, so we consider n = {0, ±1, ±2, ±3}. By symmetry, we
13.3. PRACTICAL DIGITAL FILTERS 119
hi [0] = 0.5
hi [1] = 0.3183 = hi [−1]
hi [2] = 0 = hi [−2]
hi [3] = −0.1061 = hi [−2]
For the rectangular window, we just need to shift these coefficients so that
the filter is causal. We get
window filter is
We plot the two spectra and compare with the ideal response in Fig. 13.3(b)
over the range [−π, π].
|H ejΩ |
h [n]
1
2 1
π
Ω
n −π − π2 π
2
1 2 3 4 5 6 7 8
Rectangular Filter
Hamming Filter
Rectangular Filter Hamming Filter Ideal Filter
• The gain over the pass band, defined by the pass band frequency Ωp , can vary
about unity between 1 − δp /2 and 1 + δp /2. δp is the pass band ripple.
13.4. DESIGNING FILTERS FOR TARGET SPECIFICATIONS 121
• The gain over the stop band, defined by the stop band frequency Ωs , must be
less than the stop band ripple δs .
We define the stop band ripple δs in dB analogously to the stop band gain for
analogue filters, such that GdB = 20 log10 δs . The pass band ripple in dB is defined
by the pass band ripple parameter rp :
!
1 + δ2p
rp = 20 log10 . (13.3)
1 − δ2p
Interestingly, when using the window method for filter design, we cannot inde-
pendently specify pass band and stop band ripples. Generally, a filter’s stop band
ripple will equal half of its pass band ripple δs = δ2p . Furthermore, the ripple char-
acteristics of the windowing filters are approximately fixed for the type of window
and change very little with window length (i.e., filter order). The transition band
Ω∆ = Ωs − Ωp , i.e., the difference between the pass band and stop band frequencies,
does change with filter length. All of these details are typically found in a table such
as Table 13.2.
Table 13.2: Band Characteristics of Common FIR Window Functions.
4π 1.84π
Rectangular L
-13.3 L−1
0.090 -20.9 1.57
8π 6.22π
Hann L
-31.5 L−1
0.0064 -43.9 0.11
8π 6.64π
Hamming L
-42.7 L−1
0.0019 -54.5 0.033
12π 11.13π
Blackman L
-58.1 L−1
0.00017 -75.3 0.0030
Design an FIR low pass filter with cut-off frequency at 20 kHz, pass band
frequency no less than 19 kHz, pass band ripple rp ≤ 0.1 dB, stop band fre-
quency no greater than 21 kHz, and stop band gain Gs ≤ −50 dB. Set the
sampling frequency to be 4 times the cut-off frequency, i.e., 80 kHz.
122 LESSON 13. FIR DIGITAL FILTER DESIGN
From Table 13.2 we see that a Hamming window could meet this specifi-
cation because rp = 0.033 dB and Gs = −54.5 dB. We need to translate each
of the frequencies based on the sampling frequency:
2π(20000) π
Ωc = = ,
80000 2
2π(19000) 19π
Ωp = = ,
80000 40
2π(21000) 21π
Ωs = = ,
80000 40
so we find that Ω∆ = Ωs − Ωp = 0.05π. We then apply the Hamming window
formula for Ω∆ and calculate that we need a filter of length L = 134. You
would not be expected to find these terms by hand (!), though a computer
program could be helpful.
13.5 Summary
• Realisable filters are constrained by causality and delay.
2. Consider an FIR low pass digital filter implementation of the subwoofer design
in Question 5.4. This filter was to have a pass band frequency of at least 100 Hz
13.7. END-OF-LESSON PROBLEMS 123
and a stop band frequency of no more than 250 Hz. The stop band gain was
to be Gs ≤ −30 dB. Assume that the signal is being sampled at 5 kHz.
rad
(a) What are the radial pass band and stop band frequencies in sample
?
(b) What length of a Hann window filter is needed to achieve this perfor-
mance?
(c) Can a rectangular window filter meet the specification?
Lesson 14
124
14.2. DISCRETE FOURIER TRANSFORM 125
The DTFT is defined for the infinite-length sequence x [n] and gives a continuous
spectrum with values at all frequencies. We saw in the previous lesson that we often
have finite-length sequences, and for digital computation it would be convenient
to have a finite number of frequencies. Furthermore, the IDTFT requires solving
an integration that in general must be approximated. We can address all of these
concerns at once. Let’s suppose that our sequence x [n] is of length N . The DTFT
is then
N
X −1
jΩ
x [n] e−jnΩ .
X e = (14.2)
n=0
Now suppose that we sample the spectrum X ejΩ . We know that X ejΩ
repeats every 2π, so it should be sufficient to sample over the window [0, 2π). We will
find it convenient to take that same number of samples in the frequency domain as
the length
of the time-domain signal, such that we take N evenly-spaced samples of
X ejΩ . These samples occur at multiples of the fundamental frequency Ω0 = 2π/N ,
i.e., at the frequencies
2π 4π 2π(N − 1)
Ω = 0, , , . . . , , (14.3)
N N N
which we can substitute into the DTFT and write the sampled form of the spectrum
as
N −1
2π
X
X [k] = x [n] e−jnk N , k = {0, 1, 2, . . . , N − 1}. (14.4)
n=0
Importantly for implementation, the DFT and IDFT look very similar; very
similar algorithms can be used for both transforms. Computers can evaluate both
of them exactly and without any approximation. The length N can be as large as
we wish.
126 LESSON 14. DISCRETE FOURIER TRANSFORM AND THE FFT
Calculate the DFT of a sine wave that is evenly sampled N = 6 times over
one period, as shown in Fig. 14.1(a). Plot the magnitude and phase spectra.
The time-domain signal is
( √ √ √ √ )
3 3 3 3
x [n] = 0, , , 0, − ,− .
2 2 2 2
X [0] = 0
√ h
3 −j π 2π 4π 5π
i
X [1] = e 3 + e−j 3 − e−j 3 − e−j 3
√2
3 π π 2π 2π
= cos − j sin + cos − j sin
2 3 3 3 3
4π 4π 5π 5π
− cos + j sin − cos + j sin
3 3 3 3
√ " √ √ √ √ #
3 1 3 1 3 1 3 1 3
= −j − −j + −j − −j
2 2 2 2 2 2 2 2 2
= −j3
X [2] = 0,
We plot the magnitude and phase spectra in Figs. 14.1(b) and (c). We
note these both have periodic extensions of length N ; the 3 at k = 5 is the
same as being at k = −1. Also, for sampling frequency fs , the separation
between samples in frequency is fs /N = fs /6.
k − π2
0 1 2 3 4 5
(a) Time-domain signal. (b) Magnitude spectra. (c) Phase spectra.
As we have noted, the DFT provides a sampled view of the DTFT. It is referred
to as a picket fence, since we only see the DTFT at N frequencies. If we want to see
more detail in the DTFT, then we can artificially increase the length of the time-
domain signal x [n] by adding zeros to the end. This is known as zero padding.
We will see the effect of zero padding in an example.
Find the DFT X [k] of the signal x [n] = {3,2,3} as shown in Fig. 14.2(a).
Compare the DFT magnitude with 1) the corresponding DTFT X ejΩ ; and
2) the DFT when we pad x [n] to be length N = 6.
Since N = 3 know that the frequencies are separated by Ω0 = 2π/3. The
DFT is then
2
2π 2π 4π
X
X [k] = x [n] e−jnk 3 = 3 + 2e−jk 3 + 3e−jk 3 ,
n=0
128 LESSON 14. DISCRETE FOURIER TRANSFORM AND THE FFT
X [0] = 3 + 2 + 3 = 8
√ !
√ 3 3 3
X [1] = 3 + (−1 − j 3) + − +j = 0.5 + j0.866
2 2
X [2] = 0.5 − j0.866
= 3 + 2e−jΩ + 3e−2jΩ
= e−jΩ 2 + 3ejΩ + 3e−jΩ = e−jΩ (2 + 6 cos(Ω)) .
The DTFT is defined for all Ω but we plot its magnitude in Fig. 14.2(b)
over [0, 2π). We see that the DFT is sampling the DTFT, as expected, though
it doesn’t capture the shape of the DTFT particularly well.
Now consider zero-padding x [n] (as in Fig. 14.2(c)) so that N = 6 and
re-calculating the DFT. The frequency separation is now Ω0 = 1π/3 and the
DFT is then
5
2π 2π 4π
X
Xpad [k] = x [n] e−jnk 5 = 3 + 2e−jk 5 + 3e−jk 5 ,
n=0
and we plot the magnitude of Xpad [k] in Fig. 14.2(d) with the same corre-
sponding DTFT. By increasing N the DFT has a better representation of the
DTFT.
We will not go over properties of the DFT in detail, but we note the DFT
14.3. FAST FOURIER TRANSFORM 129
x [n] |X [k] |
3 8
|X ejΩ |
7
6
2 5
4
3
1 2
1
n kΩ0
0 1 2 3 4 5 6 0 2π 4π 2π
3 3
(a) Time-domain signal. (b) Magnitude spectra.
xpad [n] |Xpad [k] |
8 |X ejΩ |
3
7
6
2 5
4
3
1 2
1
n kΩ0
0 1 2 3 4 5 6 0 2π 4π 2π
3 3
(c) Zero-padded time-domain signal. (d) Zero-padded magnitude spectra.
has some properties that are similar to others that we have seen throughout
the module, in addition to properties that derive from its periodicity such as
circular convolution and circular correlation. More details are in Section 9.3
of Lathi and Green.
are still cumbersome to evaluate by hand. However, importantly, the FFT and its
inverse are readily available in MATLAB (and other computing platforms). The
syntax of the fft and ifft functions in MATLAB is quite simple:
% Given discrete-time sequence x (already zero-padded if desired)
X = fft(x); % FFT
Calculate the DFT of a sine wave that is evenly sampled N = 64 times over
one period, as shown in Fig. 14.3. Plot the magnitude spectra.
The sequence length is too long to calculate by hand, so will use the FFT
in MATLAB. The following code can do this:
N=64; % Sequence length
nVec = 0:(N-1); % Vector of index values
x = sin(2*pi*nVec/N); % Sample N times over one period of 2*pi
X = fft(x); % FFT
14.4 Summary
• Discrete spectra are more convenient than continuous spectra for computa-
tions.
14.4. SUMMARY 131
x [n]
n
4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64
35
30
25
20
|X[k]|
15
10
0
0 10 20 30 40 50 60 70
Spectral Index k
This lesson is the digital counterpart to Lesson 7, where we saw how MATLAB can
be used as a computing tool for analogue systems. It is even more “natural” to
represent digital signals and systems in a computer (in fact this is by design). While
we have already covered some cases of digital signal processing on a computer, e.g.,
when computing the FFT in Lesson 14, this lesson provides a more general overview
for working with digital signals and systems. In particular, we will cover tasks that
we’ve already done “by hand” in the previous lessons of this part of the module, so
this should facilitate revision of previous learning concepts.
We once again re-iterate that MATLAB is not the only tool available for these
purposes; practically any programming language has (or should have) libraries avail-
able for common digital signal processing tasks.
133
134 LESSON 15. COMPUTING WITH DIGITAL SIGNALS
signal (e.g., voltage level) being stored in a one-dimensional array, where each el-
ement in the array corresponds to one discrete-time index of the signal. This can
also be extended to multi-dimensional signals being stored in multi-dimensional ar-
rays, e.g., as we will see with images in the Image Processing part of the module.
MATLAB stands for “MATrix LABoratory,” in case the relevance wasn’t sufficiently
apparent, though really any modern program language or general computing plat-
form should have functionality to work with and manipulate arrays of data.
Throughout this module we have referred to “digital” signals even though we
have treated them as continuous in amplitude. This has facilitated our mathematical
analysis and has minimal impact on implementation, especially given the precision
of floating point numbers (see more on this in Lesson 7).
We now discuss some common ways to represent digital systems and signals
in MATLAB, in particular those that are most relevant to the material covered
throughout this part of the module.
There are also function for creating arrays with pre-determined values. These
can be in any number of dimensions by supplying additional arguments.
x6 = ones(1,10); % Create array of ones with 1 row and 10 columns
x7 = ones(2,5,3); % Create a 2x5x3 array of ones
x8 = zeros(3); % Create a 3x3 matrix of zeros (or use zeros(3,3))
We note that the length of the output from conv is one less than the sum of the
length of the inputs (i.e., the length of the full convolution vector).
Signals can also be readily converted to the spectral domain using the FFT
implementation of the DFT. We have already seen examples of this in Lesson 14.
If we create functions using these variables, we can convert between the time
and z domains using the ztrans and iztrans functions. We can use the same pre-
built functions that apply to continuous-time systems (e.g., rectangularPulse, dirac,
heaviside). Here we repeat Example 7.1 for an equivalent digital system.
Find the output of a simple low pass filter with transfer function
z+1
H (z) = ,
z
when the input is a cosine x (t) = cos (Ωn). Using our knowledge of LSI
systems, we can find the answer in a short function using symbolic math.
function y = lowpassOutputDigital(omega)
% Find output to my low pass filter
% Create symbolic variables
syms n z
% Create symbolic functions for input and system
x = cos(omega*n);
H = (z+1)/z;
If you call this function with frequency Ω = 5, then you will find that the
output is different from that which we saw in Example 7.1.
Some additional useful functions when using the Symbolic Math Toolbox:
10
Magnitude (dB)
0
-10
-20
-30
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
0
Phase (degrees)
-50
-100
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
check this out and explore the options available. However, it contains many more
features that what we need for this module, so we will not discuss it here in detail.
• Elliptic: ellip
Design a 20th order band pass FIR filter with a Hann window that processes
signals sampled at 1 kHz and passes signals between 100 Hz and 200 Hz.
If fs = 1 kHz then the filter is designed for signals with frequencies between
0 and 500 Hz. Thus, the normalised cut-off frequencies are 0.2 and 0.4.
b = fir1(20, [0.2,0.4], ’band’, hann(21)); % Design FIR filter
freqz(b,1) % Plot filter’s frequency response
stem(0:20,b) % Plot FIR filter coefficients
xlabel(’n’) % Label stem plot
ylabel(’h[n]’) % Label stem plot
0.25 0
Magnitude (dB)
0.2 -50
0.15
-100
0.1
-150
0.05 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
h[n]
-0.05
Phase (degrees)
-0.1 0
-0.15
-500
-0.2
0 2 4 6 8 10 12 14 16 18 20 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
n Normalized Frequency ( rad/sample)
• filter – similar to conv but takes transfer function coefficients (or filter design
140 LESSON 15. COMPUTING WITH DIGITAL SIGNALS
• filtfilt – similar to filter but it actually filters twice (once forward and
once backward) so that there is zero phase distortion. As a result, the function
squares the magnitude (and doubles the order) of the original filter defined by
the transfer function.
y = filtfilt(b,a,x); % Default call with coefficient vectors a
and b. If FIR, a = 1
y = filtfilt(d,x); % Call with filter "d" returned by call to
designfilt
15.4 Summary
• Digital signals and systems are easy to represent directly in digital computers.
• MATLAB has very powerful tools for FIR and IIR filter design and analysis.
We can use these tools to implement many of the tasks that we have completed
“by hand” throughout this part of the notes, or to design systems that are more
complex than what we can readily do on paper.
(a) conv
(b) ztrans and iztrans (subs and double will also help)
(c) filter
Plot the outputs (using stem or some comparable plotting function) and com-
ment on differences.
2. Verify the results of Question 12.1, where you were asked to design an FIR
low pass filter with cut-off frequency Ωc = π/4 using L = 5 coefficients with
a rectangular window, and compare the time-domain and magnitude spectra
with that of a Hamming window. Find the impulse responses and spectra
using MATLAB.
Lesson 16
We now end the Digital part of the module in the way we started by re-visiting
analogue systems. However, we are not discussing signal conversion as we did in
Lesson 8. Instead, in this lesson we recap and highlight key similarities and differ-
ences between analogue and digital systems, signals, and their analysis. One of our
goals is to avoid confusion over which tools and transforms apply to which class of
systems. We also draw attention to the conversion of designs developed for one class
to be translated to the other, i.e., using the bilinear transform.
2. Understand the bi-linear transform to map between the analogue and digital
domains.
142
16.2. COMPARISON OF TRANSFORMS 143
• For an aperiodic (or simple periodic) continuous-time signal f (t), we can con-
vert to the Laplace domain (or s-domain) via the Laplace transform, which
for s = jω is the (continuous) Fourier transform. The Fourier transform of the
signal is its frequency response F (jω), and is generally defined for all ω. The
Laplace and Fourier transforms also have corresponding inverse transforms to
convert F (s) or F (jω) back to f (t).
• For a more complex periodic continuous-time signal f (t), the Fourier series
representation decomposes the signal into its frequency components Fk at mul-
tiples of the fundamental frequency ω0 . This can be interpreted as samples of
the frequency response F (jω), which then corresponds to periodicity of f (t)
over time. The coefficients Fk are found over one period of f (t).
• For discrete-time signal f [n], we can convert to the z-domain via the Z-
transform, which for z = ejΩ is the discrete-time Fourier transform. The
discrete-time Fourier transform of the signal is its frequency response F ejΩ
and repeats every 2π (i.e., sampling in time corresponds to periodicity in
frequency).
There are corresponding inverse transforms to convert F (z) or
jΩ
F e back to f [n].
• For discrete-time signal f [n] with finite length (or truncated to) N , we can
convert to the frequency domain using the discrete Fourier transform, which
is also discrete in frequency. The discrete Fourier transform also has N points
distributed over 2π and is otherwise periodic. Here, we see sampling in both
frequency and time, corresponding to periodicity in the other domain (that we
usually ignore in analysis and design because we define both the time domain
signal f [n] and frequency domain signal F [k] over one period of length N ).
With familiarity with the above, one could be given an arbitrary f (t), f [n], or
some transform F, and in principle we should know which transforms would apply.
In practice, you are not expected to memorise these differences. The emphasis here
is to present the transforms together so that we can see how they are qualitatively
related and distinguish between the circumstances where they can be applied.
One detail that is important to memorise is the nature of frequency when used
for continuous-time versus discrete-time systems. As noted above, any frequency
ω can be observed in a continuous-time function. The frequency range Ω in a
discrete-time function is only 2π, i.e., one trip around the unit circle, and the range
of frequencies covered by this circle varies according to the sampling frequency (if
we have frequencies beyond the range −π < Ω ≤ π, then they are aliased ). This
difference is evident when we consider system stability, as shown by the comparison
of stability regions in Fig. 16.2. For a system to be stable, its poles in the s-domain
144 LESSON 16. DIGITAL VS ANALOGUE RECAP
f (t) |F (jω) |
FT
⇐⇒
IFT
t ω
FS
⇐⇒
t ω
ω0
(c) Continuous-Time Periodic Signal (d) Fourier Series
|F ejΩ |
f [n]
DTFT
⇐⇒
IDTFT
n Ω
−π π
(e) Discrete-Time Signal (f) Discrete-Time Fourier Transform
f [n] |F [k] |
DFT
⇐⇒
IDFT
n kΩ0
(g) Finite Discrete-Time Signal (h) Discrete Fourier Transform
Figure 16.1: All frequency-based transforms that we have seen in this module.
16.3. BILINEAR TRANSFORM 145
must have negative real components, but poles in the z-domain must lie inside the
unit circle.
Im {s}
Im {z}
Re {s} Re {z}
|z| = 1
Let’s take a closer look to compare the Laplace and Z-transforms. We see
that there is a similar role being played by e−st and z −k . If we were to say
that we have a sampling period of Ts , then we could sample the complex
exponential at times t = kTs . By setting e−st = z −k , we then have z = esTs .
We can use this to do an approximate mapping between the s-domain and
z-domain. If we apply a Taylor series approximation (ea ≈ 1 + a), then we
146 LESSON 16. DIGITAL VS ANALOGUE RECAP
esTs /2
z = esTs =
e−sTs /2
1 + sTs /2
≈ ,
1 − sTs /2
which we can also re-arrange to write
2 z−1
s≈ .
Ts z + 1
This conversion is known as the bilinear transform, and it enables us to
take a filter that was designed in the s-domain and map it to the z-domain.
Doing so preserves stability and maps low frequency features very well. We
will not apply the transform directly in this module, but you may see it
elsewhere during your course.
16.4 Summary
• The transforms that we have applied throughout this module are generally
related to each other, but primarily differ in whether they apply to functions
that are continuous or discrete in frequency or time.
148
Lesson 17
The third part of this module is a brief study of Random Signal Processing.
Most practical signals contain an unknown component that could be undesirable
(e.g., thermal noise impairs all sensors) or intentional (e.g., communication signals
have embedded information that we need to learn). In this lesson, we provide a brief
overview of random probability distributions and some of the roles that random
variables can play in practical signal processing applications. Subsequent lessons
consider the estimation of signals in the presence of noise and measuring additional
characteristics of random signals.
149
150 LESSON 17. PROBABILITIES AND RANDOM SIGNALS
or practically any measurable quantity. Random variables can also be discrete (e.g.,
result of a coin toss) or continuous (e.g., impairments in a wireless communication
signal).
Mathematically, continuous random variables are described by their probability
density function (PDF), whereas discrete random variables are described by their
probability mass function (PMF). The notation for both types of distribution is
very similar. For random variable X that can take values between xmin and xmax
(which could be ±∞), p (x) is the probability that X = x. If X is discrete, then the
summation of these probabilities over all x is equal to 1, i.e.,
x
X max
p (x) = 1, (17.1)
x=xmin
and if X is continuous, then the integration of these probabilities over all x is equal
to 1, i.e.,
Z xmax
p (x) dx = 1. (17.2)
x=xmin
We can take the PMF summation or PDF integral over a subset of the domain of
X to calculate the probability of X being within that subset.
An important feature of a random variable is its moments. Roughly speaking,
they summarise the values that a random variable can take. The general formula
for the nth order moment of X E [X n ] is
x
X max Z xmax
n n n
E [X ] = x p (x) E [X ] = xn p (x) dx, (17.3)
x=xmin x=xmin
so it can be directly calculated from the first and second order moments. The
standard deviation is the square root of the variance.
Many distributions are defined in terms of their moments, as we will see in the
following.
17.2. RANDOM VARIABLES 151
p (x)
1
xmax −xmin
x
xmin 0 xmax
that have no dependency on each other (i.e., if knowing the value of one random
variable gives you no information to be able to better guess another random vari-
able, then those random variables are independent of each other). While we won’t
worry about the mathematical details of the CLT, we emphasise the relevance of
the Gaussian distribution and we will see it repeatedly in Lesson 18 when modelling
estimation problems.
p (x)
2
√ 1 exp − (x−0X)
2σ 2
2πσ 2
x
0
p (x)
True Distribution
Empirical Distribution
x
0
We have seen PDFs and PMFs that are analytical. Even though they describe
non-deterministic quantities, the distributions themselves can be written with an
equation. We emphasise that this does not mean that a set of samples that are drawn
from a distribution will exactly re-create the distribution. To observe behaviour that
would match a PDF or PMF, we require an infinite number of samples (random
variables drawn from the distribution). In practice, for a set of random variables
drawn from a distribution, we can make a histogram that divides our domain into
bins and we count the number of random variables that belong to each bin. If
we scale a histogram by the total number of samples, then we have an empirical
17.3. RANDOM SIGNALS 153
p (x)
0.5
Heads Tails
Figure 17.4: Empirical distribution from flipping a coin for Example 17.1.
1. All electronics exhibit thermal noise due to the agitation of electrons. This is
often modelled by adding a Gaussian random variable to the signal of interest.
3. Random variables can be used to store information, e.g., data can be encoded
into bits and delivered across a communication channel. A receiver does not
know the information in advance and can treat each bit as a Bernoulli random
variable that it needs to estimate.
4. Signals can be drastically transformed by the world around them before they
reach a transducer. Wireless signals can be obstructed by buildings and trees,
chemicals can react, musical instruments can have defects, etc. Effectively,
these analogue signals are passing through an unknown system h (t) and this
system can also vary with time. The variations in the system can be repre-
sented using random variables that describe the phenomenon under consid-
eration, e.g., there are particular distributions for the obstruction of wireless
signals.
17.4 Summary
• Continuous random variables are described by a probability density func-
tion (PDF) and discrete random variables are described by a probability
mass function (PMF).
2. Prove using the definition of the mean for a continuous random variable that
the mean of a uniformly-distributed random variable is µX = xmin +x
2
max
.
3. A random variable X is non-negative and has the PDF p (x) = kxe−x . Find
the following:
Signal Estimation
156
18.2. THE ESTIMATION PROBLEM 157
We assume that know the form of the function f (·) but not the value of φ.
However, we do assume that φ is constant. This is referred to as the classical
approach to estimation.
The Bayesian approach to estimation still assumes the form of the
function f (·) but it also assumes that φ is a random variable and we need
to estimate the current realisation of that random variable. In particular, it
is assumed that the probability distribution (whether a PDF or PMF) of φ
is known. This approach, which is based on the Bayes’ theorem, is useful
because it enables us to take advantage of any prior information that we
have about φ in the design of our estimator. Some popular approaches based
on the Bayesian approach include minimum mean square error estimation,
maximum a posteriori estimation, and Kalman filtering. You can read more
about these in Chapters 10-13 of Kay.
A common feature about both classical and Bayesian approaches is that
we assume knowledge about the function f (·). There are also more automated
methods that make no assumptions about the underlying function f (·). In-
stead, we try to learn about φ from simply the signal y [n] alone. Artificial
neural networks follow this approach.
and to include how A and B affect y [n] we build the observation matrix Θ. Since
here we have two parameters, the observation matrix is an N × 2 matrix structured
as follows:
1 0
1 1
Θ = 1 2 , (18.4)
.. ..
. .
1 N −1
where the first column reflects the fact that y [n] is a constant function of A and the
second column reflects the fact that y [n] is a linear function of B where the scaling
factor in the nth row is n.
This linear model problem can now be written as
~ + w,
~y = Θφ ~ (18.5)
and this form can be achieved for any linear model. Assuming that w
~ is a vector of
ˆ
~ (which minimises the variance
white Gaussian noise, then the optimal estimate φ
of the error ) for the parameters is
~ˆ = (ΘT Θ)−1 ΘT ~y ,
φ (18.6)
where ΘT is the transpose of the matrix Θ (i.e., every element swaps its row and
element indices). In this particular example, ΘT is
T 1 1 1 ··· 1
Θ = . (18.7)
0 1 2 ··· N − 1
Importantly, our signal y [n] can be more generally defined than in Eq. 18.2 and
still follow a linear model whose optimal estimate is given by Eq. 18.6. In particular:
• y [n] can depend on more variables than just the index n. For example, y [n]
could depend on the underlying continuous time t, or some other variable
that we must know or be able to measure for each sample in the sequence.
Importantly, y [n] does not need to depend on time at all, though we are
usually interested in time-varying signals in the context of this module.
• y [n] can include polynomial terms of the function variables. The linearity of
the linear model means that y [n] must be a linear function of the unknown
parameters.
For completeness, let us now write a more general form for the components in
Eq. 18.3. We assume that there are P unknown parameters and Q known variables
that can vary for each sample n. The structures of ~y and w~ are the same as in
18.3. LINEAR MODEL 161
Suppose that we have data that we want to match to a polynomial curve that
is a function of the underlying continuous time t, such that the nth sample is
at t = nTs . We write the time-domain function as
y (t) = φ1 + φ2 t + φ3 t2 + . . . φP tP −1 + w (t) ,
which we sample at times {0, Ts , 2Ts , . . . , (N − 1)Ts }. For this problem, the
observation matrix is
1 0 0 ... 0
1
Ts Ts2 ... TsP −1
1 2 P −1
Θ= 2T s 4T s . . . (2T s ) .
.. .. .. .. ..
. . . . .
2 2 P −1
1 (N − 1)Ts (N − 1) Ts . . . ((N − 1)Ts )
We recall from Lesson 12 that the difference equation for an M th order FIR
filter is
M
X
y [n] = b [k] x [n − k] ,
k=0
where the b [·] terms are the transfer function numerator coefficients (recall
that FIR filters have no feedback and hence there are no denominator coef-
ficients). The b [·] terms are also the tap multiplier coefficients in the imple-
mentation of the filter. In practice, there are many natural systems that we
can describe as a (noisy) FIR filter, where we need to estimate the filter taps
to learn about the system. We assume that we have a noise term such that
our actual observed signal is
M
X
y [n] = b [k] x [n − k] + w [n] ,
k=0
More generally, for any input function x [n], the observation matrix is
x [0] 0 0 ... 0
x [1] x [0] 0 ... 0
Θ = x [2] x [1] x [0] ... 0 .
.. .. .. . . .
.
. . . . .
x [N − 1] x [N − 2] x [N − 3] . . . x [N − (M + 1)]
We recall from Lesson 14 that the discrete Fourier transform (DFT) converts
a sequence of N data points into N spectral points. It can be shown that
the DFT is equivalently a linear estimation of the amplitudes of the sinusoid
components in the signal, such that Eq. 18.3 is equivalent to finding the DFT
coefficients. For more detail, refer to Example 4.2 of Kay. We clarify that
Kay uses the sinusoidal representation of the DFT, which is equivalent to the
complex exponential one that we studied in Lesson 14.
We make note of another generalisation of the linear model. Suppose that x [n]
includes a known signal component, such that is of the form
~ + ~s + w,
~y = Θφ ~ (18.12)
The form of Eq. 18.13 is convenient if we know that our signal is contaminated
by some large interference with known characteristics.
computer. Given data signal y (as a column vector) and linear observation matrix
Obs defined in MATLAB, the model estimate is simply
theta = Obs\y;
~ˆ = (ΘT W Θ)−1 ΘT W ~y ,
φ (18.14)
and we must rely on a more general approach for solving Eq. 18.14. Fortunately,
MATLAB has such a general purpose function for least squares problems called
lscov. First, we show that lscov can be used to find OLS estimates which is
equivalent to using the backslash operator:
theta = lscov(Obs,y);
Once again, we note that the signal y must be a column vector. To perform
weighted least squares, where we have a diagonal weight matrix W where the nth
18.5. MAXIMUM LIKELIHOOD ESTIMATION 165
diagonal element is W [n], we simply add the column vector of weights W [n] as a
third argument:
theta = lscov(Obs,y,W);
There are other interesting variations of least squares estimation available, but
the corresponding mathematics is too cumbersome for us to even present final results.
Sequential least squares (or recursive least squares) enables us to update a
least squares estimate as we add new data points, without needing to recalculate
the estimate from the entire data set. It can be performed in MATLAB using the
rlsFilt function in the DSP System Toolbox. Constrained least squares is a
generalisation where the unknown parameters must have constraints applied. For
example we might know that some parameters must be within a certain range, e.g.,
positive or negative, or that some of the unknown parameters depend on other
unknown parameters in some way. When the both the model and the constraints
are linear, constrained least squares can be performed using the lsqlin function in
the Optimization Toolbox.
3 of Kay.
18.7 Summary
• Signal estimation problems involve finding the values of unknown parame-
ters that are embedded in a signal of interest. These are found across all areas
of signal processing.
where we sample every Ts = 0.5 s for 3 s. Write out the complete observation
matrix Θ.
2. Suppose that we are try to estimate the filter coefficients b [·] of the system
defined by the difference equation
Determine the observation matrix Θ where we perturb this system with the
input sequence x [n] = {1, 0, 1, 1, 0}.
168 LESSON 18. SIGNAL ESTIMATION
We finish our brief study of random signal processing with additional mathematical
tools for comparing signals in both the time and frequency domains. These enable
us to quantify similarities between signals or how a signal varies with time. While
we will not cover the use of these tools in detail, they give us additional methods
for performing estimation of random signals.
19.2 Correlation
Correlation gives us a measure of time-domain similarity between two signals. Con-
sider pairs of data in Fig. 19.1. The data sets paired to make the blue circles are
highly correlated, whereas the data sets paired to make the red triangles are less
169
170 LESSON 19. CORRELATION AND POWER SPECTRAL DENSITY
correlated. Given discrete-time sequences x1 [n] and x2 [n] of length N , the cross-
correlation between them can be approximated as
1
RX1 X2 [k] ≈ (x1 [0] x2 [k] + x1 [1] x2 [k + 1] + x1 [2] x2 [k + 2] +
N −k
. . . + x1 [N ] x2 [k + N ]) (19.1)
N −1
1 X
= x1 [n] x2 [k + n] , (19.2)
N − k n=0
where k is the time shift of the x2 [n] sequence relative to the x1 [n] sequence. It is an
approximation because the signal lengths are finite and the signals could be random,
but in practice this is the form that is used to calculate the cross-correlation.
Variable 2
3
High Correlation
Moderate Correlation
2
Variable 1
0 1 2 3 4 5
For this module we are more concerned with calculating the cross-correlation
for specified sequences and not deriving it for random processes or continuous-
time signals. However, for completeness, the cross-correlation between deter-
19.2. CORRELATION 171
x1 [n] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5}
x2 [n] = {6, 8, 10, 0, 2, 4, 6, 8, 10, 0, 2, 4}
RX1 X2 [k] = {9.33, 8.55, 9.60, 13.33, 10.50, 8.86, 9.33, 6.40, 4.00, 3.33, 2.00, 0} .
We observe that the peak value of 13.33 occurs when k = 3. This makes sense
because we see that x2 [n] is twice x1 [n] and delayed by 3.
1. The autocorrelation for zero delay is the same as the signal’s mean square
value. The autocorrelation is never bigger for any non-zero delay.
172 LESSON 19. CORRELATION AND POWER SPECTRAL DENSITY
x [n] = {0, 1, 2, 3, 2, 1, 0}
As expected for autocorrelation, the peak value RXX [0] = 2.71 occurs when
k = 0, and this is also the mean square value of the signal.
and this will normalise the result properly. The input signals X1 and X2
must be of the same length (N ); also note their ordering. The output R will
19.2. CORRELATION 173
Consider the noisy signal in Fig. 19.2(a). Let’s say that we are trying to
detect whether the signal contains a sinusoid of a particular frequency
ω, i.e., whether
where w (t) is a random noise signal. We can assume that x (t) and
w (t) are uncorrelated. From the properties of autocorrelation, we know
that the autocorrelation of y (t) is the sum of the autocorrelations of
the two components (shown in Fig. 19.2(b) and (c)). Since random
noise should have no correlation at high τ , only the autocorrelation of
x (t) should remain after a certain time, so we should be able to recover
ω.
Alternatively, we could cross-correlate y (t) with another sinusoid
of our desired frequency ω. From this method the phase θ is also
recoverable, but we need to accurately know ω for this method.
y (t)
Rnoise (τ ) RXX (τ )
t τ
τ
(b) Autocorrelation of (c) Autocorrelation of Sig-
(a) Original Noisy Signal. Noise nal
Suppose that we have a “very long” random signal that it is effectively infinite
in duration. Such a signal is also infinite in energy, so we cannot find its
transform directly. However, we are not prevented from applying spectral
analysis because we can transform a function of the delay in the signal (i.e.,
the autocorrelation). The Fourier transform of an autocorrelation function is
known as the Power Spectral Density (PSD) SXX (ω) of the signal, and
in continuous-time it is defined as
Z ∞
SXX (ω) = RXX (τ ) e−jωτ dτ. (19.5)
−∞
The PSD gives the power per frequency interval in a signal. We can also
recover the autocorrelation from the PSD via an inverse Fourier transform:
Z ∞
1
RXX (τ ) = SXX (ω) ejωτ dω. (19.6)
2π −∞
We are not focusing here on the math of the power spectral density, but
we make note of several properties:
• PSD has non-negative real values as both power and frequency are real
19.4 Summary
• Correlation enables us to compare a signal with itself or with another signal.
2. Calculate the autocorrelation of x [n] = {1, −2, 3, −1, 0, −2, 1, 3, 2}. Verify
your result using MATLAB. What is the mean square value of the signal?
Part IV
177
Lesson 20
Image Processing
The fourth and final part of this module is a very brief study of Image Processing.
We introduce image processing as an application of filtering as we have studied it
in this module. Image processing is ideal for this purpose because we can “see” the
results, but we also need the concept of multi-dimensional signals. We are going
to take a simplified approach and focus on very small black-and-white or greyscale
images that can be readily processed by hand. We will also demonstrate several
MATLAB functions that can efficiently perform these tasks on much larger images
and in colour.
178
20.2. IMAGES AS SIGNALS 179
1. Binary – each pixel has value 0 or 1 to represent black and white, respectively.
2. Indexed – each pixel has one value within a range corresponding to a single
colour map. A colour map is a pre-determined list of colours and the index
refers to a row of colour data within the list.
3. Grayscale – each pixel has one value within a grayscale range between 0
(black) and 1 (white).
4. Truecolor – each pixel has three associated values corresponding to red, blue,
and green channels. These are referred to as RGB values, but it is also possible
to translate from other colour definition formats (e.g., HSV).
For convenience in applying image signal processing “by hand,” we will focus
on binary and grayscale images. These only need a single value to define a pixel,
and the meaning of each value is fairly intuitive (i.e., black, white, or something in
between). Thus, we only need a two-dimensional array to define an image signal,
which we will generally refer to using the notation f [i] [j]. We will follow the same
indexing conventions as MATLAB, where i refers to the vertical coordinate (i.e.,
row), j refers to the horizontal coordinate (i.e., column), and the numbering is such
that (i, j) = (1, 1) refers to the top left pixel. We show an example of pixel values
and coordinates in Fig. 20.2.
While grayscale colour values are supposed to be defined within the range [0, 1],
we will often write in whole numbers for convenience. We just need to normalise
the signal (e.g., by the highest value) before we try to view it as an image.
180 LESSON 20. IMAGE PROCESSING
(a) Image pixel values f [i] [j]. (b) Image pixel coordinates of form (i, j).
where x [n] is the input and h [n] describes the system’s impulse response. While
we noted that discrete-time convolution was easier to evaluate than continuous-
time convolution, we focused on the use of difference equations for our time-domain
analysis. Here, we re-introduce ourselves to discrete convolution with an example.
and we assume for consistency with MATLAB that the indexing starts at
n = 1 (such that h [n] = 0 and x [n] = 0 for n < 1). Sketch and compare the
input and output.
Using Eq. 20.1, we can find that
1 1
y [1] = x [1] h [1] = 1 × =
3 3
1 1
y [2] = x [1] h [2] + x [2] h [1] = 1 × +2× =1
3 3
1 1 1
y [3] = x [1] h [3] + x [2] h [2] + x [3] h [1] = 1 × + 2 × + 3 × = 2,
3 3 3
and so on. We will find that the output is
y [n] = {0.33, 1.00, 2.00, 3.00, 4.00, 4.33, 4.00, 3.00, 2.00, 1.00, 0.33} ,
and 0 for higher values of n. We plot the input and output to the same scale
in Fig. 20.3. We see that the output “follows” the input somewhat. In fact,
by inspection of h [n], this system is a moving-average filter that averages
over 3 samples.
x [n] y [n]
5 5
4 4
3 3
2 2
1 1
n n
0 1 2 3 4 5 6 7 8 9 10 11 12 13 0 1 2 3 4 5 6 7 8 9 10 11 12 13
(a) System Input. (b) System Output.
Let’s repeat Example 20.1 visually, as shown in Fig. 20.4. We start by drawing
out the arrays h [n] and x [n]. To convolve, we need to “flip” h [n] (which
in this case brings no change) and picture moving the flipped h [n] along the
array x [n]. Every time we advance h [n] by one element, we find the products
of the corresponding h [n] and x [n], add them together, and enter the sum in
the element of y [n] corresponding to the lead element of h [n]. By progressing
in this manner we find all of the elements of y [n]. We note that if h [n] has
length N and x [n] has length M , then y [n] has length N + M − 1.
1 1 1
3 3 3 1 2 3 4 5 4 3 2 1
0.33 1.00 2.00 3.00 4.00 4.33 4.00 3.00 2.00 1.00 0.33
mirroring all elements in h [i] [j] around the centre element. By symmetry,
h? [i] [j] is sometimes the same as h [i] [j].
2. Move the “flipped” impulse response h? [i] [j] along the input image x [i] [j].
3. Each time the kernel is moved, multiply all of the elements of h? [i] [j] by
the corresponding covered pixels in x [i] [j]. Add together the products and
store the sum in the output pixel y [i] [j] that corresponds to the “middle” pixel
covered by the kernel (we generally impose that h [i] [j] is a square matrix with
an odd number of rows and columns, so there is an unambiguous “middle”.).
We only need to consider overlaps between h? [i] [j] and x [i] [j] where the
middle element of the kernel covers a pixel in the input image.
The conv2 function for 2D convolution in MATLAB will use the lower
right element for output by default, but the middle element is used if passing
the option ’same’, i.e., keep the size of the output the same as the input.
The middle element is the default for the imfilter function.
We must also decide what to do when we are filtering at the edges of the image.
There are different possible conventions, including:
• Treat all “off-image” pixels as having value 0, i.e., x [i] [j] = 0 beyond the
defined image. This is known as zero-padding. This is the simplest but
could lead to unusual artefacts at the edges of the output image. This is the
only option for the conv2 function for 2D convolution in MATLAB, and the
default for the imfilter function which is specifically for images.
• Assume that “off-image” elements have the same values as the nearest element
along the edge of the image. For example, we could assume x [0] [1] = x [0] [0] =
x [1] [0] = x [1] [1], i.e., the pixels at the outside of a corner take the value of the
corner pixel. This is known as replicating the border, and is one of several
options for the imfilter function.
Now it is appropriate to discuss some common designs for the filter kernel h [i] [j].
We show several 3×3 examples in Fig. 20.5 (larger kernels have increased sensitivity
but are more expensive to compute). You will notice that the elements in a kernel
often add up to 0 or 1, such that the filter either removes signal strength to accen-
tuate certain details or maintains signal strength by re-distributing it, respectively.
The sample kernels are as follows:
• Low pass filter – shown in Fig. 20.5(a). It is equivalent to taking a weighted
average around the neighbourhood of a pixel.
• Blurring filter – shown in Fig. 20.5(b). It is very similar to the low pass
filter, but the sum of the elements adds up to more than one which “washes
out” an image more.
• High pass filter – shown in Fig. 20.5(c). This kernel accentuates transitions
between colours and can be used as a simple edge detector. Edge detection
is an important task in image processing since it is the first step towards
detecting objects in an image.
• Sobel operator – shown in Figs. 20.5(d) and (e). This kernel is more effective
for detecting edges than a high pass filter, but we need to apply separate
kernels for different directions. The X-gradient operator shown is for detecting
vertical edges of objects, and the Y-gradient operator shown is for detecting
the horizontal edges of objects.
20.4. IMAGE FILTERING 185
(a) Low pass filter. (b) Blurring filter. (c) High pass filter.
-1 0 1 1 2 1
-2 0 2 0 0 0
-1 0 1 -1 -2 -1
Figure 20.5: Examples of filter kernel h [i] [j]. h? [i] [j] is the same for (a), (b), and
(c), but we need to swap the signs of the elements in (d) and (e).
Apply the high pass filter shown in Fig. 20.5(c) to the image matrix in
Fig. 20.6(a). Assume that the image is zero-padded.
We note that the kernel is the same as its mirror, i.e., h? [i] [j] = h [i] [j]
We start by placing the middle element of h? [i] [j] (-4) over the top left pixel
of x [i] [j] and add up the products of overlapping elements to determine the
output value at this pixel. Going element-by-element, we show the result in
Fig. 20.6(b). We see that there are accentuated transitions along what were
the edges of the boundary in x [i] [j]. As expected, this filter kernel can be
used as an edge detector.
Although what we have covered is the foundation of image filtering and could
be used for practical applications, there are other ways to filter an image
186 LESSON 20. IMAGE PROCESSING
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 0 0
1 1 1 0 0 -1 -1 -2 1 0
1 1 1 0 0 -1 0 -1 1 0
1 1 1 0 0 -2 -1 -2 1 0
(a) Input image x [i] [j]. (b) Output image y [i] [j].
which your workspace will show is a 384×512×3 array of unit8s (i.e., unsigned 8-bit
integers for each of red, green, and blue in every pixel). Other interesting examples
include ngc6543a.jpg and coins.png. There doesn’t appear to be a centralised
list (unless you do a web search), but most example images are used throughout
the MATLAB documentation for the Image Processing Toolbox. Of course, you can
also import your own images using imread and referring to the relative directory
where your images are stored. Most image formats are compatible (e.g., tif, png,
jpg, bmp). Finally, you could create your own images directly in code, which could
be helpful to verify filtering that you perform by hand.
MATLAB provides many default filter kernels available (see the MATLAB doc-
umentation page on “Image Filtering and Enhancement” for an overview), but we
will focus on using the simple kernels that we have already defined in this lesson.
These kernels can be implemented by creating a 3 × 3 matrix with the appropriate
elements. To apply a kernel to an image, we can use the default 2D convolution func-
tion conv2 for grayscale images, or the Image Processing Toolbox function imfilter
more generally.
Apply all of the filters described in Fig. 20.5 to the image ’peppers.png’.
Code to apply the low pass filter is as follows:
h = ones(3)/9; % Equivalently h =
[1/9,1/9,1/9;1/9,1/9,1/9;1/9,1/9,1/9]
P = imread(’peppers.png’);
output = imfilter(P,h,’conv’);
figure; imshow(output)
We show the result for this and all other filters in Fig. 20.7. We note that
the Sobel operators accentuate edges much more strongly than the high pass
filter, but the high pass filter is able to accentuate edges in all directions at
once.
We note that imfilter uses correlation and not convolution for filtering by
default. We added the ’conv’ argument to force convolution for consistency
with our discussion here. In practice the two operations are quite similar;
188 LESSON 20. IMAGE PROCESSING
correlation is essentially the same but without the “flipping” of the impulse
response. For symmetric kernels like the low pass filter, blurring filter, and
20.6. SUMMARY 189
high pass filter there is no difference, but for the Sobel operators it would
be necessary to mirror the kernel in order to achieve the same result with
correlation.
We also note that, when applied to standard image arrays (typically com-
posed of unsigned 8-bit integers), the imfilter function will discard results
with negative values and set the values in those pixels to 0.
20.6 Summary
• Images are signals defined over two-dimensional space. We can extend signal
processing ideas covered earlier in this module once we account for the extra
dimension(s).
• Section 9.6 of “Essential MATLAB for engineers and scientists,” B. Hahn and
D. Valentine, Academic Press, 7th Edition, 2019.
2. Consider the image in Fig. 20.9. We want to detect the object in the im-
age. What kernel options do we have to detect the edges and what are their
strengths? Filter with the possible kernels and comment on the results. Verify
your results in MATLAB.
190 LESSON 20. IMAGE PROCESSING
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
0 0 0 0 0
0 0 1 1 0
0 0 1 1 0
0 0 1 1 0
0 0 0 0 0
Appendices
191
Appendix A
Mathematical Background
where K and the ps are constants. Partial fraction expansion re-writes this ratio
as a sum of ratios. The key detail is that we want each denominator to be a linear
function of s. Thus, we need our transfer function in the form
A B C
H (s) = + + + ... (A.3)
(s − p1 ) (s − p2 ) (s − p3 )
192
A.1. PARTIAL FRACTIONS 193
and we need to solve for the numerators. To do so, we need to cross-multiply the
ratios in Eq. A.3 so that we get a polynomial that we equate with the numerator of
Eq. A.1. We can then write a linear equation for each power of s. In other words,
we equate
multiply through the terms on the left, and compare powers of s on both sides to
solve for A, B, etc. The following is a simple example.
5s + 10 5s + 10 A B
= = + .
s2 + 3s − 4 (s + 4)(s − 1) s+4 s−1
We cross multiply to get
A+B =5
4B − A = 10
Next, we consider a more challenging example where we cannot factor the de-
nominator into linear terms without one (or more) of the ps having an imaginary
component. In such a case, we will find it more useful to leave the corresponding
denominator term(s) as higher order (usually second order) functions of s. The key
thing to remember in this case is that the corresponding numerator term(s) need to
be 1 order lower than the denominator terms. The following is an example of this.
194 APPENDIX A. MATHEMATICAL BACKGROUND
2s − 7 2s − 7 A Bs + C
= = + 2 .
s3 2
+ 2s + s 2
s(s + 2s + 1) s s + 2s + 1
We cross multiply to get
A+B =0
2A + C = 2
A = −7
Find
Z ∞
y= xe−x dx,
0
A.3. EULER’S FORMULA 195
ejx + e−jx
cos(x) = (A.7)
2
e − e−jx
jx
sin(x) = . (A.8)
2j
Show the validity of Eq. A.7. From Eq. A.6 we can write
sinc(x)
x
−2π −π π 2π
Answers/Hints to End-of-Lesson
Problems
B.1 Lesson 2
1. The Laplace transforms are
8
(a) F (s) = s3
4s
(b) F (s) = (s2 +4)2
2 2
(c) F (s) = (s−2)2
+ s3
s−1
(d) F (s) = (s−3)2 +4
4(s+3)
(e) F (s) = (s2 +6s+13)2
3. f (t) = e2t − et .
197
7. Write equations for voltage drops over each loop.
R2
H (s) =
s2 LCR1 + s(L + CR1 R2 ) + R1 + R2
8. Write 3 equations for currents (current coming out of node to right of R1 and
C1 , current through R2 , and current through C2 ). These are all the same
current. Combine to solve.
(1 + sR1 C1 )(1 + sR2 C2 )
H (s) =
s2 R 1 C1 R2 C2 + s(R1 C1 + R2 C2 + R1 C2 ) + 1
9. A perfect op-amp has no current coming in or out of any of its terminals, and
there is no voltage drop across the input terminals. This enables you to write
2 current equations that are equal (current through the capacitor and R1 , and
current through R2 ).
−sR2 C
H (s) =
1 + sR1 C
B.2 Lesson 3
1
1. There are zeros at s = {−25, − 11 }; poles are at s = {−0.08, −29.56}
2. The poles are at s = −23.33 ± j11.06 and the system is stable.
s2 −s
3. The transfer function is H (s) = s2 +2s+2
and the system is stable.
4. (a) s = 1, unstable; (b) s = ±jω, marginally stable; (c) s = −1 ± 3j, stable.
B.3 Lesson 4
1. The plots are as shown in Fig. B.1:
2. The plots are as shown in Fig. B.2:
3. This question is a proof.
B.4 Lesson 5
1. The ideal low pass filter frequency response is unrealisable because a rectangle
function in the frequency domain is a sinc function in the time domain. The
sinc function is defined for all time, including t < 0, so the ideal filter must
respond to input before the input is applied, which is impossible.
198
Im {s} 6 H (jω)
π
2
|H (jω) |
π
4
(-1,0) 1
Re {s}
ω ω
0
0.5 ω
0
(-2,0) − π2
Re {s}
(-1,0)
ω −π
2. G = −42.3 dB.
B.5 Lesson 6
1. There will be 3 sinusoidal terms at the output with frequencies 1.6π/τ , 2π/τ ,
and 2.4π/τ .
B.6 Lesson 7
1. The following function will find the system output for any input frequency
omega:
199
function y = analogue_output_example(omega)
% Find output to my low pass filter
R = 2; C = 1; L = 2;
% Create symbolic variables
syms t s
% Create symbolic functions for input and system
x = sin(omega*t);
H = R/(s^2*L*C*R + s*(L+C*R^2)+2*R);
% Convert input to Laplace, solve, and convert output to time
X = laplace(x); Y = H*X; y = ilaplace(Y);
Note that symbolic math will leave real numbers as fractions whenever possi-
ble.
2. The following function should work and return both the upper bound and
lower bound cutoff frequencies. All of the equations are implementations of
those in Lesson 5.
function [cutoff, order] = butterworth_design(gainPass,
gainStop, radPass, radStop)
% gainPass - target pass band gain in dB
% gainStop - target stop band gain in dB
order =
ceil(log10((10^(-gainStop/10)-1)/(10^(-gainPass/10)-1))...
/2/log10(radStop/radPass));
cutoff(1) = radPass/(10^(-gainPass/10)-1)^(1/2/order);
cutoff(2) = radStop/(10^(-gainStop/10)-1)^(1/2/order);
B.7 Lesson 8
1. This question is a proof. You need to show that f2 [n] = cos (nω1 Ts ) = f1 [n].
1
2. Largest error is 2(2W −1)
.
200
3. Resolution is 0.024 %; dynamic range is 72.25 dB.
B.8 Lesson 9
1. The Z-transforms are
(a) F1 (z) = 1 + z −1
1
(b) F2 (z) = 1−z −1
1
(c) F3 (z) = 1−0.5z −1
2−z −2
(d) F4 (z) = 1−z −1
4. This question can be solved two ways, but it is faster to solve in the z-domain.
y [n] = {1, 3, 3, 5, 3, 7, 4, 3, 3, 0, 1}.
5. Y (z) = 6 + z −1 − 2z −2 .
1+z
6. H (z) = 2z
.
Ts z
7. y [n] = y [n − 1] + Ts x [n], H (z) = z−1
.
B.9 Lesson 10
z 2
1. H (z) = z2 −0.6z+0.5 . There are poles at z = 0.3 ± 0.64j and two zeros at z = 0.
The system is stable.
201
B.10 Lesson 11
z2
1. H (z) = (z+0.9)2
. When Ω = π, the phase is 0.
B.11 Lesson 12
1. y [n] = x [n] − 2x [n − 1] + x [n − 2]; H (z) = (z 2 − 2z + 1)/z 2 ; this is an FIR
high pass filter. The filter in Fig. 12.6 has a multiplier of 2 instead of −2 and
it is a low pass filter.
3. This is an FIR filter (no poles are shown so they are assumed to be at the
origin). The frequency response has a magnitude of 1 at Ω = 0, 0 at Ω = π/3,
and 3 at Ω = π. This is a band stop filter. Although the pass bands have
different gains, the stop band is implemented effectively.
4. This filter has 2 zeros at z = −0.5 ± j0.5 and poles at z = 0.5 ± j0.5. It is a
stable 2nd order low pass filter.
5. The magnitude of the frequency response is 0.6154, 2.2188, and 8 at the fre-
quencies Ω = {0, π/2, π}, respectively. Hence, this is a high pass filter. The
transfer function is
1 − 2z −1 + 2z −2
H (z) = ,
1 + 0.5z −1 + 0.125z −2
202
x [n]
2 −2
y [n]
+ D + D +
− 81 −0.5
B.12 Lesson 13
1. The filters are:
We plot the FIR impulse responses and magnitude spectra in Fig. B.4.
π rad π rad
2. (a) Ωp = 25 sample
, Ωs = 10 sample
.
(b) Need L = 105.
(c) The stop band gain of the rectangular filter is only Gs = −20.9 dB, which
is less than the target stop band gain, so such a filter cannot meet the
design specification.
203
|H ejΩ |
h [n]
1
4
1
ω
n −π π
1 2 3 4 5 6 7 8
Rectangular Filter
Hamming Filter
Rectangular Filter Hamming Filter Ideal Filter
B.13 Lesson 14
1. From calculations we find that
√ √
X [k] = {4, 1 + j 3, 1 − j 3}, 0 ≤ n ≤ 2
X ejΩ = 4e−jΩ cos(Ω)
2. To sample the sinusoids with frequencies fs /16 and fs /4, multiply the sinusoid
argument in Example 14.3 by 4 and 16, respectively. The magnitude spectra
of their sum are shown in Fig. B.6.
204
35
30
25
20
|X[k]|
15
10
0
0 10 20 30 40 50 60 70
Spectral Index k
B.14 Lesson 15
1. Code to find and plot the outputs is as follows:
syms n z
205
figure; hold on;
subplot(3,1,1)
stem(0:(L-1),y1,’k’)
legend(’conv’)
subplot(3,1,2)
stem(0:(L-1),y2,’b’)
legend(’symbolic’)
subplot(3,1,3)
stem(0:(length(i)-1),y3,’r’)
legend(’filter’)
We plot the resulting figure in Fig. B.7. We see that the results look nearly
identical, except that filter does not evaluate the final 4 time steps (i.e.,
those beyond the existence of the input) and the symbolic approach behaves
as if the input continues indefinitely. In each case the filter output is a sinusoid
with about half the amplitude of the input signal.
0.5
conv
-0.5
0 5 10 15 20 25 30 35 40 45
0.5
symbolic
-0.5
0 5 10 15 20 25 30 35 40 45
0.5
filter
-0.5
0 5 10 15 20 25 30 35 40
2. Code to design the filters and plot their responses is as follows (we set the
filter design to not scale to make sure we can directly compare with our design
by hand):
bRect = fir1(4, 0.25, ’low’, rectwin(5), ’noscale’); %
Rectangular filter
206
bHamm = fir1(4, 0.25, ’low’, hamming(5), ’noscale’); % Hamming
filter
figure
freqz(bRect,1)
title(’Rectangular Window Filter’)
figure;
freqz(bHamm,1)
title(’Hamming Window Filter’)
We plot the resulting figures in Figs. B.8-B.10. We include several data points
in the magnitude responses (that we can convert to linear form) to help verify
the design in Question 12.1.
B.15 Lesson 17
1. If xmin = xmax , then the random variable is deterministic and not actually a
random variable.
207
Rectangular Window Impulse Response
0.3
0.2
h[n]
0.1
0
0 0.5 1 1.5 2 2.5 3 3.5 4
n
Hamming Window Impulse Response
0.3
0.2
h[n]
0.1
0
0 0.5 1 1.5 2 2.5 3 3.5 4
n
Y 0.1589
Y -4.908
-50
-100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
100
Phase (degrees)
-100
-200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
208
Hamming Window Filter
0
Magnitude (dB)
-10 X0
X 0.25
Y -5.704
Y -7.496
-20
-30
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
0
Phase (degrees)
-100
-200
-300
-400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
B.16 Lesson 18
1 0 0 0
1 0.5 0.25 0.125
1 1.0 1.0 1.0
1
Θ= 1.5 2.25 3.375
.
1 2.0 4 8.0
1 2.5 6.25 15.625
1 3.0 9 27
1 0 0
0 1 0
1
Θ= 0 1
.
1 1 0
0 1 1
209
3. The weight vector should be
0.5
0.5
0.5
0.5
0.5
~
W=
0.2 .
0.2
0.2
0.2
0.2
4. Code to generate the Poisson realisations and estimate the mean using a max-
imum likelihood estimator is as follows:
lambda = 5; % Poisson mean
y = poissrnd(lambda,1,100); % Generate random numbers from
Poisson distribution
lambdaEst = mle(y, ’distribution’, ’poiss’); % Max. Likelihood
estimate of lambda
B.17 Lesson 19
1. RX1 X2 [k] = {−7.33, −8.00, −11.50, −7.33, −9.00, −18}. The highest correla-
tion occurs when k = 5 because these two signals differ by a factor of −1
except that the second signal is shifted by 5 (which in this case is also equal
to 5 − N = −1).
2. RXX [k] = {3.67, −0.50, 0.43, −2.00, 0.80, 0.75, 0.33, −0.50, 2.00}. The mean
square value is RXX [0] = 3.67.
B.18 Lesson 20
1. The filter output is shown in Fig. B.11. This low pass filter kernel has smoothed
the abrupt transitions between 0s and 1s.
2. To detect the edges we could use a high pass filter or Sobel operators. The
high pass filter only needs to be applied once, but Sobel operators will ac-
centuate the edges more clearly. We show the output to the high pass filter
210
0.22 0.33 0.33 0.33 0.22
and the X gradient Sobel operator in Fig. B.12. From the high pass filter we
see transitions from negative to positive values along all 4 edges. The Sobel
filter output only has negative to positive transitions along the right edge and
positive to negative transitions along the left edge, but they are much stronger
transitions.
0 0 1 1 0 0 -1 -1 1 1
0 1 -2 -2 1 0 -3 -3 3 3
0 1 -1 -1 1 0 -4 -4 4 4
0 1 -2 -2 1 0 -3 -3 3 3
0 0 1 1 0 0 -1 -1 1 1
(a) High pass filter output. (b) X gradient Sobel filter output.
211