Note: Your browser may not currently support MathML. See our browser support page for additional details. You can always view the correct math in the PDF version.
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
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.
While the DTFT is very useful analytically, it usually cannot be exactly evaluated on a computer 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.
Here
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.
The DTFT usually cannot be computed exactly because
the sum in Equation 1 is infinite.
However, the DTFT may be approximately computed
by truncating the sum to a finite window.
Let
Then we may define a truncated signal to be
The DTFT of
We would like to compute
where
We can calculate
For
Notice that the magnitude of this function
is similar to
Equation 7 contains a summation over a finite number of terms.
However, we can only evaluate
Equation 7 for a finite set of frequencies,
for
In short, the DFT values result from sampling the DTFT of the truncated signal.
Download DTFT.m for the following section.
We will next investigate the effect of windowing when computing
the DFT of the signal
[X,w] = DTFT(x,512)
.![]() |
We will now develop our own DFT functions to help our understanding of how the DFT comes from the DTFT. Write your own Matlab function to implement the DFT of equation Equation 3. Use the syntax
X = DFTsum(x)
where x
is
an for-loops for j=sqrt(-1)
. If you use for-loop.
Test your routine DFTsum by computing
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.
DFTsum.
Write a second Matlab function for computing the inverse DFT of Equation 4. Use the syntax
x = IDFTsum(X)
where X
is the 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.
IDFTsum.
The DFT of Equation 3 can be implemented as a matrix-vector product. To see this, consider the equation
where
where
The
A = DFTmatrix(N)
that returns
the NxN DFT matrix A.
As with the DFT, the inverse DFT may also be represented as a matrix-vector product.
For this section,
B = IDFTmatrix(N)
that returns
the NxN inverse DFT matrix B.
Click here for help on the cputime function.
Although the operations performed by DFTsum
are mathematically identical to a matrix product,
the computation times for these two DFT's in Matlab are quite different.
(This is despite the fact that the computational complexity of two
procedures is of the same order!)
This exercise will underscore why you should try to avoid using
for loops in Matlab, and wherever possible, try to formulate your
computations using matrix/vector products.
To see this, do the following:
X = DFTsum(x)
with
a matrix implementation X = A*x
by using the
cputime function before and after the program execution.
Do not include the computation of A
in your timing calculations.
cputime required for each of the two implementations.
Which method is faster? Which method requires less storage?