ECE438 - Laboratory 6: Discrete Fourier Transform and Fast Fourier Transform Algorithms (Week 1)
ECE438 - Laboratory 6: Discrete Fourier Transform and Fast Fourier Transform Algorithms (Week 1)
ECE438 - Laboratory 6: Discrete Fourier Transform and Fast Fourier Transform Algorithms (Week 1)
ECE438 - Laboratory 6:
Discrete Fourier Transform and Fast Fourier
Transform Algorithms (Week 1)
October 6, 2010
1 Introduction
This is the first week of a two week laboratory that covers the Discrete Fourier Transform
(DFT) and Fast Fourier Transform (FFT) methods. The first week will introduce the DFT
and associated sampling and windowing effects, while the second week will continue the
discussion of the DFT and introduce the FFT.
In previous laboratories, we have used the Discrete-Time Fourier Transform (DTFT)
extensively for analyzing signals and linear time-invariant systems.
∞
jω
X
(DTFT) X(e ) = x(n)e−jωn (1)
n=−∞
1 Zπ
(inverse DTFT) x(n) = X(ejω )ejωn dω. (2)
2π −π
While the DTFT is very useful analytically, it usually cannot be exactly evaluated on a com-
puter because equation (1) requires an infinite sum and equation (2) requires the evaluation
of an integral.
The discrete Fourier transform (DFT) is a sampled version of the DTFT, hence it is
better suited for numerical evaluation on computers.
N
X −1
(DFT) XN (k) = x(n)e−j2πkn/N (3)
n=0
1 NX
−1
(inverse DFT) x(n) = XN (k)ej2πkn/N (4)
N k=0
Here XN (k) is an N point DFT of x(n). Note that XN (k) is a function of a discrete integer
k, where k ranges from 0 to N − 1.
Questions or comments concerning this laboratory should be directed to Prof. Charles A. Bouman,
School of Electrical and Computer Engineering, Purdue University, West Lafayette IN 47907; (765) 494-
0340; bouman@ecn.purdue.edu
Purdue University: ECE438 - Digital Signal Processing with Applications 2
In the following sections, we will study the derivation of the DFT from the DTFT, and
several DFT implementations. The fastest and most important implementation is known as
the fast Fourier transform (FFT). The FFT algorithm is one of the cornerstones of signal
processing.
N
X −1
= x(n)e−jωn . (8)
n=0
We would like to compute X(ejω ), but as with filter design, the truncation window
distorts the desired frequency characteristics; X(ejω ) and Xtr (ejω ) are generally not equal.
To understand the relation between these two DTFT’s, we need to convolve in the frequency
domain (as we did in designing filters with the truncation technique):
1 Zπ
Xtr (ejω ) = X(ejσ )W (ej(ω−σ) )dσ (9)
2π −π
where W (ejω ) is the DTFT of w(n). Equation (9) is the periodic convolution of X(ejω ) and
W (ejω ). Hence the true DTFT, X(ejω ), is smoothed via convolution with W (ejω ) to produce
the truncated DTFT, Xtr (ejω ).
We can calculate W (ejω ):
∞
W (ejω ) =
X
w(n)e−jωn
n=−∞
N
X −1
= e−jωn
n=0
(
1−e−jωN
, for ω 6= 0, ±2π, . . .
= 1−e−jω (10)
N, for ω = 0, ±2π, . . .
Purdue University: ECE438 - Digital Signal Processing with Applications 3
N
X −1
= x(n)e−j2πkn/N
n=0
= XN (k) .
In short, the DFT values result from sampling the DTFT of the truncated signal.
We willnext investigate the effect of windowing when computing the DFT of the signal
x(n) = cos π4 n truncated with a window of size N = 20.
1. In the same figure, plot the phase and magnitude of W (ejω ), using equations (10) and
(11).
3. Truncate the signal x(n) using a window of size N = 20 and then use DTFT.m to
compute Xtr (ejω ). Make sure that the plot contains a least 512 points. Hint: Use the
command [X,w] = DTFT(x,512).
1 12
0.9
10
0.8
0.7
8
0.6
0.5 6
0.4
4
0.3
0.2
2
0.1
0 0
0 5 10 15 20 −4 −2 0 2 4
n ω
Figure 1: The plot of a Hamming window (left) and its DTFT (right).
Purdue University: ECE438 - Digital Signal Processing with Applications 5
INLAB REPORT:
4. Describe the difference between |Xtr (ejω )| and |X(ejω )|. What is the reason for this
difference?
5. Comment on the effects of using a different window for w(n). For example, what would
you expect your plots to look like if you had used a Hamming window in place of the
truncation (rectangular) window? (See Fig. 1 for a plot of a Hamming window of
length 20 and its DTFT.)
Plot the magnitude of each of the DFT’s. In addition, derive simple closed-form analytical
expressions for the DFT (not the DTFT!) of each signal.
Purdue University: ECE438 - Digital Signal Processing with Applications 6
INLAB REPORT:
Write a second Matlab function for computing the inverse DFT of (4). Use the syntax
x = IDFTsum(X)
where X is the N point vector containing the DFT and x is the corresponding time-domain
signal. Use IDFTsum to invert each of the DFT’s computed in the previous problem. Plot
the magnitudes of the inverted DFT’s, and verify that those time-domain signals match
the original ones. Use abs(x) to eliminate any imaginary parts which roundoff error may
produce.
INLAB REPORT:
where Akn is the matrix element in the k th row and nth column of A. By comparing equations
(3) and (15) we see that for the DFT,
The −1’s are in the exponent because Matlab indices start at 1, not 0. For this section,
we need to:
2. Use the matrix A to compute the DFT of the following signals1 . Confirm that the
results are the same as in section 3.1.
INLAB REPORT:
3. How many multiplies are required to compute an N point DFT using the matrix
method? (Consider a multiply as the multiplication of either complex or real numbers.)
As with the DFT, the inverse DFT may also be represented as a matrix-vector product.
x = BX
1. Write an analytical expression for the elements of the inverse DFT matrix B, using
the form of equation (16).
3. Compute the matrices A and B for N = 5. Then compute the matrix product C =
BA.
INLAB REPORT:
3. Print out the elements of C = BA. What form does C have? Why does it have this
form?
1
Remember that the symbol ∗ is used for matrix multiplication in Matlab, and that .′ performs a simple
transpose on a vector or matrix. An apostrophe without the period is a conjugate transpose.
Purdue University: ECE438 - Digital Signal Processing with Applications 8
INLAB REPORT:
Report the cputime required for each of the two implementations. Which method is faster?
Which method requires less storage?