Lecture Notes
Lecture Notes
Lecture Notes
D R D ENNIS D ENG
1
Preface
This is the first draft of the lecture notes for ELE32DSP. Your comments and feedbacks are wel-
come. Send your comments/corrections to: d.deng@latrobe.edu.au
The first draft was finished on August 17, 2001. In version 1.1, some typing errors identified by
Mr Finn Thain (ELE32DSP student) are fixed. Last revised: July 2008.
I intend to use it as the key teaching material for this subject. However, it is not a text book. It can
not replace the recommended text book.
The textbook for this subject is "DSP First A Multimedia Approach", by J. H. McClellan, R. W.
Schafer and M. A. Yoder. This book is published by Prentice Hall.
2
3
Contents
1 Introduction 7
1.0.1 Signals and systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.0.2 Advantages of using DSP . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.0.3 Applications of DSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.0.4 Notations and representations . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.0.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.1 Text book and reference books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2 How to study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3 Self-test Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 Matlab 16
3.1 Matrix operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 File input and output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 Matlab script and function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4 Self-test Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6 Problem class-1 38
4
8 z-Transform 48
8.1 Definition and properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
8.2 The z-transform and the Fourier transform . . . . . . . . . . . . . . . . . . . . . . . 50
8.3 The z-transform as an operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
8.4 Region of convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.5 The Inverse z-transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
8.6 Self-test exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5
13.3.2 Design procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
13.3.3 Design examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
13.4 Self-test exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
14 Applications of DSP 97
14.1 Audio signal processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
14.1.1 Reverberation effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
14.1.2 Equalizers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
14.1.3 Digital FM stereo generation . . . . . . . . . . . . . . . . . . . . . . . . . . 97
14.2 Number representations in digital signal processors . . . . . . . . . . . . . . . . . . 97
14.2.1 Fix point representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
14.2.2 Floating point representation . . . . . . . . . . . . . . . . . . . . . . . . . . 98
14.3 Quantization effects of filter coefficients . . . . . . . . . . . . . . . . . . . . . . . . 99
14.4 Fix point digital signal processor-TMS320c5x . . . . . . . . . . . . . . . . . . . . . 101
14.4.1 Addressing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
14.4.2 Implementing an FIR filter . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
14.4.3 The assembler source code . . . . . . . . . . . . . . . . . . . . . . . . . . 104
6
1 Introduction
In this lecture, we try to answer the following questions relating to digital signal processing (DSP).
What is it about? What is the advantage of using DSP? What are the major applications of DSP? Can
you show me a few simple examples?
• perfectly reproducible
x[n] = {1, 0.5, −0.5, −1, −0.5, 0.5, 1, 0.5, −0.5, −1}
1 This part is still being written.
7
x = cos(πn/3)
1
0.8
0.6
0.4
0.2
−0.2
−0.4
−0.6
−0.8
−1
0 1 2 3 4 5 6 7 8 9
In this case it is important to indicate the location where n = 0. This is an important reference point.
I will use an up-arrow to point to that signal value. When the signal is represented in this way, it is
assumed that signal values at unspecified locations are zero. We make this assumption throughtout
this unit. We can also visualize the signal in Matlab by using the following codes:
n = 0 : 9;
x = cos( pi * n / 3 );
figure;
stem( n, x );
title(’ x = cos(\pin/3) ’ ); % \pi is π
The figure is shown in fig. 1below.
Therefore, a discrete signal can be represented by using an equation, by specifically listing signal
values and by using a figure.
1.0.5 Examples
A simple linear filter is the moving average filter that is defined as:
1 1
y[n] = ∑ x[n − k]
3 k=−1
where x[n] and y[n] represents the input and the output signals of the filter (system) at index n. A
simple nonlinear filter is the median filter that is defined as:
where the output signal y[n] is the median value of the three input samples. For example, if x[n−1] = 7,
x[n] = 2, x[n + 1] = 11, then y[n] = med{7, 2, 11} = 2.
If a data sequence, u[n] = {0, 0, 0, 0, 0, 5, 5, 5, 5, 5}, is corrupted by noise and the resulting noisy
data sequence is given by x[n] = {0, 7, 0, 0, 0, 10, 5, 5, −3, 5}. We can apply the above two filters to the
noisy signal to see if they can remove the noise. Figure 2 shows A plot of the original signal, the noisy
signal and the results of the two simple filters.
We can also apply these two filters to digital images. Results are shown in Figure 3. We can see
that the median filter is useful for filtering out impulse noise.
The moving average filter is a useful filter for a number of noise filtering applications. For ex-
ample, a cosine signal, given by u[n] = cos(2πω0 + 0.1π), is corrupted by Gaussian noise. The noisy
8
6
original signal
4
0
1 2 3 4 5 6 7 8 9 10
10
5 noisy signal
−5
1 2 3 4 5 6 7 8 9 10
10
0
1 2 3 4 5 6 7 8 9 10
6
0
1 2 3 4 5 6 7 8 9 10
Figure 2: A plot of the original signal, the noisy signal and the results of the two simple filters.
Figure 3: From left to right, top to bottom, the original image, the noisy image, output of a median
filter, output of a moving average filter.
9
1 2
1.5
0.5
1
0 0.5
0 noisy
−0.5 original signal
signal −0.5
−1 −1
0 20 40 60 80 100 0 20 40 60 80 100
2 1.5
1.5
1
1
0.5 0.5
0
N=1 N=10
0
−0.5
−1 −0.5
0 20 40 60 80 100 0 20 40 60 80 100
Figure 4: The outputs of the moving average filter with N=1 (bottom left) N=10 (bottom right)
signal is x[n] = u[n] + r[n], where r[n] represents the noise signal. We can use the moving average filter
to remove the noise. A generalized form of the filter is
N
1
y[n] = ∑ x[n − k]
2N + 1 k=−N
where N controls the number of samples involves in the averaging operation. Figure 4 shows two
cases with N = 1 and N = 10, respectively.
• R. D. Strum and S. E. Kirk, First Principles of Discrete Systems and Digital Signal Processing,
Addison Wesley, 1988
• S. K. Mitra, Digital Signal Processing A Computer Based Approach, McGraw Hill, 1998
• J. G. Proakis and D. G. Manolakis, Digital Signal Processing Principles, Algorithms and Ap-
plications, 3rd ed., Prentice-Hall, 1996
10
I hear, I forget
I see, I remember
I do, I understand
• Modify the filter such that only the past and current input samples are used.
• The moving average filter can also be implemented in a recursive form: y[n] = ay[n − 1] +
b(x[n] − x[n − N]). Determine the two constants a and b.
Answer:
• y[n] = 1
N ∑0k=N−1 x[n − k]
• Ny[n − 1] = ∑0k=N−1 x[n − k − 1], N(y[n] − y[n − 1]) = x[n] − x[n − N], a = 1, b = 1
N
11
s(t) s(t+1) s(t−2)
t t t
Ω0 = 2π f0
which determines how fast it oscillates. The period of the signal is T0 = f10 . For example, when the
frequency is 10 kHz, its radian frequency is 20,000π rad/sec and the period is T0 = 0.1 ms. Note that
this cosine signal is an analog signal. Its frequency can go very high. Later on we will see that for a
discrete cosine signal, its highest frequency is π.
The phase shift is related to the time-shift of a signal. Let s(t) represent a signal. Then s(t − t0 )
represents a time-shifted version of the original signal. When t0 > 0, the signal is delayed in time
(shifted to the right). When t0 < 0 , the signal is advanced in time (shifted to the left).
It is easy to determine the relationship between the time-shift and the phase shift of a cosine signal
x(t) = cos(Ωot). A time-shifted signal is
Therefore the phase shift is: φ = −Ω0 τ. Another interpretation is that given the phase shift, the time
delay is:
φ φ
τ=− =−
Ω0 2π f0
Note that if the phase shift caused by the time shift is greater than 2π, then it must be converted to the
principal value between −π and π.
A discrete cosine signal can be generated by evaluating the analog cosine signal at a discrete set
of times, tn = nTs , where n is an integer, Ts is called the sampling period. By sampling, we obtain a
sequence of data:
x[n] = x(nTs ) = cos(2π f0 nTs + φ)
The index n represents the order of the data samples. Unless we know Ts , the time between any two
samples, for example, between x[n − 1] and x[n + 3] is unknown.
2 We use Ω to represent the radian frequency of an analog signal and ω to represent that of a discrete time signal. This
12
20
10
−10
−20
−0.04 −0.03 −0.02 −0.01 0 0.01 0.02 0.03
20
10
−10
−20
−8 −6 −4 −2 0 2 4 6
Figure 6: Discrete cosine signal, sampling period = 0.005 sec. Top: using the plot command. Bottom:
using the stem command. Note that when we use the stem command, we plot the signal against the
location index n.
In Matlab, a sequence of data is usually stored as a row or a column vector. Several related or
unrelated data sequences can be stored in a matrix. The following Matlab code shows you how to
generate and plot cosine signals:
n = -7 : 5 ; %index
Ts = 0.005; %sampling period
tn = n * Ts ;
xn = 20 * cos ( 80 * pi * tn + 0.4*pi); % f0 = 40, φ = 0.4π
subplot ( 211 ) %put more than one signal in on figure
plot ( tn , xn ) %plot the signal against time
subplot ( 212 )
stem( n, xn ) %it is different from plot
• Rectangular form: z = x + jy
• Polar form: z = re jθ
√
where x, y, r and θ are real numbers and j = −1. These two representations are related by:
p
r = x2 + y2
and
y
θ = arctan( )
x
A geometric view is shown in Figure 7.
13
y
θ x
e jθ = cos θ + j sin θ
14
Addition, subtraction and division of two complex numbers have interesting geometric interpreta-
tions.
In DSP, we are interested in the frequency response of a filter. The frequency response, de-
noted by H(ω), is the Fourier transform of the impulse response, denoted by h[n]. The frequency
response is usually a function of the complex variable e jω . As such, it can be represented as H(ω) =
|H(ω)|e j∠H(ω) , where the amplitude response is |H(ω)| and the phase response is ∠H(ω). For the
amplitude response, it can be calculated as follows
where H ∗ (ω) is the complex conjugate of H(ω). For example, if we have H(ω) = 1 − e− jω , then
H ∗ (ω) = 1 − e jω and
• Determine the amplitude and phase for the complex number z = 1 + e− j2ω0
Answer:
• zn = e jnπ/3 , n = 0, 1, ..., 5.
jω0 +e− jω0
• z = 2e− jω0 e 2 = 2 cos ω0 e− jω0
15
3 Matlab
This lecture is based on Appendix B of the text book, where you can find more examples.
So you can see some of the data processing features of Matlab. For example, to implement the last
operation, a threshold operation on each element of a matrix, with other high level languages such as
C, you would need to use two for-loops. But in Matlab, it is just a command line.
Actually, Matlab is optimized for such “vectorized” operation. A vectorized operation such as this
last operation runs in most case faster (or a lot more faster in some cases) than using the for-loop.
Therefore, you should avoid using for-loops in Matlab. Here is one more example that shows the
vectorized operation. The task is to calculate the entropy of an information source that contains N
symbols:
N
E = − ∑ p[n] log2 (p[n])
n=1
where p[n] is the probability of the nth symbol. The Matlab code is:
3A Matlab command is shown in typewriter font.
16
%define the probability pn first
pn = [ 0.1 0.2 0.05 0.05 0.3 0.3 ];
E = -sum ( pn .* log2 ( pn ) )
Matlab also provides program flow functionality such as if statements, while loops and for
loops.
function y = threshold(x, t)
%threshold y = x>=t ;
%usage:
% y = threshold(x, t)
%where:
% y = output
% x = input
% t = threshold
y = ( x >= t ) ; %note >= is one operation, no space in between
• Write a Matlab function to calculate the mean square value of a vector or a matrix.
17
4 Signal and system representation in the time domain
We will spend two lectures on this section. In the first lecture, we will discuss three topics:
18
10 10
x[n] x[n−2]
5 5
0 0
−5 −5
−10 −10
0 1 2 3 0 1 2 3 4 5
10 10
x[n+2] x[−n]
5 5
0 0
−5 −5
−10 −10
−2 −1 0 1 2 3 −3 −2 −1 0
Figure 8: A plot of four signals, top left x[n], top right x[n − 2], bottom left x[n + 2], bottom right
x[−n].
In general, a discrete signal can be represented as a linear combination of unit sample sequences:
∞
x[n] = ∑ x[m]δ[n − m]
m=−∞
Note that x[m] inside the summation represents a data sample at location (index) m and δ[n − m] is a
delayed version of the unit sample sequence. It is delayed by m samples such that the only non-zero
sample is at index m. For the above example, we have:
19
since
e j(2knπ) = cos(2knπ) + j sin(2knπ) = 1
Therefore, we only need to consider frequency in the interval of 0 ≤ ω < 2π for the discrete complex
exponential signal. This is different from analog signals, where a very high frequency is possible.
Next we take a look at the cosine signal
x[n] = cos(ωn + φ)
If we make a new cosine signal, denoted by x1 [n], with the same phase shift and the frequency ω1 =
ω + 2kπ, where k is an integer. We can easily see that x[n] = x1 [n], the two signals are exactly the
same. This implies that the two frequencies are indistinguishable. What is the interpretation of a high
frequency and a low frequency for the discrete time signal?
Since frequency is used to indicate the rate of oscillation, a higher frequency means faster os-
cillation. When the frequency is zero, there is no oscillation at all. So the lowest frequency is zero
(ω = 2kπ). This can be verified by:
What is the fastest oscillation for a cosine signal? From Figure 9, which shows cosine signals with
different frequencies, we can see that π (or π + 2kπ) is the highest frequency. This is because when
the frequency gradually increases from 0 to π, the oscillation becomes faster. You can imagine (show
it with Matlab, see self-test exercise) that as the frequency gradually increases from π to 2π, the
oscillation becomes slower. In fact, let us consider the cosine signal x[n] = cos(ωn) and let ω = π + ω0
(0 < ω0 ≤ π). We can rewrite it as ω = 2π − (π − ω0 ) = 2π − ω1 where ω1 = π − ω0 . Therefore
x[n] = cos(ωn)
= cos((π + ω0 )n)
= cos(2πn − (π − ω0 )n)
= cos((π − ω0 )n)
= cos(ω1 n)
As such, we can say the two frequencies ω and ω1 are the same. When ω is increased from π to 2π,
ω0 is increased from 0 to π, and ω1 is decreased from π to zero. Therefore, the highest frequency is π
and the lowest frequency is 0.
One student asked me the following question: I can understand the development of the idea using
the cosine signal, but what would be the conclusion if we use a sine signal? This is a good question.
Actually, using the cosine signal is a way to illustrate different speeds of oscillation relating to different
settings of ω. It is intuitively understandable that the fastest oscillation is represented by the signal
x[n] = {1, −1, 1, −1, 1, −1, ...} which is the same as the cosine signal cos(πn). However, when we use
a sine signal, x[n] = sin(ωn), the fastest oscillation we can get is by setting ω = π/2. This results in
a signal {0, 1, 0, −1, 0, 1, 0, −1, ...} which is clearly not oscillating as fast as cos(πn). We will have a
deeper understanding of this issue after we discuss the sampling theorem.
Another issue is related to periodic signals. In the continuous case, a cosine signal, denoted by
x(t) = cos(Ωt + φ), is always a periodic signal with a period of 2π/Ω. Is this true in the discrete case
? Let us define a discrete periodic signal as:
x[n] = x[n + N]
where N is an integer and is called the period of the signal. To see if a discrete cosine signal x[n] =
cos(ωn + φ) is periodic, we perform the following operation (replacing n by n = N) :
20
1 1
0.8
0.5
0.6
0
0.4
−0.5
0.2
0 −1
0 5 10 15 20 0 5 10 15 20
1 1
0.5 0.5
0 0
−0.5 −0.5
−1 −1
0 5 10 15 20 0 5 10 15 20
Figure 9: Plots of cos(ωn). Top left ω = 0 . Top right ω = π/8 . Bottom left ω = π/4. Bottom right
ω = π.
ωN = 2kπ
where k is an integer. The smallest integer value of N satisfying this condition is called the fundamental
period of the signal. Therefore, for a cosine signal to be a periodic signal with a period N, its frequency
must be:
2k
ω= π
N
where k = 0, 1, ..., N − 1. So there is a set of N different frequencies (ωk ) that satisfies the condition.
In other words, for a given period N, there are only N different frequencies given by the above equation
such that the cosine signal is periodic. Therefore, cosine signals or a complex exponential signals are
not necessarily periodic with a period of 2π/ω, and depending on the value of the frequency, they may
not be periodic at all.
For example, when N = 4, the frequencies are: ω0 = 0, ω1 = π/2, ω2 = π, ω3 = 3π/2. You can
verify that a cosine signal with one of these frequencies is indeed a periodic signal with a period of 4.
When ω = π/7, the smallest non-zero value of N that satisfies the condition is 14. This corresponds
to k = 1.
On the other hand, when ω = 1, we can easily see that the corresponding cosine signal is not
periodic at all, because there is no such integer value of N that satisfies
Since the index n is dimensionless, the unit of the frequency is radians. However, if n is designated
a unit of samples, then the unit for the frequency is radians/sample. If, just as in the analog case, we
define ω = 2π f , then f is the frequency in cycles/sample. For example, a periodic cosine signal with a
frequency of ω = π/5 corresponds to f = 1/10 cycles/sample. This means that for every 10 samples,
the signal repeats itself. In other words, the fundamental period is N = 1/ f = 10.
Summary
The lowest and highest frequency of a discrete signal is 0 and π. A discrete cosine is not necessarily
a periodic signal. It is periodic with a period of N only when its frequency satisfies ω = 2k N π for
k = 0, 1, ..., N − 1.
21
4.3 Discrete time system
A discrete time system is defined mathematically as a transformation or an operator that maps an input
signal x[n] into an output signal y[n]:
y[n] = H{x[n]}
An ideal delay system produces an output which is a delayed version of the input
y[n] = x[n − N]
The moving average filter and the median filter are other examples of a system.
A system is memoryless if the output y[n] at index n only depends on the input x[n] at the same
index. For example, the moving average filter and the median filter are said to have memory, because
the output depends on the input sample x[n] as well as other input samples. The system given by:
y[n] = ax[n] + b
is memoryless.
A system is causal if for every choice of n0 the output sequence value at index n = n0 depends
only on the input sequence value for n ≤ n0 . This implies that if the sequence value at index n0 is
regarded as the “current” value, then the current output value depends only on the past and current
input sequence values. For example, the following moving average filter is non-causal, because the
current output depends on the “future” input value x[n + 1].
1
y[n] = (x[n − 1] + x[n] + x[n + 1])
3
However, we can change it into causal in this way:
1
y[n] = (x[n − 2] + x[n − 1] + x[n])
3
In this case, the current output y[n] only depends on the past input (x[n − 2], x[n − 1]) and the current
input x[n]5 .
A system is stable in the bounded-input bounded-output (BIBO) sense, if and only if every
bounded input signal produces a bounded output signal. A bounded signal is defined as:
For example, the unit step signal u[n] is bounded. If it is used as an input to a system defined as:
n
0, n<0
y[n] = ∑ u[k] =
k=−∞
n + 1, n≥0
then we can easily see that the output signal is unbounded. Thus the system is unstable.
5 Please note that there may be a confusion due to the notation that we use to represent the signal. The term x[n − 3] has
two meanings: (1) if it appears in an equation like y[n] = x[n − 3], then it means a delayed version of the WHOLE signal,
(2) if it appears in an equation like y[n] = 13 (x[n − 3] + x[n − 1] + x[n]), then it means the value of the signal sample at index
(n − 3).
22
x1[n] y1[n]=H{x1[n]}
Η
x2[n] y2[n]=H{x2[n]}
ax1[n]+bx2[n] ay1[n]+by2[n]
and
y2 [n] = H{x2 [n]}
then for an input which is a linear combination of these two signals:
its output is
y[n] = H{x[n]}
= H{ax1 [n]} + H{bx2 [n]}
= ay1 [n] + by2 [n]
This is shown in Figure 10. In other words, for a linear system, a linear combination of the input
signals results in a linear combination of the respective outputs.
For example, suppose the output signals of a linear system for two input signals x1 [n] and x2 [n] are
y1 [n] = {1, 2, 3} and y2 [n] = {0, 4, 5, 6}, respectively. Then for a new input signal
where yk [n] is the output signal for the the input signal xk [n]. You can verify that the median filter
described in Section 1.0.4 is not a linear system.
23
A time invariant system is one for which a time shift of the input signal causes a corresponding
shift in the output signal. For example, if the output is y[n] for an input x[n], then the output for
a delayed input x1 [n] = x[n − m] (delayed by m samples) is y1 [n] = y[n − m]. As an example, we
consider a system with the input-output relationship: y[n] = nx[n]. Is it time invariant? The response
of the system to a delayed signal x[n − k] is y1 [n] = nx[n − k]. However, a delayed output y[n − k] is
due to (n − k)x[n − k]. Therefore, the system is time variant since y1 [n] 6= y[n − k]. Following the same
procedure, we can determine that the system y[n] = x[−n] is also a time variant system.
A linear time-invariant (LTI) system satisfies both requirements. Let us take a look at another
example. A system is defined by
y[n] = x[n] + x[n − 1]
Is this an LTI system? To test if it is time-invariant, we use a new signal as the input x1 [n] = x[n − m] ,
where m is an constant integer. The output is
y3 [n] = x3 [n] + x3 [n − 1]
= a(x1 [n] + x1 [n − 1]) + b(x2 [n] + x2 [n − 1])
24
Because the system is LTI, the output is given by
We now study a general case for an LTI system. If the input signal is a unit sample sequence δ[n],
the output is called the unit sample response h[n] and is represented in the following general form
h[n] = H{δ[n]}
What is the output for the input xm [n] = am δ[n − m] where m is an integer and am is a scaling factor?
Because the system is LTI, the output denoted ym [n] is given by
Once we know the unit sample response h[n], can we determine the output signal for an arbitrary input
signal? In other words, can the unit sample response uniquely specify a system? For an LTI system
the answer is YES.
To establish the input-output relationship, we use the signal representation
∞
x[n] = ∑ x[m]δ[n − m]
m=−∞
An interpretation for this representation is that an arbitrary signal x[n] is now presented as a linear
combination of many unit sample sequences with different delays. In terms of our previous example,
we can write x[n] = ∑∞ m=−∞ xm [n] where xm [n] = am δ[n − m] and am = x[m]. Here is a potentially
confusing point. In the equation am = x[m], the term x[m] is used to represent the value of the signal
x[n] at a particular location index m. It is a number but is not referred to the whole signal! With this
interpretation and the properties of an LTI system, we can determine the system output
y[n] = H{x[n]}
= H ∑∞m=−∞ x[m]δ[n − m]
= ∑∞
m=−∞ x[m]H {δ[n − m]}
= ∑∞
m=−∞ x[m]h[n − m]
Therefore, once h[n] is known, the output can be calculated by the convolution operation
∞
y[n] = x[n] ∗ h[n] = ∑ x[m]h[n − m]
m=−∞
For example, if you want to calculate a particular output sample at index, say n = 3, then you use
∞
y[3] = ∑ x[m]h[3 − m]
m=−∞
This is a multiplication-and-sum operation, where corresponding samples of the two sequences, x[m]
and h[3 − m], are multiplied then summed together. To understand how to perform convolution, you
need to understand the sequence denoted by h[3 − m]. This sequence can be regarded as being gener-
ated by first folding h[n] about n = 0 (h[−m]), then shifting it to the left by three samples.
25
The following two examples shows you how to perform the convolution operation. In the first
example, we would like to find the input-output relationship of an LTI system given the unit sample
response: h[0] = 1, h[1] = 2, and h[2] = 1. In this case, m can only take one of the three values: m = n,
m = n − 1 and m = n − 2. Therefore the convolution can be performed as
n
y[n] = ∑ x[m]h[n − m] = h[0]x[n] + h[1]x[n − 1] + h[2]x[n − 2]
m=n−2
In the second example, we would like to perform the convolution operation for the two sequences
given by
x[n] = δ[n] + 2δ[n − 1]
and
h[n] = δ[n + 1] − δ[n − 1]
unit sample reponse is: h[−1] = 1, h[0] = 0 and h[1] = −1, the index m can only take three values:
m = n − 1, m = n and m = n + 1. Therefore, the system output is given by
n+1
y[n] = ∑ x[m]h[n − m] = h[1]x[n − 1] + h[0]x[n] + h[−1]x[n + 1] = x[n + 1] − x[n − 1]
m=n−1
Now we caluclate the output for this particular input x[n] = δ[n] + 2δ[n − 1] as follows
Of course, we can calculate the convolution operation to determine the output. The folding and
shifting of h[n] is shown in the following table. In this table, empty cells indicate zero-value for both
sequences.
m -2 -1 0 1 2 3
x[m] 1 2
h[m] 1 0 -1
h[-m] (n = 0 ), y[0] = 2 -1 0 1
h[-1-m] (n = -1 ), y[-1] = 1 -1 0 1
h[1-m] ( n = 1 ), y[1] = -1 -1 0 1
h[2-m] ( n = 2 ), y[2] = -2 -1 0 1
In Matlab, you use the command conv(x,h) to perform the convolution operation.
26
x[n] y[n] h[n] y[n]
h[n] x[n]
y[n]
h1[n]
x[n]
y[n] x[n] y[n]
+ h1[n]+ h2[n]
h2[n]
This means that you can regard h[n] as the signal and x[n] as the unit sample response. For a
cascade system where the output of the first system serves as the input to the second system
This means a parallel connection of two LTI systems is equivalent to another system of which
unit sample response is the sum of the two respective systems.
h[n] = 0, f or n < 0
This condition is easy to understand if we consider a simple system for which h[−1] = 1, h[0] = 1 and
h[1] = 1. The input-output relationship is:
27
So we see that this is a non-causal system because the current output sample depends on the “future”
input sample x[n + 1].
4.5.4 Summary
In summary, the output of an LTI system is determined by the convolution of the input and the unit
sample response. The convolution operation is both commutative and distributive. The stability and
the causality of an LTI system can be determined from its unit sample response.
28
5 Signal and system representation in the frequency domain
5.1 Introduction
We will spend two lectures on the following topics
If you are not familiar with the frequency domain representation of signals and systems, you should
read Chapter 3 of the text book.
A basic idea of the frequency domain representation is that a signal can be represented as a linear
combination of cosine signals (or complex exponentials)
x(t) = A0 + ∑Nk=1 Ak cos(2π fk t + φk )
= X0 + ∑Nk=1 ℜe j2π fk t
Xk e
= X0 + 12 ∑Nk=1 Xk e j2π fk t + Xk∗ e− j2π fk t
where Xk = Ak e jφk is a complex number that represents the amplitude and phase of the kth cosine
signal with frequency fk . Xk∗ represents the complex conjugate of Xk . Now you see where the negative
frequency comes from. Once we know the set of pairs {Xk , fk }, we can generate the signal. With the
frequency domain representation, we have another representation which is easier to handle than its
original form x(t) that could be very complicated.
k=0
the coefficient ck is given by
1 N−1 2π
ck = ∑ x[n]e− j N kn
N n=0
Using the DTFS, a periodic signal is represented by a linear combination of the complex exponential
signals e jωk n , where the frequency is
2π
ωk = k
N
There are N frequency components (complex exponential signals), their frequencies range from
ω0 = 0
to
2π
ωN−1 =(N − 1)
N
The quantity ck represents the “amount” of a particular frequency component that the periodic signal
contains. For example, a periodic signal with N = 3 is given by: x[0] = 1, x[1] = 2 and x[2] = 2. The
DTFS representation is:
5 1 n j 2π n 4π
o
x[n] = − e 3 +ej 3 n
3 3
29
1.5
0.5
0
1 1.5 2 2.5 3 3.5 4
0.5
−0.5
1 1.5 2 2.5 3 3.5 4
1.5
0.5
0
1 1.5 2 2.5 3 3.5 4
Figure 13: The Fourier representation of a periodic signal x[n] = {1, 2} with a period of 2. Only two
periods of the signal and its frequency components are shown in this figure. Top: the DC component.
Middle: the high frequency component. Bottom: the original signal. We can see easily that the
original signal can be represented as a summation of the two frequency components.
5 1 n j 2π 0 4π
o 5 2
x[0] = − e 3 +ej 3 n = − = 1
3 3 3 3
Therefore, the periodic signal can be regarded as being generated by a combination of three complex
exponential signals whose frequencies are 0, 2π/3 and 4π/3, respectively. These complex exponential
signals are usually referred to as the frequency components of the original signal.
Here is another example. Suppose a periodic signal is given by x[n] = {1, 2}. The Fourier series
coefficients are c0 = 32 and c1 = − 12 . The signal is represented by
x[n] = c0 + c1 e− jnπ
which is a combination of two signals: a DC signal represented by c0 and a high frequency signal
(with a frequency π) represented by c1 e− jnπ . In other words, we can decompose the signal into two
frequency components. This is shown in figure 13.
where
1
Z π
x[n] = X(ω)e jωn dω
2π −π
n 2 4
o
6c
1 = 1
3 x[0] + x[1]e− j 3 π + x[2]e− j 3 π = − 13
30
5
0
−15 −10 −5 0 5 10 15
−2pi 2pi
−2
−4
−15 −10 −5 0 5 10 15
Figure 14: The amplitude (top) and phase (bottom) of the spectrum. Note that both are periodic
functions of ω and the amplitude is an even function while the phase is an odd function.
where XR (ω) and XI (ω) are the real and imaginary part of X(ω). X(ω) is called the spectrum of the
signal. It is a periodic function of the frequency variable ω with a fundamental period of 2π
and
XI (ω)
∠X(ω) = arctan
XR (ω)
We can easily see that the amplitude is an even function while the phase is an odd function.
31
ax[n] + by[n] aX(ω) + bY (ω) linearity
Here are two examples that illustrate how to use these properties. In the first example, we consider
a pure delay system given by
y[n] = x[n − 3]
The Fourier transform of the output signal is:
Therefore, a time delay corresponds to a linear phase-shift. In the second example, we consider
performing the convolution operation in the frequency domain. The convolution of two signals given
by: x1 {1, 1} and x2 {1, −1}8 is
X1 (ω) = 1 + e− jω
and
X2 (ω) = 1 − e− jω
Therefore we have
Y (ω) = X1 (ω)X2 (ω) = 1 − e− j2ω
Compared this result with the definition of the Fourier transform, we see that
32
5.5 The frequency domain representation of the LTI system
The frequency domain
The convolution property of the Fourier transform suggests another way to represent the LTI system.
In the frequency domain, where the signal and the unit sample response are represented by their
respective Fourier transform X(ω) and H(ω), the Fourier transform of the output Y (ω) is given by:
Y (ω) = X(ω)H(ω)
Since H(ω) is the Fourier transform of h[n], it is a complex function whose amplitude is an even
function and its phase is an odd function. It is also a periodic function with a fundamental period of
2π. Therefore, we only need to consider the frequency in range of [0, π]. The quantity H(ω) is called
the frequency response of the LTI system. We know that, as in the time domain case, once we know
the frequency response, we can determine the output of the system for any input signal.
To see the implication of the frequency domain representation, let us consider the input-output
relationship of an LTI system, with an complex exponential input signal:
x[n] = Ae jω0 n
y[n] = ∑ x[m]h[n − m]
= ∑ h[m]x[n − m]
= A ∑ h[m]e jω0 (n−m)
= Ae jω0 n ∑ h[m]e− jω0 m
= Ae jω0 n H(ω)|ω=ω0
= Ae jω0 n H(ω0 )
where the notation H(ω)|ω=ω0 represents the frequency response evaluated at a particular frequency.
The above calculation shows that the output signal is modified in two ways: the amplitude and the
phase. However, the frequency remains the same. The amplitude of the output signal is A|H(ω0 )|, and
the phase is (assume A is a real number) ∠H(ω0 ). Therefore, the output signal is:
Here is an example. Suppose the impulse response of an LTI system is h[n] = {1, 1}. The fre-
quency response is H(ω) = 1 + e− jω . The amplitude response is |H(ω)| = 2|cos(ω/2)| and the
phase response is ∠H(ω) = −ω/2. As such, we can write H(ω) = |H(ω)|e j∠H(ω) . Let us first
consider the output for the input signal x[n] = cos(ω0 n). To use our previous results, we can write
x[n] = (e jω0 n + e− jω0 n )/2 = x1 [n] + x2 [n], where x1 [n] = 21 e jω0 n and x2 [n] = 21 e− jω0 n . Therefore the
output of the system is
In this example, we have shown that this simple LTI system modifies the input signal in two ways.
It changes the amplitude of the signal and adds a phase angle to the signal. The amount of changes
33
1
0.8
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3 3.5
0
10
−5
10
0 0.5 1 1.5 2 2.5 3 3.5
Figure 15: Top: the frequency response (amplitude response) of a low pass filter. Bottom: the same
plot in log-scale
is related to the frequency of the signal and frequency response of the system. For example, when
ω0 = π4 , we have
y[n] = 2 cos(π/8) cos(πn/4 − π/8).
Here is a question for you, what is the output signal if the input signal is x[n] = cos(πn)? Answer:
y[n] = 0. You can verify your result by using convolution: y[n] = x[n] ∗ h[n] = cos(πn) + cos(π(n −
1)) = 0. Here is another question for you, what is the output signal is the input signal is given by
x[n] = cos(πn/3) + 0.5 cos(πn/4).
What is a filter ?
The word filter is a key word in digital signal processing. We usually call an LTI system a filter. This
is because
• As a result of the Fourier transform, a discrete time signal can be regarded as a linear combina-
tion of discrete exponential signals (or cosine signals or frequency components) with different
amplitude, frequency and phase.
• An LTI system (a filter) only changes the amplitude and phase of a discrete exponential signal
• By properly designing the frequency response of the LTI system, the amplitude and phase of
each frequency component of the input signal are modified. Thus, the input signal is filtered.
For example, to attenuate the high frequency components of a signal, we would use a low pass filter
which has a unit gain for low frequency components and a smaller gain for high frequency compo-
nents. In other words, the frequency response of the filter should be similar to Figure 15. We note that
the horizontal axis represents the frequency and the vertical axis represents the gain. So this figure
shows the system’s gain versus the frequency. For example, the gain for a input frequency component
whose frequency is ω0 = 0.5π is 0.1. This means that the amplitude of the respective output signal
will be scaled down by a factor of 0.1. In this figure, we only plot the frequency response (or precisely,
the amplitude response) in the frequency range [0, π]. Figure 16 shows a combination of two cosine
signals:
x[n] = cos(0.1πn) + cos(0.5πn)
34
1
−1
0 5 10 15 20 25 30 35 40 45 50
1
−1
0 5 10 15 20 25 30 35 40 45 50
2
−2
0 5 10 15 20 25 30 35 40 45 50
2
−2
0 5 10 15 20 25 30 35 40 45 50
Figure 16: An illustration of a low pass filter. From top to bottom: cos(0.1πn), cos(0.5πn),
cos(0.1πn) + cos(0.5πn) and the filtering result.
and the result of the previous low pass filter. We can see that the amplitude of the high frequency
component becomes about 0.1 after the low pass filter and the amplitude of the low frequency compo-
nent is almost unchanged. Therefore, the filtering result looks almost the same as the low frequency
component In the same way, we can now define a high pass filter, a band pass filter and a band stop
filter.
The frequency response characterizes a filter’s function. For example, the first-difference system
is given by:
y[n] = x[n] − x[n − 1]
To determine its frequency response, we take the Fourier transform on both side of the equation:
Therefore we have
Y (ω)
H(ω) = = 1 − e− jω
X(ω)
and
|H(ω)| = 2|sin(ω/2)|
Figure 17 shows its magnitude response. We can see that this is a high pass filter. The DC component
of a signal will be “nulled” by the filter.
As another example, we consider the frequency response of a moving average filter given by
1 N−1
y[n] = ∑ x[n − k]
N k=0
35
2
1.8
1.6
1.4
1.2
0.8
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3 3.5
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.5 1 1.5 2 2.5 3 3.5
1 N−1
sin(ωN/2) − jω(N−1)/2
H(ω) = ∑ e− jωk = e
N k=0 Nsin(ω/2)
This is shown in Figure 18. Next, we consider the frequency response of an LTI system (a Butterworth
high pass filter) given by
36
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.5 1 1.5 2 2.5 3 3.5
• An LTI system is given by: y[n] = x[n − 1] − 2x[n − 2] + x[n − 3]. Find its unit sample response,
frequency response. Is this a high pass filter? Answer: h[n] = δ[n − 1] − 2δ[n − 2] + δ[n − 3].
H(ω) = e− jω (1 − 2e− jω + e− j2ω ). It is a high pass filter.
• Use the Fourier transform to perform the convolution x[n] ∗ h[n], where x[n] = {1, 2, 1} and
h[n] = {1, −1}. Answer: X(ω) = 1 + 2e− jω + e− j2ω , H(ω) = 1 − e− jω
37
6 Problem class-1
We will summarize what we have done so far and briefly discuss problems in Assignment 1
38
x1(t)
x2(t)
Figure 20: The same discrete signal could be a result of sampling two different analog signals.
where Ωk = 2π fk . When we sample this signal with a sampling period Ts , the resulting discrete signal
is
x[n] = A0 + ∑Nk=1 Ak cos(Ωk nTs + φk )
= A0 + ∑Nk=1 Ak cos(ωk n + φk )
where ωk = Ωk Ts . Here we have an important relationship between the frequency of an analog cosine
signal and that of a discrete cosine signal:
2π f
ω = ΩTs =
fs
39
1
0.5
−0.5
−1
0 5 10 15 20 25
0.5
−0.5
−1
0 5 10 15 20 25 30 35 40 45 50
Figure 21: A 200 Hz cosine signal is sampled at 2000 Hz and 4000 Hz respectively. The corresponding
frequencies are π/5 (top) and π/10 (bottom).
The quantity ω is called the discrete time radian frequency (we will call it discrete frequency or just
frequency later on) and it is dimensionless. For example, an analog cosine signal with a frequency
of 4 kHz will be converted to a discrete signal with the discrete time radian frequency of π/4 when
it is sampled at fs = 32 kHz. If we increase the sampling frequency to fs = 128 kHz, the resulting
discrete time radian frequency will be π/16. We note that a higher sampling frequency results in a
lower discrete time radian frequency and that there are more samples in one period of the signal. A
200 Hz cosine signal is sampled at 2000 Hz and 4000 Hz respectively. The corresponding frequencies
are π/5 and π/10, respectively. These two discrete signals are shown in Figure 21. If the discrete
cosine signal is a periodic signal, then its fundamental period is
2π
N=
ω
For example, the fundamental periods of these two signal are 10 and 20.
From the above discussion, it is evident that we only have to investigate the condition that a
sampled cosine signal uniquely represent the original analog cosine signal. Next we take a look at the
relationship among the three quantities: the discrete frequency ω0 , the frequency of the signal f0 , and
the sampling frequency fs
• ω0 ≤ π
• π < ω0 ≤ 2π
• 2π < ω0 ≤ 3π
40
In the first case, we have f0 ≤ f2s and ω0 is a linear function of f0 . This is a one to one mapping from
f0 to ω0 . In other words, there is no other analog cosine signal (with a different frequency in the range
of [0, fs /2] ) that would lead to this discrete signal. Therefore, the discrete cosine signal uniquely
represents the original signal.
In the second case, we have f2s < f0 ≤ fs . Let us define a new signal with a frequency f1 such that
f0 = fs − f1
and
fs
f1 ≤
2
We can easily see that
2π f0 2π( fs − f1 ) 2π f1
ω0 = = = 2π − = 2π − ω1
fs fs fs
In this case, the cosine signal cos(ω0 n) is indistinguishable from the other cosine signal cos(ω1 n).
Why? Because cos[(2π − ω0 )n] = cos(2nπ − ω0 n) = cos(ω0 n). Therefore, we do not know if the
discrete cosine signal is due to a signal, given by
x0 [n] = cos(ω0 n − φ)
and
x1 [n] = cos(ω1 n + φ)
You can easily see that x0 [n] = x1 [n]. This is called folding, where the two frequencies f0 and f1 are
mirror images with respect to fs /2. Actually, ω0 is linearly decreased from π to 0 when f0 is increased
from fs /2 to fs .
In the third case, fs < f0 ≤ 32 fs . As in the second case, let us define a new signal with a frequency
f2 such that
f0 = fs + f2
and
fs
f2 ≤
2
Then, we have
2π f0 2π( fs + f2 ) 2π f2
ω0 = = = 2π + = 2π + ω2
fs fs fs
Again, we see that the signal cos(ω0 n) is indistinguishable from another signal cos(ω2 n). Therefore,
in this third case we do not know if the discrete cosine signal is due to a signal, denoted by
41
ω
folding
aliasing
f
f0 fs/2 f1 fs f2 3fs/2
Figure 22: The aliasing and folding as a result of sampling the cosine signal. Three cosine signals
with frequencies of f0 , f1 and f2 lead to the same discrete-time cosine signal with a frequency of π/2.
f1 is called the folded frequency, because f1 = fs − f0 . f2 is called the aliased frequency, because
f2 = fs + f0 .
x0 [n] = cos(ω0 n + φ)
and
x2 [n] = cos(ω2 n + φ)
You can easily see that x0 [n] = x2 [n]. The frequency f0 is called the aliased frequency of f2 . ω0 is
linearly increased from 0 to π when f0 is increased from fs to 32 fs .
Figure 22 illustrates aliasing and folding as a result of sampling the cosine signal. In this figure,
we can see that there are other aliasing and folding frequencies located at:
fkaliasing = k fs + f0
and
f olding
fk = k fs − f0
where k is an integer.
Let us take a look at one example. Suppose a signal is given by the formula
and that it was obtained by sampling a continuous-time signal at a sampling rate of fs = 1000 sam-
ples/sec. We will determine two different continuous-time signals x1 (t) and x2 (t) such that x[n] =
x1 [nT ] = x2 [nT ]. Both signals should have a frequency less than 1000 Hz.
From the above discussions, we know that the frequency of x1 (t) should be in the non-aliasing
region and the frequency of x2 (t) should be is in the folding region. The frequency for the first signal
is given by
2π f1
= ω = 0.2π
fs
We have f1 = 100 Hz. The frequency for the second signal is the folded frequency of f1
f2 = fs − f1 = 900Hz
42
and
x2 (t) = cos(2π f2t + π/7)
To verify these results, we sample these two signals with a sampling frequency of 1000 Hz. We obtain
x1 [nT ] = cos(2π f1 nT − π/7) = cos(0.2πn − π/7)
and
The results are shown in fig. 23. Following this example, let us consider this problem: what would
happen if sample the following analog signal with the sampling frequency fs = 1000Hz?
x[n] = 3 cos(ω1 n)
Where have the two other frequency components gone? Because they are the folding ( f2 ) and aliasing
( f3 ) frequency of f1 , in the discrete domain they are identical.
To summarize we have demonstrated the following key points for a fixed sampling frequency fs
and a cosine signal x(t) = cos(2π f t).
fs 2π f
• When f ≤ 2, the resulting discrete signal x[n] = cos(ωn) (ω = fs ) is a unique representation
of x(t).
• When f2s < f ≤ fs , we can write f = fs − f0 (for f0 ≤ f2s ) the resulting discrete signal x[n] =
cos(ωn) = cos(ω0 n) (ω0 = 2πfsf0 ). f0 is the folding frequency. In other words, when the fre-
quency f is in this range, the resulting discrete signal will be the same as that due to sampling
the signal x0 (t) = cos(2π f0t).
43
A cosine signal with f0=200Hz and sampled at 1000Hz
1
0.5
−0.5
−1
0 5 10 15 20 25 30 35 40 45 50
0.5
−0.5
−1
0 5 10 15 20 25 30 35 40 45 50
0.5
−0.5
−1
0 5 10 15 20 25 30 35 40 45 50
Figure 23: The three figures are results of sampling three cosine signals with frequencies 200Hz, 800
Hz and 1200Hz, respectly. The sampleing frequency is 1000Hz. We can see that the resulting discrere
signals are exact the same.
44
• When fs < f ≤ 32 fs , we can write f = fs + f0 (for f0 ≤ f2s ) the resulting discrete signal x[n] =
cos(ωn) = cos(ω0 n) (ω0 = 2πfsf0 ). f0 is the aliasing frequency. In other words, when the fre-
quency f is in this range, the resulting discrete signal will be the same as that due to sampling
the signal x0 (t) = cos(2π f0t).
with f1 = 200Hz, f2 = 700Hz and f3 = 1400Hz. Suppose we sample this signal with a sampling
frequency fs = 1000Hz. According to the above three points, we have three frequency components.
The fisrt is with ω1 = 2π f1 / fs = 2π/5. The second is with the folding frequency for f2 is 300 Hz
(700=1000-300) and ω2 = 2π × 300/1000 = 3π/5 and the third is with the aliasing frequency for f3
is 400Hz (1400=1000+400) and ω3 = 2π × 400/1000 = 4π/5. So the discrete time signal we have is
If we are given this signal and the sampling frequency fs , then we may say that the corresponding
analog signal has three frequency components with f1 = ω1 fs /(2π) = 200Hz, f2 = ω2 fs /(2π) =
300Hz and f3 = ω3 fs /(2π) = 400Hz. Note that f2 is the folding and f3 is the aliasing frequency.
45
f0
0 f
0 ω=2π f/fs
π 2π 3π
Figure 24: The mapping from f to ω. When fs ≥ 2 f0 , there is no aliasing. The frequency range [0, f0 ]
is mapped to [0, π].
X( Ω) X s( Ω)
low pass filter fs>2fmax
Ω Ω
Ωmax Ωmax Ωs 2Ω s
X s( ω) X s( ω)
fs=2fmax fs=fmax
Ω Ω
Figure 25: The frequency domain representation of the sampling operation. Note that these figures
show the spectrum in the continuous case, where Ωs = 2π fs . Top left: spectrum of the analog signal
with the highest frequency denoted fmax . Top right: sample signal spectrum, fs > 2 fmax . Bottom left:
f s = 2 fmax . Bottom right: fs = fmax
46
Ωs = 2Ωmax , the cut-off frequency is Ωc = Ωs /2. This corresponds to 2π fs /2 = π/Ts . In other cases
where Ωs > 2Ωmax , the cut-off frequency can be selected from the frequency range
sin(πt/Ts )
h(t) =
πt/Ts
x[n] = x(t)|t=nTs
A general formula for converting a discrete signal into an analog signal is given by:
∞
x(t) = ∑ x[n]p(t − nTs )
n=−∞
where the function p is the interpolation function which fills the gaps between samples. In the previous
case, the interpolation function is a sinc-function. Other interpolation functions, such as a square pulse,
a triangular pulse and a linear function can be used. These functions do not usually lead to a perfect
reconstruction to the original signal. Here are two examples using the square pulse and the linear
interpolation function to reconstruct the cosine signal.
• If the sampling frequency is 8000 Hz, assuming no aliasing and folding, what is the cut-off
frequency for the ideal low pass filter to reconstruct the original signal ? Answer 2π × 4000 Hz
47
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
−10 −8 −6 −4 −2 0 2 4
8 z-Transform
This section covers a little bit more than Chapter 7 of the text book. In particular, we will discuss the
region of convergence and the inverse z-transform.
The z-transform of the unit sample sequence x[n] = δ[n] and y[n] = δ[n − n0 ] are
∞
X(z) = ∑ δ[n]z−n = δ[0]z−0 = 1
n=−∞
and ∞
Y (z) = ∑ y[n]z−n = δ[n0 ]z−n0 = z−n0
n=−∞
These examples are used to show how to perform the z-transform for simple signals. However, more
careful calculations are required for other signals. For example, the z-transform of the signal shown
in Figure 26 x[n] = −an u[−n − 1] (where u[n] is the unit step signal) is
X(z) = ∑∞ −n
n=−∞ x[n]z
= − ∑−1 n −n
n=−∞ a z
= 1 − ∑n=0 (a−1 z)n
∞
48
If |a−1 z| < 1 or equivalently, |z| < |a|, then
1 1
X(z) = 1 − =
1 − a z 1 − az−1
−1
You see that a signal of infinite duration is now represented by a formula in the z-transform domain.
Here is another example, the z-transform of a signal given by: x[n] = an u[n] is
X(z) = ∑∞ −n
n=−∞ x[n]z
= ∑∞ n −n
n=0 a z
= ∑n=0 (az−1 )n
∞
An important point to note is that for an LTI system, the convolution in the time domain is equiv-
alent to the multiplication in the z-domain. This is similar to the Fourier transform. The Fourier is
indeed closely related to the z-transform. For example, we can perform the convolution of two sig-
nals, denoted by x1 [n] = {1 2 2 1} and x2 [n] = {1 − 2 1} by using the z-transform. Performing the
z-transform on both signals we have
X1 (z) = 1 + 2z−1 + 2z−2 + z−3
and
49
Assume h0 [n] = {h0 h1 h2 h3 } = {1 2 2 1}(N = 3), determine the impulse response of the filter given by
H1 (z). To solve this problem, we determine H0 (−z−1 ) first. Since
then
H0 (−z−1 ) = 1 − 2z + 2z2 − z3
Therefore, we have
The impulse response is h1 [n] = {1 − 2 2 − 1}. Actually, H0 (−z−1 ) corresponds to two operations:
time reversal indicated by z−1 and changing the sign of the odd indexed coefficients indicated by the
negative sign. Then z−N is a delay operation to make it a causal filter.
When r = 1, the above equation defines the Fourier transform. In other words, when we evaluate the
z-transform on the unit circle, we obtain the Fourier transform:
X(ω) = X(z)|z=e jω
This is because the unit circle is defined as |z| = 1 (refer to Section 2 on complex numbers).
The interpretation of variable ω is that it is the angle between a vector that points to a point on the
unit circle and the real axis of the complex z-plane. You can refer to Figure 7. With this interpretation,
we can see that ω = 0 corresponds to z = 1 and ω = π corresponds to z = −1. Therefore, interpreting
the Fourier transform as the z-transform evaluation on the unit circle corresponds conceptually to
wrapping the linear frequency axis around the unit circle. The inherent periodicity property of the
frequency ω is captured naturally since a change of an angle by 2π in the z-plane corresponds to
traversing the unit circle once and returning to exactly the same location.
There is an interesting demonstration in the CDROM (in section 8, a demo called Z to Freq).
Here we have taken the interpretation that z−1 x[n] = x[n − 1]. In other words, we regard z−k as a delay
operator that causes a signal to delay by k samples. Figure 27 shows two equivalent block diagrams
that show the implementation of a system.
50
x[n] + y[n]=x[n]+x[n−1]+x[n−2] x[n]
y[n]=x[n]+x[n−1]+x[n−2]
z−1
x[n−1]
z −1 +
x[n−1] z −1
x[n−2]
z −1 +
x[n−2]
Figure 27: Two equivalent block diagrams that show the implementation of y[n] = x[n] + x[n − 1] +
x[n − 2]
1
x[n] = −an u[−n − 1] X(z) = 1−az−1
|z| < |a|
We can see that the two different signals have the same z-transform with different ROCs. There-
fore, the z-transform together with the ROC uniquely specifies a signal. Figure 28 shows the ROCs.
Let us consider the ROC of a z-transform: X(z) = 1 + 2z−1 + 2z−2 + z−3 . Its ROC is the whole
z-plane, excluding the origin where z = 0. As another example, we want to determine the z-transform
of a signal
1 1
x[n] = ( )n u[n] + (− )n u[n]
2 3
According to the above table and using the linearity property, we obtain
1 1 1 1
X(z) = 1 −1
+ 1 −1
= 1 −1
+
1− 2z 1+ 3z 1− 2z 1 − (− 13 )z−1
where the ROC for the first term is |z| > 1/2 and the ROC for the second term is |z| > | − 1/3| = 1/3.
The ROC that satisfies both conditions is |z| > 1/2.
In general, the problem of finding the ROC is equivalent to determining the values of r, such that
∞ ∞ ∞
|X(z)| ≤ ∑ |x[n]z−n | = ∑ |x[n]r−n e− jωn | = ∑ |x[n]r−n | < ∞
n=−∞ n=−∞ n=−∞
51
unit circle unit circle
1111111
0000000
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
|z|<|a|
|z|>|a|
where
x[−n], n > 0
x1 [n] =
0, n ≤ 0
and
x[n], n ≥ 0
x2 [n] =
0, n > 0
With these notations, we have10
−n −1 −n −n
∑∞ ∞
n=−∞ |x[n]r | = ∑n=−∞ |x[n]r | + ∑n=0 |x[n]r |
∞ n ∞ −n
= ∑n=1 |x1 [n]r | + ∑n=0 |x2 [n]r |
We can easily see that the ROC for the signal x1 [n] is |z| < r1 , while that for x2 [n] is |z| > r2 , where r1
and r2 are two positive constants that depend on the signal. If r1 > r2 , then the ROC is r1 < |z| < r2 .
This is a ring shape region in the z-plane. Otherwise, if r1 < r2 , the z-transform does not exist for the
signal.
In summary, the ROC provides useful information about the signal.
• If the signal is of finite duration, then its ROC is the whole z-plane except z = 0 or z = ∞
• If the signal is a left-sided sequence, i.e., a sequence that is zero for n < N < ∞ (N is a positive
integer), then its ROC is within the region of a circle, except z = 0.
• If the signal is a right-sided sequence, i.e., a sequence that is zero for n > N > −∞ (N is a
positive integer), then its ROC is outside a circle.
• If the signal is a two-sided sequence, then its ROC is within a ring-shaped region.
10 Note, if we let m = −n, then ∑−1 −n ∞ m ∞ n
n=−∞ |x[n]r | = ∑m=1 |x[−m]r | = ∑n=1 |x1 [n]r |
52
8.5 The Inverse z-transform
Performing the inverse z-transform is relatively simple in some cases, but it may be quite a complicated
task in other cases. In this subject, we only discuss how to use the z-transform table and a number of
its properties to perform the inverse transform.
Here are a few examples that show you how to determine the inverse transform
For example, a causal and stable filter is described by the difference equation
where p1 = e jπ/3 . The impulse response is obtained by taking the inverse z-transform
• Use the ZT to calculate the convolution: x[n]∗h[n], where x[n] = {1, 0, 2, 3} and h[n] = {1, −1, −1, 1}
53
• A system is a cascade of two causal LTI systems: h1 [n] = {1, 2, 1} and h2 [n] = {1, −2, 1}.
Determine the system function, the frequency response and the unit sample response of the
system.
0.5z−2
H(z) = , |z| > 0.2
1 − 0.2z−1
1 + 0.5z−2
H(z) = , |z| > 0.2
1 − 0.2z−1
Answers
• Y [z] = X[z]H[z] = (1 + 2z−2 + 3z−3 )(1 − z−1 + z−2 − z−3 ). Perform the inverse z-transform to
determine y[n]
• Assume x1 [n] = {1, 2} and x2 [n] = {1, 0, 2}, we make a new signal x[n] = ax1 [n] + bx2 [n], you
can show that X(z) = aX1 (z) + bX2 (z)
• The system function is the z-transform of the unit sample response. In this case, the overall
response is h[n] = h1 [n] ∗ h2 [n]. So H(z) = H1 (z)H2 (z). H(ω) = H(z)|z=e jω
54
9 Implementation of FIR and IIR filters
9.1 Finite impulse response (FIR) filter
An FIR filter is usually represented by a linear constant coefficient difference equation
M
y[n] = ∑ bm x[n − m]
m=0
where the parameter M is called the order of the filter. For example, a half-band low pass filter is given
by
10
y[n] = ∑ bm x[n − m]
m=0
b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
0.005 0 -0.042 0 0.289 0.497 0.289 0 -0.042 0 0.005
The impulse response (unit sample response) of the filter is obtained by using the signal δ[n] as
the input:
h[n] = 0.005δ[n]−0.042δ[n−2]+0.289δ[n−4]+0.497δ[n−5]+0.289δ[n−6]−0.042δ[n−8]+0.005δ[n−10]
and
M
H(ω) = ∑ h[m]e− jmω
m=0
The time domain and frequency domain representations of the above half-band filter are shown in
Figure 29. The following Matlab codes are used to produce these results
b = fir1 (10, 0.5); %design an fir filter
subplot ( 211 ); stem ( 0:10, b ); grid
subplot ( 212 ); plot ( 0 : pi/128 : pi*127/128, abs (freqz ( b, 1, 128 )));
55
0.5
0 1 2 3 4 5 6 7 8 9 10
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3 3.5
Figure 29: Top: a plot of h[n]. Bottom: the amplitude response of the half-band filter
4
3.5
2.5
1.5
0.5
0
0 0.5 1 1.5 2 2.5 3 3.5
Here is one more example. The unit sample response of the filter is: h[n] = {1, 0, 2, 0, 1}. The
difference equation is
y[n] = x[n] + 2x[n − 2] + x[n − 4]
Its frequency response and system function are
and
H(z) = 1 + 2z−2 + z−4
The amplitude response is
|H(ω)| = 4 cos2 (ω)e− j2ω = 4 cos2 ω
This is shown in Figure 30. Note that this filter is neither a low pass nor a high pass filter. It passes the
low frequency and high frequency components and attenuates those components whose frequencies
are close to π/2. What is the output for an input signal x[n] = cos(0.5n) + cos( π2 n) ?
56
9.2 Infinite impulse response (IIR) filter11
An IIR filter is usually represented by a linear constant coefficient difference equation
N M
y[n] = ∑ ak y[n − k] + ∑ bm x[n − m]
k=1 m=0
This equation represents an LTI system, only when the initial rest condition is satisfied. The impulse
response is obtained when we use the unit sample sequence as the input. For example, we consider
the simplest IIR filter given by:
y[n] = a1 y[n − 1] + b0 x[n]
Its impulse response is
h[n] = a1 h[n − 1] + b0 δ[n]
The following table shows how to recursively calculate the impulse response.
n n<0 0 1 2 3 4
δ[n] 0 1 0 0 0 0
h[n − 1] 0 0 b0 b0 a1 b0 a21 b0 a31
h[n] 0 b0 b0 a1 b0 a21 b0 a31 b0 a41
From this table, we can see that for an input signal such as δ[n] with only one non-zero data
sample, the output of the filter is an infinite-length sequence:
b0 an1 ,
n≥0
h[n] =
0, n<0
Therefore, convolution is not a practical way to calculate the output of an IIR filter. In most cases, we
use the difference equation. Let us take a look at another example. The IIR filter is given by
1 1
y[n] = y[n − 1] + x[n]
2 2
and the input is x[n] = δ[n] + δ[n − 1]. We can use our previous results by using a1 = 1/2 and b0 = 1/2.
The output is given by
y[n] = h[n] + h[n − 1]
= 12 ( 12 )n + 21 ( 12 )n−1
= 1.5 × 0.5n−1
You can also use the difference equation to obtain the same result. Note that in both examples, we
have assumed the initial rest condition.
In the frequency domain, an IIR filter is characterized by its system function, defined as
−m
Y (z) ∑M
m=0 bm z
H(z) = =
X(z) 1 − ∑Nk=1 ak z−k
Note that in deriving the above equation, we have used an equivalent representation
N M
y[n] = ∑ ak y[n − k] + ∑ bm x[n − m]
k=1 m=0
11 An IIR filter can be motivated from a feedback system point of view. It can be motivated from a computational point of
view. Its different from FIR filters in a number of aspects. I will leave these to the next major revision.
57
For example, the system function of an IIR filter
can be calculated by taking the z-transform of the both side of the equation as
b = [0 4 5] ;
a = [1 − 2 − 3] ;
9.3 Implementations
There are three basic operations involved in implementing an LTI system: addition, multiplication and
unit delay. A block diagram and a signal flow graph for an FIR filter
58
12
10
0
0 0.5 1 1.5 2 2.5 3 3.5
2
10
1
10
0
10
0 0.5 1 1.5 2 2.5 3 3.5
0.7
x[n] + y[n]
0.3
z −1
x[n−1]
z−1
0.3
Figure 32: The block diagram (top) and the signal flow graph (bottom) for an FIR filter
59
x[n] y[n]
+ x[n] y[n]
b0
z−1 b0
z −1
a1 a1
+ y[n−1]
−1
z
z−1
a2 a2
y[n−2]
Figure 33: The block diagram (left) and the signal flow graph (right) for an IIR filter
x[n] b0 y[n]
z −1 z −1
b1 a1
−1 −1
z z
b2
a2
Figure 34: Direct form-I implementation scheme for a second order IIR filter
The block diagram and the signal flow graph are show in Figure 33. A general second order IIR filter
is represented by the the difference equation
Let
1
W (z) = X(z)
A(z)
1
The system can be regarded as a cascaded of two sub-systems: one with a system function of A(z) and
the other with B(z). In the time domain, this system corresponds to two difference equations
60
w[n] y[n]
x[n] b0
z −1 z −1
a1 b1
−1 −1
z z
b2
a2
z−1
a1 b1
z−1
b2
a2
Figure 35: The direct form-II implementation scheme. Top: the two-step implementation. Bottom:
the delay units merged together.
and
y[n] = b0 w[n] + b1 w[n − 1] + b2 w[n − 2]
These two equations suggest another implementation of an IIR filter, which is called the direct form-
II implementation. Compared to direct form-I, it requires smaller number of delay units. Figure 35
shows the above implementation scheme.
1
H(z) =
1 − a1 z−1
b0 + b1 z−1
H(z) =
1 − az−1
61
b0 + b1 z−1 + b2 z−2
H(z) =
1 − a1 z−1 − a2 z−2
Using this factorization, the IIR system can be implemented by a cascade of the basic structures. We
can also express the system function in the following way:
M1 N1
e0k + e1k z−1
H(z) = ∑ ck z−k + ∑ 1 − a1k z−1 − a2k z−2
k=0 k=1
Using this factorization, the IIR system can be implemented with the basic structures discussed in
section 9.4.1 in a parallel form.
• Draw both direct form-I and II implementations for the following IIR filters
62
1
unit circle
0.8
0.6
0.4
0.2
Imaginary Part
2 2
0
−0.2
−0.4
−0.6
−0.8
−1
−1 −0.5 0 0.5 1
Real Part
Figure 36: pole-zero plot of H(z) = 1 − 2z−1 + z−2 . This figure is produced by using a Matlab com-
mand, zplane ( [1 -2 1] , [1 0 0] ).
63
1
0.8
0.6
0.4
0.2
Imaginary Part
3
0
−0.2
−0.4
−0.6
−0.8
−1
−1 −0.5 0 0.5 1
Real Part
where A is a constant and zn is the nth zero of the system function. Therefore, if all zeros of a system
function are known, then the system function can be determined to within a scaling constant. For
example, a system is given by the pole-zero plot shown in Figure 37. It has three zeros at z0 = 1,
z1 = e jπ/3 and z2 = e− jπ/3 . Its system function can be expressed as (assuming the scaling constant
A = 1)
z3 −2z2 +2z−1
= z3
H(ωk ) = H(zk ) = 0
64
For example, when the input signal is given by
x[n] = e jnπ/3
Therefore, y[n] = 0. So we see that a zero, denoted by zk = e jωk , can remove a complex exponential
signal
x[n] = Ae jnωk
Because a cosine signal can be expressed as
1
cos(ωk n) = (e jωk n + e− jωk n )
2
to remove this cosine signal, we can use a cascade of two filters, one with a zero zk and and the other
with a zero z∗k (the conjugate of zk ). Therefore, the system function is given by
z−z∗
H(z) = z−z
z
k
z
k
You can verify that when the input is x[n] = A cos(ωk n), the output of this system is zero.
65
1
unit circle
0.8
0.6
0.4
0.2
Imaginary Part
2pi/9
8
0
−0.2
−0.4
−0.6
−0.8
−1
−1 −0.5 0 0.5 1
Real Part
1.2
0.8
0.6
0.4
0.2
0
−4 −3 −2 −1 0 1 2 3 4
−2pi/9 2pi/9
66
A special class of FIR filter, denoted by
M
y[n] = ∑ bk x[n − k]
k=0
bk = bM−k
for k = 0, 1, ..., M. It can be proved that the frequency response of this filter is given by
So the frequency response is a real valued amplitude function times a linear phase factor e− jωM/2
which corresponds to a delay of M/2 samples. For a discussion of how to interpret a delay of non-
integer value, you can refer to page 192-194 of the text book.
If the signal is of finite length and real time processing is not required, then it is possible to have a
filtering process with zero-phase. The process involves the following steps
In the above steps, we have introduced three internal variables y[n], u[n] and w[n] and used both time
domain and z-transform domain representations. The final output is d[n]. We can see that it is a
filtering output with zero-phase by converting the z-transform representation to the Fourier transform
representation
D(ω) = H ∗ (ω)H(ω)X(ω) = |H(ω)|2 X(ω)
In Matlab, you can use the function called filtfilt to perform the above operations.
67
1
0.8
0.6
0.4
0.2
Imaginary Part
0
−0.2
−0.4
−0.6
−0.8
−1
−1 −0.5 0 0.5 1
Real Part
450
400
350
300
250
200
150
100
50
0
−4 −3 −2 −1 0 1 2 3 4
Zeros and poles satisfy the condition A(z) = 0 and B(z) = 0, respectively. For example, the system
function
2
H(z) =
1 − 0.5z−1
has a zero z = 0 and a pole p = 0.5. The system function
2 + 2z−1
H(z) =
1 − z−1 + z−2
has two zeros z0 = 0 and z1 = −1 and two poles p0 = e−iπ/3 and p1 = e jπ/3 . As in the FIR filter case,
we can plot the pole-zero plot using the zplane command in Matlab. Figure 39 shows the pole-zero
plot for the last system function.
We can also look for connections between zeros and poles and the shape of the frequency response.
We use the fact that a pole pushes the frequency response up and a zero pulls it down. For the pole-
zero plot shown in Figure 39, we know that the filter is a band pass filter with a center frequency at
π/3, this is because the zero (z1 ) pull it down at frequency π. The magnitude response of this filter is
shown in Figure 40.
Here is an example of how to calculate the amplitude response from the locations of zeros and
68
poles. We can write
2 + 2z−1
H(z) =
1 − z−1 + z−2
z+1
= 2 2
z −z+1
(z − z0 )(z − z1 )
= 2
(z − p0 )(z − p1 )
(e jω − z0 )(e jω − z1 )
H(ω) = 2
(e jω − p0 )(e jω − p1 )
and
|(e jω − z0 )||(e jω − z1 )|
|H(ω)| = 2
|(e jω − p0 )||(e jω − p1 )|
What does the term |(e jω − z0 )| mean? It is the length of the vector that points from the point e jω to
the point z0 . Figure 41 illustrates this interpretation.
p0=ejpi/3
x
e−jw w l3
l1
l2
z0=0
q o
z1=−pi
l4
x
p1=e−jpi/3
Figure 41: Using the locations of zeros and poles to calculate the amplitude
response.
With this interpretation, we can simplify our notation and use l1 (ω) = |(e jω − z0 )|, l2 (ω) = |(e jω −
z1 )|, l3 (ω) = |(e jω − p0 )|,l4 (ω) = |(e jω − p1 )|. As such, we have
l1 (ω)l2 (ω)
|H(ω)| = 2
l3 (ω)l4 (ω)
69
1
0.5
Imaginary Part
0
−0.5
−1
3.5
2.5
1.5
0.5
0
−4 −3 −2 −1 0 1 2 3 4
Figure 42: The pole-zero plot and the frequency response of an IIR filter
When we calculate |H(ω)| by going through the unit circle once (this is the same as 0 ≤ ω < 2π
or −π ≤ ω < π), we have the amplitude response. Now let us calculate the amplitude response for
the frequency of π and π/3. You can easily see that since l2 (π) = 0, |H(π)| = 0. Since l3 (π/3) = 0,
|H(π/3)| → ∞.
As another example, we take a look at a filter given by
1 1
y[n] = y[n] − y[n − 1] − x[n] + 3x[n − 1] − 2x[n − 2]
2 3
Its system function is
−1 + 3z−1 − 2z−2
H(z) =
1 − 21 z−1 + 31 z−2
The pole-zero plot and the magnitude response is shown in Figure 42. From this figure, you can see
the connection between the pole-zero plot and the magnitude response.
70
1 1
0.8 0.8
0.6 0.6
0.4 0.4
0.2 0.2
Imaginary Part
Imaginary Part
0 0
−0.2 −0.2
−0.4 −0.4
−0.6 −0.6
−0.8 −0.8
−1 −1
0.5 40
35
0.4
30
25
0.3
20
0.2
15
10
0.1
0 0
0 2 4 6 8 10 12 14 16 18 20 0 2 4 6 8 10 12 14 16 18 20
Figure 43: Pole-zero plot and impulse response. Left panel a1 = 0.5, right panel a1 = 1.2.
∑ |h[n]| < ∞
This condition is satisfied only when |a1 | < 1. In other words, when the pole is inside the unit circle,
the filter is stable. Figure 43 shows two cases where a1 = 0.5 and a1 = 1.2. In both cases, we set
b0 = 1. We can see that when the pole is inside the unit circle (left panel), the values of the samples of
impulse response are decreasing. When the pole is outside the unit circle, the values of the samples of
the impulse response are increasing. Further more, a causal and stable IIR filter requires that the ROC
be outside the outermost poles and have all poles inside the unit circle.
71
1
pole−zero plot
Imaginary Part
0.5 H(z) = 1 / ( 1 + 0.5z−1)
−0.5
−1
−5 −4 −3 −2 −1 0 1 2 3 4 5
Real Part
2
1.5
1
amplitude response
0.5
0 20 40 60 80 100 120 140
impulse response
0.5
0
0 2 4 6 8 10 12 14 16 18 20
• Double poles
In the first two cases, we will examine the effects of the locations of poles (inside, on and outside the
unit circle). In this demonstration, we can also see that as in the case of an FIR filter, the locations of
poles and zeros are also related to the shape of the frequency response. We use a single pole with a
zero as an example and plot its pole-zero plot, amplitude response and impulse response. These are
shown in figures 44 to47. You can make a number of observations from these figures and see how the
three domains of representations of an LTI system are related.
We have already shown that when all poles are inside the unit circle, the filter is stable. What
happens when they are on the unit circle? In section 8.5, we studied the IIR filter given by
72
1
pole−zero plot
Imaginary Part
−0.5
−1
−5 −4 −3 −2 −1 0 1 2 3 4 5
Real Part
2
1.5
1
amplitude response
0.5
0 20 40 60 80 100 120 140
impulse response
0.5
−0.5
0 2 4 6 8 10 12 14 16 18 20
73
1
pole−zero plot
Imaginary Part
−
0.5 H(z) = 1 / (1 + z 1)
−0.5
−1
−5 −4 −3 −2 −1 0 1 2 3 4 5
Real Part
60
40 amplitude response
20
0
0 20 40 60 80 100 120 140
0.5
−0.5
−1
0 2 4 6 8 10 12 14 16 18 20
impulse response
Figure 46: The pole is on the unit circle. The impulse response is a cosine signal with a frequency of
π. Can you change the frequency to other values, say π/5? You need a two-pole filter, why?
74
1
pole−zero plot
Imaginary Part
0.5 H(z) = 1 / (1 + 1.5z−1)
−0.5
−1
−5 −4 −3 −2 −1 0 1 2 3 4
Real Part
2
1.5
amplitude response
1
0.5
0
0 20 40 60 80 100 120 140
2000
−4000
0 2 4 6 8 10 12 14 16 18 20
Figure 47: This is an unstable filter. The pole is outside the unit circle. The absolute values of the
impulse response increases with the index n.
0.8
0.6
0.4
0.2
Imaginary Part
pi/3
0
−0.2
−0.4
−0.6
−0.8
−1
−1 −0.5 0 0.5 1
Real Part
Figure 48: The pole-zero plot for an IIR filter. There are two poles (located at ±π/3) on the unit circle.
The impulse response of this filter is a discrete cosine signal with a frequency of π/3.
75
1
0.8
0.6
0.4
0.2
Imaginary Part
2
0
−0.2
−0.4
−0.6
−0.8
−1
−1 −0.5 0 0.5 1
Real Part
Figure 49: The pole-zero plot of an IIR filter There are two poles (located at ±π/2) on the unit circle.
The impulse response of this filter is a discrete cosine signal with a frequency of π/2.
circle. The impulse response of this filter is a discrete cosine signal with a frequency of π/3. As
another example, the impulse response of an IIR filter given by
is
π
h[n] = cos( n)u[n]
2
The pole-zero plot of its system function is shown in Figure 49.
where x[n], h[n], r[n] and y[n] represent the original signal, the impulse response of the channel, the
additive noise and the received signal, respectively. If the noise power is relatively low and can be
omitted, then we would like to recover the original signal from y[n]. More specifically, we want to
design a filter to process the received signal such that the output is as close to the original as possible.
Such a filter, denoted by h1 [n], is a deconvolution filter
In an ideal case, we require v[n] = x[n − nd ] where nd represents a pure delay by nd samples. If noise
is not considered and the delay is assumed zero, then it requires that
76
The system function of the inverse filter is given by
1 1
H1 (z) = 5 −1
= 1 −1 1 −1
1− 6z + 61 z−2 (1 − 2 z )(1 − 3 z )
This system function has two poles (both inside the unit circle) so that the inverse filter is stable and
is given by
5 1
v[n] = y[n] + v[n − 1] − v[n − 2]
6 6
To obtain its impulse response, the ROC must be |z| > 0.5. The system function can be expanded to
3 2
H1 (z) = 1 −1
−
1− 2z 1 − 13 z−1
Determine the frequency of a cosine signal that will be “nulled” by this filter. Answer: x[n] =
cos(nπ/3)
• Use the method described in Section 8.5 to determine the impulse response of the filter
77
11 Problem class-2 A review of signal and system representation meth-
ods
11.1 Signal representation
• In the time domain:
x(n) = x(n) ∗ δ(n) = ∑ x(m)δ(n − m)
• H(z) is called the system function. The z transform together with its ROC uniquely specifies a
filter. when performing the inverse z transform, the ROC must be considered.
• The relationship between the Fourier transform and the z-transform is:
H(ω) = H(z)|z=e jω
• Poles and zeros are related to the frequency response. We can design a filter by properly placing
zeros and poles in the z-plane.
• For a stable filter, all poles must be inside the unit circle
78
11.3 Sampling and reconstruction of analog signals
• Sampling is a process to convert an analog signal into a discrete signal with the sampling interval
Ts or the sampling frequency fs .
• The relationship between the analog frequency and the corresponding digital frequency is given
by:
ω = ΩTs = Ω/ fs
fs ≥ 2 fmax
• A low pass filter is used to reconstruct the analog signal from the digital form. The cutoff
frequency of the low pass filter should satisfy:
where Ωmax is the maximum frequency of the signal, Ωs = 2π fs and Ωc = 2π fc is cutoff fre-
quency of the filter.
79
12 FIR filter design
12.1 Design of FIR filters using windows
To design a filter, the desired filter characteristics are usually specified in the frequency domain in
terms of the magnitude and phase response. A digital filter can be either an FIR or an IIR filter. The
designer’s task is then to determine the type of the filter and the filter coefficients. In this section, we
discuss using the window method to determine the coefficients of an FIR filter of which the frequency
response is an approximation to the desired frequency response. Other methods, such as frequency
sampling and optimal FIR filter design, will not be discussed.
The task of designing an FIR filter can be described as: given the desired frequency response,
denoted by Hd (ω), determine the filter coefficients h[n] such that the resulting frequency response,
denoted by H(ω) is a good approximation of Hd (ω).
Usually, Hd (ω) is defined as piece-wise constant with discontinuity at the boundaries between
bands. As a result, the corresponding unit sample response is non-causal and is of infinite length. For
example, an ideal low pass filter is given by
1, 0 ≤ ω ≤ ωc
|Hd (ω)| =
0, ωc < ω ≤ π
We assume a linear phase response (∠Hd (ω) = −mω). To simplify the analysis, this phase character-
istic is neglected temporarily by assuming zero delay (m = 0). The unit sample response is determined
by
1 Rπ jωn dω
hd [n] = 2π −π Hd (ω)e
1 R ωc jωn dω
= 2π −ωc H(ω)e
1 R ωc jωn dω
= 2π −ωc e
1
= πn sin(nωc ), n = 0, ±1, ±2, ...
Therefore, the unit sample response of an ideal low pass filter is of infinite length and is non-causal.
To make it an FIR filter, we can truncate it to a length of 2N + 1 by using
hd [n], |n| ≤ N
h[n] =
0, |n| > N
There are two implications for this process. The first implication is that truncation in this way can be
regarded as multiplication of hd [n] by a window function, denoted by w[n]
h[n] = hd [n]w[n]
where
1, |n| ≤ N
w[n] =
0, |n| > N
The second implication is that the resulting frequency response is no longer the same as the ideal
one. It is actually a convolution of Hd (ω) with W (ω) which is the Fourier transform of the window
function w[n]. This is a direct result of the property of the Fourier transform which states that the
multiplication of two sequences in the time domain corresponds to the convolution of their respective
Fourier transform in the frequency domain. Figure 50 shows the Fourier transform of the window
function as well as the result of the convolution.
We can see from Figure 50 that the “distortions” in the resulting frequency response are
80
10
Fourier transform of a window function
8
ideal half band filter
0
0 20 40 60 80 100 120 140
1.2
Actual frequency response of a half band filter
1
0.8
0.6
0.4
0.2
0
0 20 40 60 80 100 120 140
Figure 50: The actual frequency response is a result of the convolution of the Fourier transform of the
window function and the ideal frequency response.
• a smooth transition between the pass band and the stop band, which is largely due to the width
of the main lobe of the Fourier transform of the window function, and
• the ripples in both pass band and stop band which are due to the main lobe and the side lobes.
Since our task is to design a filter such that its frequency response is a good approximation to the
desired one, we must optimize the window function. In an ideal case, the Fourier transform of the
window function should be an impulse. This is not possible, because it requires that the window be
of infinite length. Generally, a longer window leads to a longer unit sample response and a better
approximation to the desired frequency response. Figure 51 shows the Fourier transform of a rectan-
gular window of different lengths as well as the resulting frequency response of the half band filter.
We can see from this figure that as the length of the window increases, the width of main lobe and the
magnitude of the side lobes decrease. The resulting frequency response better approximates the ideal
one.
A practical requirement is that we should choose a window function such that its Fourier trans-
form has a very narrow main lobe and a very small side lobe magnitude. However, these are usually
conflicting requirements for a fixed window length. For example, by tapering the window smoothly
to zero at each end, the magnitude of the side lobes becomes smaller at the cost of a wider main lobe.
There is a trade-off between the width of the main lobe and magnitude of the side lobes. Figure 52
shows a number of window functions and their Fourier transforms.
So what is a good window function? We can see from Figure 52 that if a sharp transition between
the pass band and the stop band is desired, then for a given filter length the rectangular window is most
suitable as its main lobe is the narrowest among other window functions. However, it should be noted
that the magnitude of its side lobes is also the largest.
81
0 0
main lobe
−20
−20 side lobes
−40 n=10
−40
−60
−60
−80
−80
−100
−100 −120
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
0 20
−20 0
−20
−40 n=50
−40
−60
−60
−80
−80
−100 −100
−120 −120
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
0 20
−20 0
−20
−40
−40 n=100
−60
−60
−80
−80
−100 −100
−120 −120
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Figure 51: Left panel: the Fourier transform of Hamming window with N=10, 50 and 100. Right
panel: the frequency response of an FIR filter (cutoff frequency ωc = 0.4π) designed using the Ham-
ming window with N=10, 50, 100.
82
0 0
−50 −50
−100 −100
−150 −150
hamming
−200 −200
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
0 20
0
−20
−20
−40
−40
−60
−60
boxcar
−80 −80
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
0 50
−20
0
−40
−50
−60
−100
−80
blackman
−100 −150
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Figure 52: This figure shows the different characteristics of window functions and the FIR filters
designed using thes window functions. Left panel: the Fourier transform of three window functions
(top to bottom) Hamming, boxcar and Blackman. Right penal: the amplitute response of the FIR
filters designed using these window functions.
83
0.2
−10 −8 −6 −4 −2 0 2 4 6 8 10
0.2
0 2 4 6 8 10 12 14 16 18 20
Figure 53: The unit sample response before and after shifting
Low pass filter
−2pi 0 w pi 2pi
Figure 54: Magnitude relationship between a low pass filter and a high pass filter.
n 0 ±1 ±2 ±3 ±4 ±5 ±6 ±7 ±8 ±9 ±10
h[n] .25 .225 .159 .075 0 -.045 -.053 -.032 0 .025 .032
To make this filter causal, the unit sample response is shifted to the right side by 10 samples:
1
h(n) = sin((n − 10)ωc ), 0 ≤ n ≤ 20, ...
π(n − 10)
The shifting introduces delay in the system. Figure 53 shows the unit sample response before and after
shifting.
HH (ω) = HL (ω − π)
84
Here we use the subscripts H and L to represent the high pass and low pass filter, respectively. Ac-
cording to the definition, we have
∞
HH (ω) = ∑ hH (n)e− jωn
n=−∞
and
∞
HL (ω) = ∑ hL (n)e− jωn
n=−∞
then
HH (ω) = HL (ω − π)
= ∑∞ − j(ω−π)n
n=−∞ hL (n)e
= ∑n=−∞ hL (n)e jπn e− jωn
∞
Therefore, we have established the relationship between the low pass and high pass filters in the time
domain
ωu − ωl = 2ωc
ωu +ωl
2 = ω0
ωu − ωl = 2ωc
ωu +ωl
2 = ω0
Figure 55 shows the magnitude responses for both type of filters. To design a band pass filter
based on the above method is simple. For example, a 11th order digital filter is required to meet the
following specifications: sampling frequency 10 kHz, pass band 1kHz to 2 kHz. We need to convert
the specification into the discrete radian frequency by using
ω = Ω/ fs = 2π f / fs
85
band pass filter
ωl ω0 ωu
ωl ω0 ωu
Figure 55: The magnitude response. Top : band pass filter, bottom: band stop filter
Therefore, we have
ωu = 2π × 2/10 = 0.4π
and
ωl = 2π × 1/10 = 0.2π
The corresponding cut off frequency of the low pass filter is
ωu − ωl
ωc = = 0.1π
2
and the center frequency of the pass band is
ωu + ωl
ω0 = = 0.3π
2
Therefore, the unit sample response of the band pass filter is given by
• How do you convert the above low pass filter into a high pass filter with a cutoff frequency of
0.5π?
• A 7th order digital filter is required to meet the following specifications: sampling frequency
40 kHz, stop band from 4kHz to 8 kHz. Design a causal digital band stop filter to meet these
requirements. Plot the magnitude response to verify your design. (hint: refer to the example in
section 12.4)
86
13 IIR filter design
This section is divided into three parts: analog prototype filters, IIR filter design using the bi-linear
transform, and IIR filter design using Matlab.
Y (s)
H(s) =
X(s)
The frequency response is given by substituting s = jΩ into the transfer function.
H(Ω) = H(s) s= jΩ
1
|H(Ω)|2 =
1 + ε2 (Ω/Ωc )2N
where ε is the parameter that controls the ripple (usually ε=1 ), Ωc is the cutoff frequency and N is
the order of the filter. The Butterworth filter is maximally-flat and it passes through -3dB at the cut-off
frequency.
When the cut off frequency is 1, the filter is called the prototype (since filters with different cut off
frequency can be easily obtained from the prototype by a scaling in the frequency domain).
1
|H(Ω)|2 =
1 + Ω2N
The only parameter is the order of the filter. It is usually determined by the specification of the signal
processing system, ie, the attenuation at a given frequency Ωa . For example, if an attenuation of M
dB is required, then
1
M = 10 log10 |H(Ωa )|2 = 10 log10
1 + Ω2N
a
and
M
log10 10− 10 − 1
N=
2 log10 Ωa
87
13.1.3 Chebyshev low pass prototype filter design
A class of filters are called equal-ripple filters. The Chebyshev filter has equal-ripple in the pass
band, the inverse Chebyshev filter has equal-ripple in the stop band. By allowing ripples in the filter
frequency response, a sharper transition from pass band to stop band than that of the Butterworth filter
can be achieved.
The Chebyshev low pass prototype is defined as:
1
|H(Ω)|2 =
1 + ε2CN2 (Ω)
where CN (Ω) is the N-th order Chebyshev polynomial It can be defined by the recursion function
where
C0 (Ω) = 1
and
C1 (Ω) = Ω
The prototype ripple bandwidth is from 0 ≤ Ω ≤ 1 . In 0 ≤ Ω ≤ 1, there are N maximum and
minimum points. The ripple amplitude in dB is given by
1
rdB = −10 log10 ( ) = 10 log10 (1 + ε2 )
1 + ε2
The -3dB cutoff frequency is greater than 1.
To design a Chebyshev filter, two parameters need to be determined. The desired ripple is set by
ε and the order N is found by knowing a desired half-power or -3dB frequency and/or the required
stop band characteristics. This is usually done by consulting a filter design handbook (using tables or
monograms)
1
|H(Ω)|2 =
1 + ε2 ZN2 (Ω)
where ZN (Ω) is a Chebyshev rational function determined from the specified ripple characteristics.
An elliptic filter has three parameters (which can be defined in different ways). One set of parameters
are the order N, the acceptable pass band ripple and the acceptable stop band gain.
The magnitude responses for 4th-order digital IIR filters (Butterworth, Chebyshev-I and elliptic
filter) are shown in Figure 56.
z−1
s=
z+1
88
1
0.5
0
0 20 40 60 80 100 120 140
0.5
0
0 20 40 60 80 100 120 140
0.5
0
0 20 40 60 80 100 120 140
Figure 56: Magnitude response of Butterworth filter (top), Chebyshev-I filter (middle) and elliptic
filter (bottom)
1.2
0.8
0.6
0.4
0.2
0
0 20 40 60 80 100 120 140
Figure 57: The magnitude response of a second order digital Butterworth filter designed using bilinear
transform.
The transfer function of an analog filter H(s) is converted to that of a digital filter with the transfer
function
z−1
H
z+1
For example, the transfer function of the second order Butterworth prototype filter and its correspond-
ing digital filter are:
1
H(s) = √
1 + 2s + s2
and
1 1 + 2z−1 + z−2
H(z) = √ z−1 = 0.293
1 + 2 z+1 + z−1 2 1 + 0.172z−2
z+1
The frequency response of this digital filter is shown in Figure 57.
It can be shown that using the bilinear transform, the right/left half of the s-plane is mapped to the
exterior/interior of the unit circle of the z-plane, and the entire imaginary axis of the s-plane is mapped
89
to the unit circle in the z-plane. Therefore, a stable analog filter (the poles of which must be in the
left-half of the s-plane) is converted to a stable digital filter (the poles of which must be inside the unit
circle).
How does the system function of H(s) relate to that of H(z)? The frequency responses of the
analog and the digital filter can be calculated by
H(Ω) = H(s)|s= jΩ
and
H(ω) = H(z)|z=e jω
Therefore the bilinear transform corresponds to the following relationship in frequency:
e jω − 1
jΩ =
e jω + 1
The above equation is equivalent to ω
Ω = tan
2
One can easily see that the range of the discrete radian frequency [0, π] is mapped to the analog
frequency range [0, ∞) . Therefore, the bilinear transform corresponds to a nonlinear compression of
the analog frequency range to the discrete radian frequency range.
In general, the design of a digital IIR filter using the bilinear transform involves the following
steps
1. Determine the filter specification (such as the cutoff frequency) according to a problem
2. Prewarp the discrete radian frequencies using the above equation. This step converts the discrete
radian frequencies into the analog frequencies.
4. Use the bilinear transform to determined the transfer function of the digital filter.
90
pass band ripple
Rp
at both pass band and stop band. So there is a trade-off between the computational complexity (order
of the filter) and the frequency response.
Here is an example14 of the 4 types of IIR filters with ω p = 0.2, ωs = 0.3, R p = 1 and Rs = 40. The
amplitude responses are roughly the same, when we ignor the effects of ripples. However, the order
of these filters are not the same, Butterworth 12, Chebyshev I and II 6, and elliptic 4. In other words,
to have roughly the same amplitude response, the elliptic filter is most computational efficient among
the filters. This is at the costs of having ripples in both the pass band and stop band. The butterorth
filter, on the other hand, is most computationally demanding. It has the advantage of being max-flat,
i.e., no ripples. The computational requirement for the Chebyshev typy I and II filters is between the
elliptic and butterworth filters. What will happen if we use the same order for the filter types? Fig. 61
shows the amplitude repsonses of using N = 4. We can clearly see that the elliptic filter has the fastest
14 Hereis the matlab code.
wp=0.2; ws=0.3; rp=1; rs=40;
[bN,bw] = buttord(wp,ws,rp,rs);
[c1N,c1w] = cheb1ord(wp,ws,rp,rs);
[c2N,c2w] = cheb2ord(wp,ws,rp,rs);
[eN,ew] = ellipord(wp,ws,rp,rs);
[bb,ba]=butter(bN,bw);
[c1b,c1a]=cheby1(c1N,rp,c1w);
[c2b,c2a]=cheby2(c2N,rs,c2w);
[eb,ea]=ellip(eN,rp,rs,ew);
[bH,W]=freqz(bb,ba,10000);
[c1H,W]=freqz(c1b,c1a,10000);
[c2H,W]=freqz(c2b,c2a,10000);
[eH,W]=freqz(eb,ea,10000);
subplot(421);plot(W/pi,abs(bH))
subplot(422);plot(W/pi,20*log10(abs(bH)))
subplot(423);plot(W/pi,abs(c1H))
subplot(424);plot(W/pi,20*log10(abs(c1H)))
subplot(425);plot(W/pi,abs(c2H))
subplot(426);plot(W/pi,20*log10(abs(c2H)))
subplot(427);plot(W/pi,abs(eH))
subplot(428);plot(W/pi,20*log10(abs(eH)))
91
1.5 200
butterworth
0
1
−200
0.5
−400
0 −600
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
1 0
cheby1
0.8 −100
0.6 −200
0.4 −300
0.2 −400
0 −500
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
1.5 50
cheby2
0
1
−50
0.5
−100
0 −150
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
1 0
0.8 elliptic
−50
0.6
0.4
−100
0.2
0 92 −150
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
1.5 100
butterworth
0
1
−100
−200
0.5
−300
0 −400
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
1 0
cheby1
0.8
−100
0.6
−200
0.4
−300
0.2
0 −400
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
1.5 50
cheby2
0
1
−50
0.5
−100
0 −150
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
1 0
0.8 elliptic
−50
0.6
0.4
−100
0.2
0 93 −150
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
change from pass band to stop band, while the Butterworth has the slowest changes.
1. Choose the type of the filter that best fits the application.
2. Determine the order of the filter by using the following Matlab functions. Note that the fre-
quency specifications must be normalized discrete radian frequency in the range [0, 1], which
corresponds to [0,π]. If the filter is a band pass or band stop filter, then the frequency specifica-
tions are two-element vectors.
3. Determine the filter coefficients. In Matlab, the filter coefficients are stored in two vectors called
b and a.
B(z) b(1) + b(2)z−1 + ... + b(n + 1)z−n
H(z) = =
A(z) 1 + a(2)z−1 + ... + a(n + 1)z−n
To design a low pass filter, you use:
4. Test your design. You may plot the frequency response of the filter to see if it matches the
specification. A more important task is to see the quantization effect of the filter coefficients.
94
Example 2
The signal is sampled at 1000 samples/sec. Design a 10th-order band pass digital Butterworth filter
with a pass band from 100 to 200 Hz. As in example 1, we first convert the filter specification to
normalized discrete radian frequency by using
Ωc Ts 2π fc 2 fc
ωc = = =
π π fs fs
The filter coefficients are then calculated by using
Note that in the above Matlab function [b, a] = butter(n, w), when the cut off frequency is a two-
element vector, it will produce a filter with an order of 2n.
Example 3
Design a Chebyshev type-I filter with the following specifications
We can see that this is a band pass filter. We need to determine the filter specification first
w p = [600, 900]/1500
ws = [200, 1300]/1500
Rp = 1
Rs = 40; %not -40
[n, w] = cheb1ord(w p , ws , R p , Rs )
The amplitude response15 is plotted in both linear scale (left) and log-scale (dB). Note that the unit
of the horizontal axis is now coverted to Hertz.
Example 4
Design a max-flat low pass filter with the following specification
95
1 0
0.9
0.8 −50
0.7
0.6 −100
0.5
0.4 −150
0.3
0.2 −200
0.1
0 −250
0 500 1000 1500 0 500 1000 1500
Figure 61: Amplitude response of the Chebyshev type I filter in linear scale and log scale (dB).
According to the filter requirements, we use a Butterworth filter and follow exactly the same procedure
as example 3 to design the filter. This is shown in the following
w p = 2/10;
ws = 4/10;
R p = 3;
Rs = 10; %not -10
[n, w] = buttord(w p , ws , R p , Rs );
[b, a] = butter(n, w);
• For a sampling frequency of 400 Hz, what is the minimum order for an elliptic filter that you
can use to separate the 80 Hz cosine signal from its mixture with a 50 Hz cosine signal.
96
14 Applications of DSP16
14.1 Audio signal processing
14.1.1 Reverberation effects
14.1.2 Equalizers
14.1.3 Digital FM stereo generation
14.2 Number representations in digital signal processors
14.2.1 Fix point representation
The simplest representation is to use a format: sign+value. In this section, this format is referred to
as the signed-binary format. For example, the number (-10 ) can be represented as: 10001010, where
the MSB is the sign bit and the rest bits represent the value. In this case, 1 is used to represent the
negative sign and 0 is used to represent the positive sign.
Fix point DSP devices use a format called the two’s complement, where a positive number is
represented in exactly the same as the above example. The negative number, however, is represented
in a different format. The procedure to convert a negative number from the signed-binary format to
the two’s complement format involves three simple steps:
One advantage of two’s complement format is that one adder is required for both positive and negative
numbers. Another advantage is that if the final result is known to be within the processor’s number
range, then an intermediate overflow can be ignored as the final correct result will be produced. A
16-bit integer in two’s complement format can vary between +32767 and -32768. This is known as
the 16.0 format for the Analog Devices DSP processor ADSP 219x/2191. The value of the number is
calculated as: x = (−215 )a15 + ∑14
i=0 ai 2
i
In DSP, it is also common to represent numbers as fractions. The reason for this is that when
multiplying fractions (e.g. 0.99 × 0.98) the result will be always less than one and there is never an
overflow. For a fix point processor this is obvious an advantage. The TMS320c5x processor uses a
format call Q15 which is show below:
The Q15 format is also known as the 1.15 format for the Analog Devices DSP processor 219x/2191,
which supports both formats: 1.15 and 16.0. The user must specify which format is being used by
setting a bit in the MSTAT register.
Using the Q15 format, the number, x = (−1)a0 + ∑15 i=1 ai 2 , varies from -1 to 0.99996948242188.
−i
Addition and subtraction are exactly the same as for binary integers. The multiplications of two Q15
numbers results in a Q30 number which is also a fraction. It has 30 fractional bits, 2 sign bits and
no integer bits. To store the result as a Q15 number, a left shift of one bit is performed to eliminate
the extract sign bit and the resulting left-most 16 bits are stored. An interesting property of the two’s
16 This section is still being written.
97
complement format is that for a negative number, if you add a “1” in front of the MSB, the value of the
number remains the same. For example, -4 = 1100 (-8+4) = 11100 (-16+8+4) = 111100 (-32+16+8+4).
Let us use a few simple examples to illustrate the addition and mutilication of numbers in two’s
complement format. To simplify our example, we will use 4.0 format which can represent an integer
ranging from -8 (1000) to 7 (0111).
Example 1
3 - 4 = 0011 + 1100 = 1111 = -1
Example 2
In this example, we have to left shift one bit to get rid of the extra sign bit to get the correct result.
5 - 4 = 0101 + 1100 = 10001 = 0001 = 1
Example 3
3 × (−4) = 0011 × 1100 = 1110100 = −12. The actual calculation is shown below
Example 4
(−3) × (−4) = 1101 × 1100 = 0001100 = 12
Using a fixed point DSP processor such as ADSP 219x, if both operands are in 1.15 format, the
multiplication of these two numbers results in 2.30 format (2 sign bits and 30 fractional bits). The
processor can automatically left shift one bit to get rid of the extra sign bit and the result is a 1.31
format which is then truncated to 1.15 format.
31 30 23 22 0
s EXPONENT(E) FRACTION(F)
MSB LSB MSB LSB
98
• If E = 0 and F = 0, then x = 0.
EXPONENT(E) s FRACTION(F)
31 24 23 22 0
So we see that the performance of the filter changes a lot as the number of bits used to represent
the filter varies from 5 to 15. The quantization effect is more significant for an IIR than an FIR filter.
FIR filters are always stable, while quantization could turn a stable IIR filter into a unstable one since
the poles of the filter with quantized coefficients may be outside the unit circle. The following figure
shows the quantization effect of a 5th order Butterworth filter.
99
Figure 62: Quantization effects
1
10
f5
0
10
−1
10
−2 f8
10
f15
−3
10
−4 f12
10
f10
−5
10
−6
10
0 10 20 30 40 50 60 70 80 90 100
1.4
0.6 256 0
−762 1
974 3
8−bit −652 3
225 1
0.4 −33 0
0.2
0
0 20 40 60 80 100 120 140
100
Implementing an IIR filter in a fix point processor needs more careful efforts. For example to
implement an IIR filter described the difference equation:
In this equation, variables multiplied by an integer can be implemented by addition. Those fractional
multiplication factors must be quantized.
Direct addressing
In the direct memory addressing mode, the instruction contain the lower 7-bit of the data memory
address (dma). The 7-bit dma is concatenated with the 9-bit of the data memory page pointer (DP)
in status register 0 to form the full 16-bit address. The DP bits can be loaded by using the LDP
instruction. It should be noted that the DP is not initialized by reset and , therefore, is undefined after
power on. It is critical that all programs initialized the DP in software.
Indirect addressing
The C50 processor has 8 16-bit auxiliary registers(AR0-AR7) that provide flexible and powerful in-
direct addressing. Any location in the 64K-word data memory space cane be accessed using a 16-bit
address contained in an AR. For example, to select a AR0 as the current AR and load it with the
address 0f00, you can use the following code :
MAR *, AR0
LAR AR0 #0f00
The following indirect-addressing symbols are used in the C5x assembly language instructions
101
* no increment or decrement. content of the current AR is used as the dma
*+ content of the current AR is used as the dma,
after memory access, content of the current AR is increment by 1
*- content of the current AR is used as the dma,
after memory access, content of the current AR is decrement by 1
The real time implementation of this filter involves: (1) storing the coefficients in memory, (2) storing
N samples of the data in memory and (3) performing the multiplication-and-sum operations and up-
dating the data as the filtering operation finishes. For simplicity, we will use a 3rd order FIR filter to
illustrate the implementation. The filter coefficients are a0 = 1, a1 = 2, and a2 = 1. They are stored
in memory location starting from 0xf280. The three data samples are stored in in memory location
starting from 0xf380 and they initialized as zeros. The newest sample x(n) is always stored in the
location 0xf380. This is illustrated in the following figure:
↓x(n + 1)
f280 a2 1 f380 x(n) 0
f281 a1 2 f381 x(n − 1) 0
f282 a0 1 f382 x(n − 2) 0
In this figure, the arrow indicates that when a new sample x(n + 1) is available the data memory
must be moved up by one sample so that the next filtering operation can be performed. The source
code for specifying the filter coefficients and initialization of data memory is shown below:
The implementation of the FIR filter is based on a powerful instruction called MACD. The source
code is listed blow.
102
RECEIVE:
LDP #XN ;load DP register
CLRC INTM ;clear interup mode
LAMM DRR ;read a new sample from DRR
SACL XN ;store new sample to location XN
;start FIR
ZAP ;ACC=0,P=0
LAR ar0, #XNLAST ;load the address of XNLAST to ar0
MAR *,ar0 ;content of ar0 is used as data memory address
RPT #taps-1 ;repeat MACD until repeat counter=0
MACD #coefftab,*- ;multiplication and sum and data move
APAC ; ACC = ACC +P
SACH Output, 1 ;get rid of extra sign bit
LACC Output ;load output to ACC
SFL ;left shift ACC one bit
AND #0fffch ;get rid of last 2-bits for a 14-bit DAC
SAMM DXR ;send to output register
RETE ;return
After reading and storing the new data sample XN, the ACC and P register are set to zero, and
the address of the data memory is pointed to the last data sample. The execution of the the next two
instructions (RPT and MACD) is shown the following steps:
if(repeat_counter !=0 )
{
1. (ACC) = (ACC) + (shifted P register ); //the shift is defined by the PM status bit
2. (P register) =(coefftab) * (current data address); //the current coefficient is multiplied by the the
content of the data memory whose address is pointed to by the current AR
3. current data address = current data address -1; //point to next data
5. (current data address +1) = ( current data address ); //move the processed sample to next data
memory location
else
{perform the above steps 1, 2,3, 5}
The following figure shows the actual implementation using a 3rd order FIR filter. In the figure,
the symbol “#” represents the current data/coefficient.
103
14.4.3 The assembler source code
This section is taken from the TMS320C50 DSK User’s Guide.
15 Spectrum analysis
16 Problem class-3 23
17 Exam Tutorial 24
104
Due Date 2 pm Monday
L A T ROBE U NIVERSITY
D EPARTMENT OF E LECTRONIC E NGINEERING
ELE32DSP: D IGITAL S IGNAL P ROCESSING
DECLARATION
I certify that the above assignment is my original work and that no part of
it has been copied or reproduced from any other person’s work without
acknowledgment.
Signed: Date:
1. A signal is given by x[-1] = 1, x[0] = 2, x[1] = 2, and x[2] = 1. Sketch the following signals and
represent them as a linear combination of δ[n] . (1.1) x[n], (1.2) x[3-n], (1.3) x[n-2].
2. Use the signal x[n] = cos(ωn) to show that the discrete radian frequency is in the range [0, 2π].
Assume this signal is a periodic signal with a period of 7. Determine all possible distinctive
frequencies for this periodic signal.
3. A signal is given by x[0] = 1, x[1] = 2, x[2] = 2, and x[3] = 1. Perform the convolution operations
x[n] ∗ h[n] for the following unit sample responses. (3.1) h[0] = 1, h[1] = -1, (3.2) h[-1] = -1,
h[0] = 2, h[1] = -1, (3.3) h[0] = 1, h[1] = 0, h[2] = -2, h[3] = 0, h[4] =1.
4. The signal specified in question 3 is processed by a system which is a cascade of two sub-
systems specified by (3.1) and (3.2) respectively. Determine and sketch the output of the whole
system. Is this a causal system ?
5. An LTI system is given by y[n] = x[n] − 2x[n − 1] + x[n − 2]. Determine the unit sample response
and frequency response of the system.
6. A system is given by y[n] = ax[n] + b where a and b are two constants. Determine if this is an
LTI system
105
Due Date 2 pm Monday
L A T ROBE U NIVERSITY
D EPARTMENT OF E LECTRONIC E NGINEERING
ELE32DSP: D IGITAL S IGNAL P ROCESSING
DECLARATION
I certify that the above assignment is my original work and that no part of
it has been copied or reproduced from any other person’s work without
acknowledgment.
Signed: Date:
1. (a) Find the frequency response of the LTI system whose input and output satisfy the difference
equation
y[n] = 0.5y[n − 1] + x[n] + 2x[n − 1] + x[n − 2]
(b) Write a difference equation that characterizes s system whose frequency response is
1 − 0.5e− jω + e− j3ω
H(ω) =
1 + 0.5e− jω + 0.75e− j2ω
Find its unit sample response and frequency response. Is this a high pass filter ?
3. Use the Fourier transform to perform the convolution x[n] ∗ h[n], where x[n] = {1, 2, 1} and
h[n] = {1, −1}.
(a) Obtain an expression for the frequency response of this system. Hint:
(1 − a)3 = 1 − 3a + 3a2 − a3
106
(b) What is the output if the input is
x[n] = 10 + 4cos(0.5πn)
5. Let x(t) = 7sin(11πt). In each of the following cases, the discrete time signal x[n] is obtained
by sampling x(t) at a frequency fs and the resultant x[n] can be written as
x[n] = Acos(2π f0 n + φ)
So for each case below, determine the values of A, f0 and φ. In addition, state whether the
sampling theorem is satisfied. (a) fs = 5 Hz, (b) fs = 10 Hz (c) fs = 15 Hz
6. 2.3 The sequence, x[n] = cos( π7 n), −∞ < n < ∞ , was obtained by sampling an analog signal
xc (t) = cos(Ωt), −∞ < t < ∞ , at a sampling rate of 2000 samples/second. What are the three
smallest possible values of Ω (Ω > 0) that could have resulted in the same discrete signal ?
7. The band width of an analog signals 8 kHz. This signal is processed by an analog low pass filter
whose cutoff frequency is 3 kHz. If this signal processing task is performed by a digital signal
processing system, determine the minimum sampling frequency and the corresponding cut off
frequency of the digital low pass filter.
107
Due Date 2 pm Monday
L A T ROBE U NIVERSITY
D EPARTMENT OF E LECTRONIC E NGINEERING
ELE32DSP: D IGITAL S IGNAL P ROCESSING
DECLARATION
I certify that the above assignment is my original work and that no part of
it has been copied or reproduced from any other person’s work without
acknowledgment.
Signed: Date:
Question 1
Design a 9-tap FIR low pass filter with a rectangular window to separate two sinusoidal signals
whose frequencies are 500 Hz and 50 Hz, respectively.
(4 marks)
(6 marks)
• How would you modify the filter coefficients to make it a high pass filter that can be used to
separate these two signals ?
(6 marks)
Question 2
Briefly describe the frequency response of the following types of IIR filters
• Butterworth filter
• Chebyshev filter
• Elliptic filter
108
(9 marks)
The following questions are related to filter design using Matlab. Some useful Matlab functions
are semilogy, fir1, freqz and those listed in Section 13.3 of the lecture notes
Question 3
Determine the transfer function of a third order low pass Butterworth filter whose cutoff frequency
is π/4. Plot its amplitude response. If the same amplitude response is produced by an FIR filter,
estimate the order of that FIR filter by trying different order and plotting the corresponding amplitude
response.
(10 marks)
Question 5
Determine the transfer function of a Chebyshev type 1 filter with the following specifications:
(a) 1 dB ripple in the range 600-900 Hz (b) the sampling frequency is 3000Hz
(c) a maximum gain of -40 dB at frequency range [0, 200] Hz and [1300, ∞) Hz.
Draw a direct form-2 implementation of this filter.
(10 marks)
109
Due Date 2 pm, Monday Oct. 30, 2006
L A T ROBE U NIVERSITY
D EPARTMENT OF E LECTRONIC E NGINEERING
ELE32DSP: D IGITAL S IGNAL P ROCESSING
DECLARATION
I certify that the above assignment is my original work and that no part of
it has been copied or reproduced from any other person’s work without
acknowledgment.
Signed: Date:
Question 1
We want to use DSP to separate two sinusoidal signals whose frequencies are 500 Hz and 50 Hz,
respectively. Assume the sampling frequency is 4000Hz. You need to design a 7-tap FIR low pass
filter with a rectangular window.
(a) Determine the specification of the filter.
(b) Write an expression for a seven term casual impulse response
(c) How would you modify the filter coefficients to make it a high pass filter that can be used to
separate these two signals ?
(10 marks)
Question 2
110
Question 3
Question 4
(15 marks)
0.8
0.6
0.4
Imaginary Part
0.2
0 2
−0.2
−0.4
−0.6
−0.8
−1
−1 −0.5 0 0.5 1
Real Part
111
Due Date 2 pm, Monday Oct. 30, 2006
DECLARATION
I certify that the above assignment is my original work and that no part of
it has been copied or reproduced from any other person’s work without
acknowledgment.
Question 1
112
Question 2
Question 3
(15 marks)
0.8
0.6
0.4
Imaginary Part
0.2
0 2
−0.2
−0.4
−0.6
−0.8
−1
−1 −0.5 0 0.5 1
Real Part
Question 4
Match the frequency responses (A-E) with the correct pole-zero plots (PZ 1-6). Poles are denoted
by x and zeros by o.
(15 marks)
113
L A T ROBE U NIVERSITY
D EPARTMENT OF E LECTRONIC E NGINEERING
ELE31DSP: D IGITAL S IGNAL P ROCESSING
DECLARATION
I certify that the above assignment is my original work and that no part of
it has been copied or reproduced from any other person’s work without
acknowledgment.
Signed: Date:
The following questions are related to window methods for FIR filter design which is cover in the
lecture notes, in section 8.2.2 of Proakis’ book, and in section 7.4 of Oppenheim’s book. Other DSP
books also cover this topic (but not DSP First). You need to use Matlab to do the simulation. Matlab
is available in the PC’s in the CAD lab.
1. Derive the impulse response for an ideal low pass filter and an ideal high pass filter whose
cut-off frequency is ωc . Briefly describe the window method for FIR filter design.
2 Based on your results in question 1, design an FIR filter approximating the ideal frequency
response
(a) Determine the filter coefficients of a 25-tap filter using a rectangular window
(b) Plot the magnitude response of the filter
Use Matlab function fir1 to design the same FIR filter
(c) Using the Hamming window
(d) Using the a Bartlett window
(e) Compare the magnitude responses and identify their differences.
Note: In Matlab function fir1, the highest frequency is 1. So the cutoff frequency of π/6 corre-
sponds to 1/6.
3. Based on your results in question 1, design an FIR filter approximating the ideal frequency
response
(a) Determine the filter coefficients of a 25-tap filter using a rectangular window
(b) Plot the magnitude response of the filter
4. An analog signal is given by s(t) = cos(10000t) .
(a) Determine the Nyquist sampling frequency for this signal and the expression for the corre-
sponding digital signal.
(b) If this analog signal is sampled with a period T=10−6 second, then the corresponding digital
signal is :
s(n) = cos(0.01n) . What is the digital frequency of this signal ? Assume that the signal is
corrupted by noise :
114
x(n) = s(n) + r(n) , where r(n) is the noise. In Matlab, this can be simulated by:
n=0:1023; %assume we have 1024 data
x=cos(0.01*n)+rand(size(n)); %create the noise corrupted signal
plot(x)
(c) Design a low pass filter to filter out noise. This can be easily done using Matlab commands
fir1 and filter. Use the help command to learn how to use these two commands. Justify the cut-off
frequency you use in the low pass filter. Using a Hamming window and a fixed cut-off frequency,
compare the filtering results by using filters of different length (4, 14, 24, 104).
A sample Matlab code to implement the filtering process is given below:
f=fir1(4,0.4); %design a 5-tap low pass filter, cutoff frequency=0.4
y=filter(f, 1, x); %filter the signal
plot(y) %plot the output
(d) Repeat part (c) using a rectangular window.
(e) Compare the results in parts (c) and (d). For the same window, what do you observe as the
length of the filter increases ? For the same filter length, which window produces a better filtering
result ? The above questions can be answered by plotting the magnitude of the frequency response of
different filters, ie, plot(abs(freqz(f,1,128))).
115
L A T ROBE U NIVERSITY
D EPARTMENT OF E LECTRONIC E NGINEERING
ELE31DSP: D IGITAL S IGNAL P ROCESSING
DECLARATION
I certify that the above assignment is my original work and that no part of
it has been copied or reproduced from any other person’s work without
acknowledgment.
Signed: Date:
0. The following questions are related to IIR filter design using Matlab. Matlab is available in the
PC’s in the CAD lab. Section 13.3 of the lecture notes provides a brief summary of all functions you
need. Use help function-name to learn how to use them.
1. Determine the transfer function of a third order low pass Butterworth filter whose cutoff fre-
quency is π/4. Plot its amplitude response. If the same amplitude response is produced by an FIR
filter, estimate the order of that FIR filter by trying different order and plotting the corresponding
amplitude response.
2 Determine the transfer function of a Chebyshev type 1 filter with the following specifications:
(a) 1 dB ripple in the range 600-900 Hz (b) the sampling frequency is 3000Hz
(c) a maximum gain of -40 dB at frequency range [0, 200] Hz and [1300, ∞) Hz.
Draw a direct form-2 implementation of this filter.
3. Determine the transfer function of a low pass elliptic filter with the following specifications:
(a) pass band ripple 0.5 dB (b) stop band gain -30 dB
(c) pass band ripple-edge frequency = 2 kHz
(d) stop band ripple-edge frequency = 2.5 kHz
Draw a direct form-2 implementation of this filter
4. Design a second order digital IIR filter to remove the cos 5t component from the following
signal:
116
19 Appendix-II Laboratory Instructions
Preliminary work
The following is a list of preliminary work associated with using Matlab.
You should go through the following exercises in your spare time before
the lab. You should be able to show your work upon request.
• If you want to have two figures in one “big” figure, you use the command hold on
figure(1);clf
subplot(211);stem(h);
subplot(212);plot(n,s);
figure(2);clf
subplot(121);stem(h);
subplot(122);plot(n,s);
Look at figure 1 and figure 2 carefully, you will see how to use the command subplot prop-
erly.
• To plot two signals in one figure, you use the command hold on
figure(3)
c = cos(pi ∗ n/10);
plot(n,c,’b’);
hold on
plot(n,s,’k’)
117
• You should know how to use the functions: plot, subplot, stem, figure and clf.
Here H is a complex valued vector. The kth element of H, denoted H[k], is the frequency
response H(ω) evaluated at ωk = Mπ (k − 1), i.e., H[k] = H(ωk ). The amplitude of the frequency
response at the particular frequency ωk is given by abs(H(k)) and the phase is angle(H(k)).
When k takes the value of 0,1,...,M, ωk takes the value of 0, Mπ ,..., (M−1)
M π. A larger value of M
leads to a better approximation of H(ω) by the vector H.
The other vector W represents the frequency. For example, the kth element of W, denoted W [k],
is W [k] = ωk = Mπ (k − 1). You should use help freqz to learn more about the function.
• You should know how to use the function freqz and semilogy to visualize the frequency
response of an FIR filter.
118
1. Introduction
In this lab you will use Matlab to study the frequency response of simple filters and to simulate an
image sharpening algorithm using convolution and the FFT. After this lab you should gain a deeper
understanding of certain important concepts such as convolution, frequency, amplitude and phase
response, and the Fourier transform. You should also learn numerical simulation techniques for system
analysis and implementation in the time domain and the frequency domain.
This lab is divided into three parts. The first part is designed for a review of some important
concepts. The second and third parts are designed for system analysis and implementation.
You should ask a tutor to verify what you have done as required in the verification sheet.
Lab Report
A lab report is due on Monday, Sept. 11, 2006. In the report, you should briefly comment on
what you have done and learned. You should also answer all questions.
h0 = [ 1 -2 1];
H0 = freqz ( h0, 1, 128, ’whole’); %calculate freq response from 0 to 2π
plot ( abs ( H0 ) ) %amplitude
figure ( 2 )
plot ( angle ( H0 )) %phase
If you are not familiar with the above Matlab commands, you can use the "help" command, eg,
help freqz. Observe that the amplitude is an even function and the phase is an odd function.
• Explain why the frequency response is usually specified in the range [0, π] ?
119
A cascade of two sub−system
input output
h0[n] h0[n]
input output
h1[n]
• Determine the unit sample response of the sub-system, denoted by h0 [n] and the whole system,
denoted by h1 [n]. Verify your results by using the convolution command: conv.
• Determine the system function of the system which is the z-transform of the impulse response.
You can skip this step if you do not know the z-transform.
• Is this system a causal filter ? If not, what is the simplest way to make it causal ?
• Explain that in the frequency domain the relationship between the magnitude responses of the
whole system and sub-system is |H1 (ω)| = |H02 (ω)|. You can verify this relationship in Matlab
by using: plot(abs(H1)-abs(H0.*H0)).
• Discuss the effects of adding a zero (or zeros) before (or after) the unit sample response. The
phase response of h3 should be the same as that of h1. To see the relationship between phase
response of h0 and that of h2, you can use the following Matlab code:
120
x[n] w[n]=x[n]*h[n] y[n]
LPF
+
h[n]
a
+
u[n]=w[n]−x[n]
+
−
2.4 Optional
Use the following example to study the range of the that the discrete radian frequency.
clear
n = 0 : 100;
x1 = cos ( 13 * n * pi / 3 );
x2=cos ( n * pi / 3 );
figure ( 1 )
clf
subplot ( 211 ); plot ( x1 )
subplot ( 212 ); plot ( x2 )
• A discrete sinusoidal signal is not necessary periodic. Generate and plot such a signal to show
that it is not periodic. (Hint: follow the above example to generate the signal).
3. System analysis
A simple and effective image sharpening filter is shown in Figure 1. In this filter, a is a constant.
• Assume the low pass filter (LPF) is fixed and its frequency response is denoted by H0 (ω). Derive
the frequency response of this filter, denoted by H(ω), in terms of H0 (ω).
• Assume the LPF is given by h0 [n] = {1/3, 1/3, 1/3}, plot the amplitude response of H(ω) using
a = 0.1 and a = 3.
• Assume the LPF is h0 [n] = {1/5, 1/5, 1/5, 1/5, 1/5}, plot the amplitude response of H(ω)
using a=0.1 and a=3. Study the difference in the amplitude response for these two different low
pass filters.
4. System implementation
Try the following Matlab code, which reads an image into an array and displays it.
121
image ( y ) %display image
y = double ( y ); % make it a double array required by conv
size(y) % the size of the image
h0 = [ 1 1 1] / 3;
a = input ( ’ Input the sharpening factor, a>1 sharpening, a<1 blurring’);
%The following part implements the image sharpening filter in the time domain
for i = 1 : 256
z ( i , 1 : 256 ) = (1 + a) * conv (y ( i ,1 : 254 ) , h0) - a * y ( i , 1 : 256);
end
%The following part limits the output pixel value to the range [0, 255]
z =z.*( z >= 0 ) ;
z = z.*(z <= 255 ) +255 * (z > 255 );
figure ( 1 );
colormap ( gray ( 256 ) );
image ( z’ )
Using the above Matlab code, the image is processed line by line. It is important to note that the length
of the signal resulted from a convolution of two signals of M and N elements is N + M − 1. Therefore,
to keep the processed image the same size as that of the original (in this case 256 pixels/line), a simple
way is to use part of the signal such that after the convolution the resulted signal has 256 pixels. That
is why we have the following: conv (y ( i ,1 : 254 ) , h0) in the Matlab code. For the ith line, we
take the first 254 pixels as the signal. Why use 254 pixels? Because h0 has 3 samples, the length
of the signal from convolution is 254+3-1=256. Therefore, if the length of h0 changes to 5, then we
only take 252 pixels. However, I should emphasize that this is NOT a very good way to deal with the
problem. A better way is to perform the convolution is take only the first 256 pixels of the result. The
Matlab code is as follows
for i = 1 : 256
tmp = conv (y ( i ,:) , h0);
tmp1 = tmp(1 : 256 ); %taking the first 256 pixels
z ( i , 1 : 256 ) = (1 + a) * tmp1 - a * y ( i , 1 : 256);
end
122
h = [ h0 zeros ( 1, 253 ) ];
H0 = fft ( h ); %convert h to the frequency domain
for i = 1 : 256
Y = fft ( y ( i , 1 : 256 ) );
Z = ( ( 1 + a ) * H0 - a ) . * Y;
z ( i , 1 : 256 ) = real ( ifft ( Z ) );
end
Here we make another impulse response h by appending 253 zeros to h0. As you have seen in
section 2, appending zeros to the end of a signal does not change the signal. The reason for doing so is
because in the frequency domain we need to perform the multiplication operation of H0 and Y. They
must be of the same size.
Here is your task: modify your m-file by replacing the convolution part with the above FFT section.
Save it as a new m-file. Run this m-file. You should compare the results of this section with those of
section 4.2.
123
Instructor Verification
Name
Student Number
Your laboratory work is divided into three parts. In each part, your work must be marked by the
demonstrator. The mark is from 1 (poor) to 5 (excellent).
Preliminary work
124
B Applications of digital filters
LA TROBE UNIVERSITY
ELE31DSP LABORATORY
Preliminary work
Here are some simple preliminary work which should be finished before the laboratory class. You
should be able to show your results to a demonstrator upon request.
• To design an FIR filter and check the amplitude response, you can use the Matlab functions:
fir1 and freqz. Here is an example.
help fir1
h = fir1(12,0.3);
H = abs(freqz(h,1,128));
semilogy(H)
What is the order of the FIR filter? What is the cutoff frequency of filter? In Matlab the
frequency is normalized by π. Thus, if the frequency is 0.2π, then you should enter it in a par-
ticular filter design function as 0.2.
Design a bandpass filter with passband [0.2π, 0.5π]. You can vary the order of the filter to see
the effects. Check your design by plotting the amplitude response.
• To design an IIR filter (a Butterworth filter), you can use the Matlab function: butter. Here is an
example.
help butter
[B,A] = butter(2,0.3);%a second order Butterworth lowpass filter with cutoff freq. = 0.3π
H = abs(freqz(B,A,128));
semilogy(H)
Design a third order high pass Butterworth filter with cutoff frequency 0.8π and check its am-
plitude response.
Design a third order band stop Butterworth filter with cutoff frequency [0.5π, 0.8π] and check
its amplitude response.
• To perform the filtering operation, you can use the Matlab command filter. Here is am ex-
ample.
n = 1 : 1000;
s = cos(pi * n /100) + 0.5 * randn(1,1000);
plot(abs(fft(s))
w = 0.01;
[B,A] = butter(3,w);
y = filter(B,A,s);
figure
subplot(211);plot(s)
subplot(212);plot(y)
125
You should study the spectrum of the noisy corrupted cosine signal and determine a reason-
able cutoff frequency. You should refer to section 6 for an interpretation of the spectrum using
the fft.
1. Introduction
In this laboratory you will investigate the use of digital filters to recover signals that have been cor-
rupted by noise and 50 Hz sinusoidal mains interference.
4. Digital filters
There are two type of digital filters: finite impulse response (FIR) and infinite impulse response (IIR).
In the time domain, FIR and IIR filters are represented by difference equations:
N−1
FIR filter y(n) = ∑i=0 bi x(n − i)
N−1
IIR filter y(n) = ∑i=0 bi x(n − i) + ∑M−1
j=1 a j y(n − j)
where bi and a j are called the filter coefficients and N is the order of the FIR filter. The filter
coefficients are usually stored in two vectors in Matlab.
A filter is usually specified in the frequency domain. For example, a low pass filter is specified by
a cut-off frequency of ωc . Matlab provides a number of functions that you can used to design an FIR
or an IIR filter.
126
1
−0.5
−1
−1.5
0 500 1000 1500 2000 2500
−1
−2
0 500 1000 1500 2000 2500
1.5
0.5
−0.5
−1
−1.5
−2
0 200 400 600 800 1000 1200 1400 1600 1800 2000
127
Matlab function name Description
fir1 FIR filter design
butter IIR filter design, Butterworth response
cheby1 IIR filter design, Chebyshev I response
cheby2 IIR filter design, Chebyshev II response
ellip IIR filter design, elliptic response
Matlab also provides a function called filter to implement the filter. In this laboratory, you will
learn how to design FIR filters and Butterworth IIR filters to recover the ECG signal.
N OTE Due to a problem with Matlab, when you design an IIR bandstop filter with a very sharp
transition between pass band and stop band, the result may not be the same as what you specified.
You should try to design IIR filters with different orders and pick the one that is closest to your filter
specification. To do this, you may try the following:
5. Your task
Your task is to use both FIR and IIR filters to remove the high frequency noise and the 50 Hz interfer-
ence from the ECG signals.
• To design your filter, you must look at the spectrum of the good ECG signal and the noisy ECG
signal. For example17 , suppose the signal (with M data samples) is stored in a vector called s,
the spectrum can be obtained by using
S = f f t(s, N)
where N is the number of points between 0 to 2π. N is usually chosen to be a number of times
larger than M. You can plot the spectrum by using
plot(abs(S))
The horizontal axis represents the frequency, the vertical axis represents the magnitude. Note
|S| is a vector. The kth element of this vector is the magnitude of the spectrum at a frequency
ωk = 2πk/N. If the discrete signal is a result of sampling an analog signal, then this frequency18
corresponds to fk = k fs /N which is the frequency of the analog signal.
• You can use the Matlab function fft to calculate the spectrum and plot its amplitude. Based
on your interpretation of the plot, determine the filter specifications and design an FIR and an
IIR (Butterworth) filter to remove the noise.
• Repeat the above steps to design an FIR and an IIR (Butterworth) filter to remove the 50 Hz
interference.
17 This is only a rough estimation of the spectrum. In ELE41ASP, we will have detailed discussion on this topic.
18 ω
k = 2πfsfk =⇒ fk = k fs /N
128
• In both cases, compare the frequency response of these two filters and their order. Which one
requires less computational operations to implement ? You could also measure the time (use
Matlab function tic and toc) that is required for the filtering process. What is minimum order
for the FIR filter (IIR filter) to work reasonably well?
• In your lab book, you should clearly document your design method and justify the filter spec-
ifications. You should include relevant plots to support your justifications and to show your
results.
129
Instructor Verification
Name
Student Number
Your laboratory work is divided into two parts. In each part, your work must be marked by the
demonstrator. The mark is from 1 (poor) to 5 (excellent).
130
C Sampling Frequency, Quantization Noise and Digital Filters
LA TROBE UNIVERSITY
ELE31DSP LABORATORY
1. Introduction
The sampling frequency and the quantization levels are two important issues in digital processing of
analog signals. The purpose of this laboratory is to investigate these issues. A further purpose is to
give you hands-on experience of using a digital signal processor.
The TMS320c50 DSP starter Kit (DSK) is used in the laboratory. The DSK has a fix point proces-
sor (c50), the A/D and D/A converters and other parts such as RAM, ROM and the RS232 port that
is used to communicate between the DSK and the host PC. The DSK also has an analog input and an
analog output. It is powered by 9v AC. A detailed description of the DSK can be found in its User’s
Guide.
An analog signal is converted to digital form through sampling and quantization. The digital signal
is processed by the processor according to the DSP program. The processed signal is then converted
into analog form.
2. Sampling
1. Connect the output of the signal generator to the input of the DSK.
2. In the DOS PROMPT, type OSCOPE to run the program which contains two parts. The DSK
part converts the input analog signal into digital and send it to the PC through the RS232. The
PC part is responsible for displaying the signal as well as responding to user commands such as
changing the time base of the display and the quantization level.
3. Set the frequency of the signal generator to 250 Hz and make sure that the PC scope has a time
base of 1 ms and a resolution of 8 bits. You should see on the PC an approximation of the same
signal that can be seen on the analog oscilloscope. The period of the sine wave should be 4
ms. The red lines indicate the samples received from the DSK’s ADC. A white line joins the
samples to give a rough approximation of the input signal.
4. You can determine the sampling frequency of the ADC by dividing the period of the sine wave
from the number of samples in one period. To count the samples, press PAUSE button on the
keyboard. This makes counting easier. Press ENTER to resume counting.
5. Increase the input frequency to 1 kHz. If the display looks cluttered, the time base of the PC
oscilloscope can be altered using the left and right cursor keys. The representation of the sine
wave is now much poorer since there are less samples to represent it. However, there is still
theoretically enough information to reconstruct the signal to its original form.
6. Turn the input frequency to 2.5 kHz. Draw the sampled sine wave. Is is still theoretically
possible to reconstruct the signal to its original form ?
7. Slowly increase the frequency from 2.5 kHz to 5 kHz. Explain what you observed.
8. Set the input frequency to 3.5 kHz. Measure the frequency of the signal appeared on the PC
screen and relate it to the sampling frequency and the frequency of the input signal.
131
9. Explain what happens when the input frequency is set at 10 kHz, 20 kHz, 30 kHz, etc.
3. Quantization
1. Set the signal generator 250 Hz and a 5 v peak-to-peak output. Set the time base to 1 ms/div.
You should see a since wave. Press the 1 key. This sets the quantization level to 1 bit. The sine
wave becomes a square wave. Is the frequency of the square wave the same as that of the sine
wave ?
2. Set the quantization level to 2 bits by pressing the 2 key. How many levels do we have to
represent the input signal ? Draw the waveform for future reference.
3. Continue increasing the quantization levels up to the maximum of 8 bits. Draw the wave forms
for each quantization levels.
4. Digital Filters
4.1 How to run a real time digital filter in the DSK
1. You need to work out the specification of the filter, then design the filter, convert the filter
coefficients to suitable representation.
3. The source file (file_name.asm) must be assembled to (file_name.dsk) by using the DOS com-
mand: dsk5a file_name.asm.
4. Note: the above three steps have been done. Two 85-tap FIR filter have been designed and
assembled. All filters have a sampling frequency of 10 kHz. The low pass and high pass filter
have a cut-off frequency of 2 kHz. They are: demo3_lp.dsk and demo3_hp.dsk.
2. Connect the signal generator output to one trace of the scope and the input of the DSK. Connect
the output of the DSK to another trace of the scope.
132
4.3 The low pass filter
1. Run the low pass filter. Observe both traces on the scope. Increase the frequency of the input
waveform slowly. Around 2 kHz, the output should begin to attenuate. The cut-off frequency is
at a point where the amplitude of the output waveform is about half that of the input waveform.
Change the frequency of the input signal from 50 Hz to 4.5 kHz, take amplitude readings of the
output signal at intervals of 250 Hz. Plot the frequency response of the filter.
133
20 Appendix-III Sample exam questions
1. Answer the following questions
1.1 Determine the convolution y(n) = x1 (n) ∗ x2 (n) ,where
x1 (n) = δ(n) + 2δ(n − 1) + δ(n − 2)
and
y(n) = x(3 − n)
(5 marks)
1.3 The output y(n) of a system is related with the input x(n) by the following equation
y(n) = ax(n) + b
where a and b are non-zero constants. Is this system an LTI system ?
(5 marks)
134
2.2 Draw a block diagram of a general system which uses digital signal processing to process
continuous time signals.
(5 marks)
2.3 The sequence, x(n) = cos( π7 n), −∞ < n < ∞ , was obtained by sampling an analog signal
xc (t) = cos(Ωt), −∞ < t < ∞ , at a sampling rate of 2000 samples/second. What are two possible
values of Ω that could have resulted in the same x(n) ?
(6 marks)
2.4 An analog signal whose band width is 8 kHz is processed by an analog low pass filter whose
cutoff frequency is 3 kHz. If this signal processing task is performed by a digital signal process-
ing system, determine the minimum sampling frequency and the corresponding cutoff frequency
of the digital low pass filter.
(5 marks)
3. Answer the following questions about the system whose system function is
1 + 0.8z−1
H(z) =
1 − 0.9z−1
3.1 Determine the poles and zeros of H(z). Is this filter a low pass filter or a high pass filter ?
Explain your answer in terms of the locations of the pole and zero.
(6 marks)
3.2 Determine the difference equation relating the input and output of this filter.
(2 marks)
3.3 Draw a direct form-I and a direct form-II implementation of this filter.
(6 marks)
3.4 Determine the impulse response of this filter. (Hint: the Z-transform of the signal an u(n), a <
1) is 1/(1 − az−1 ) )
(6 marks)
3.5 Determine the filter output y(n) for the input signal x(n) = δ(n) + δ(n − 1) .
(5 marks)
135
4.2 Determine the system function of the overall system and obtain a single difference equation
that relates y(n) with x(n) in the cascade system.
(7 marks)
4.3 Show that H1 (z) can be expressed as the following.Plot the poles and zeros of this system
function. Draw a direct form-II implementation of this system function.
1 − z−4
H1 (z) =
1 − z−1
(15 marks)
136