<< Chapter < Page | Chapter >> Page > |
for in [link] , we find that
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 truncated with a window of size .
[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 [link] . Use the syntax
X = DFTsum(x)
where x
isan
point vector containing the values
and X
is the corresponding DFT.Your routine should implement the DFT exactly as specified
by
[link] using
for-loops
for
and
, and compute
the exponentials as they appear.Note:
In Matlab, "j" may be computed with the command
j=sqrt(-1)
. If you use
, remember not to use
j as an index in your
for-loop
.
Test your routine
DFTsum
by computing
for each of the following cases:
Plot the magnitude of each of the DFT's. In addition, derive simple closed-form analytical expressions for theDFT (not the DTFT!) of each signal.
DFTsum
.Write a second Matlab function for computing the inverse DFT of [link] . Use the syntax
x = IDFTsum(X)
where
X
is the
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.
IDFTsum
.The DFT of [link] can be implemented as a matrix-vector product. To see this, consider the equation
where is an matrix, and both and are column vectors. This matrix product is equivalent to the summation
where is the matrix element in the row and column of A .By comparing [link] and [link] we see that for the DFT,
The 's are in the exponent because Matlab indices start at 1, not 0. For this section, we need to:
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?Notification Switch
Would you like to follow the 'Purdue digital signal processing labs (ece 438)' conversation and receive update notifications?