Lab 4
Lab 4
4.1 Introduction
This laboratory will introduce the Discrete Fourier Transform (DFT) and the associated sampling
and windowing effects.
In previous laboratories, we have used the Discrete-Time Fourier Transform (DTFT)
extensively for analyzing signals and linear time-invariant systems.
∞
(DTFT) 𝑋(𝑒 𝑗𝜔 ) = ∑ 𝑥[𝑛] 𝑒 −𝑗𝜔𝑛
𝑛=−∞
(4.1)
𝜋
1
(inverse DTFT) 𝑥[𝑛] = ∫ 𝑋(𝑒 𝑗𝜔 )𝑒 𝑗𝜔𝑛 𝑑𝜔.
2𝜋 −𝜋
(4.2)
While the DTFT is very useful analytically, it usually cannot be exactly evaluated on a computer
because (4.1) requires an infinite sum and (4.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.
𝑁−1
(DFT) 𝑋𝑁 [𝑘] = ∑ 𝑥[𝑛]𝑒 −𝑗2𝜋𝑘𝑛/𝑁
𝑛=0
(4.3)
1 𝑁−1
(inverse DFT) 𝑥[𝑛] = ∑ 𝑋𝑁 [𝑘]𝑒 𝑗2𝜋𝑘𝑛/𝑁
𝑁 𝑘=0
(4.4)
Here 𝑋𝑁 [𝑘] is an 𝑁 point DFT of 𝑥 [𝑛]. Note that 𝑋𝑁 [𝑘] is a function of a discrete integer 𝑘,
where 𝑘 ranges from 0 to 𝑁 − 1.
In the following sections, we will study the derivation of the DFT from the DTFT, and several
DFT implementations.
𝑊(𝑒 𝑗𝜔 ). Hence the true DTFT, 𝑋(𝑒 𝑗𝜔 ), is smoothed via convolution with 𝑊(𝑒 𝑗𝜔 ) to produce
𝑁−1 𝑁−1
𝑗𝜔 −𝑗𝜔𝑛
𝑋tr (𝑒 )︱ 2𝜋𝑘 =∑ 𝑥[𝑛]𝑒 ︱ 2𝜋𝑘 =∑ 𝑥[𝑛]𝑒 −𝑗2𝜋𝑘𝑛/𝑁 = 𝑋𝑁 [𝑘]
𝜔= 𝑛=0 𝜔= 𝑛=0
𝑁 𝑁
(4.12)
In short, the DFT values result from sampling the DTFT of the truncated signal.
𝑋𝑁 [𝑘] = 𝑋tr (𝑒 𝑗2𝜋𝑘/𝑁 )
(4.13)
INLAB REPORT:
1. Submit the plot of the phase and magnitude of 𝑊(𝑒 𝑗𝜔 ).
2. Submit the analytical expression for 𝑋(𝑒 𝑗𝜔 ).
3. Submit the magnitude plot of 𝑋tr (𝑒 𝑗𝜔 ).
4. Describe the difference between | 𝑋tr (𝑒 𝑗𝜔 )| and |𝑋(𝑒 𝑗𝜔 )| . What is the reason for this
difference?
5. Comment on the effects of using a different length of the window 𝑤(𝑛).
j=sqrt(-1) . If you use 𝑗 = √−1, remember not to use j as an index in your for-loop.
Test your routine DFTsum by computing 𝑋𝑁 [𝑘] for each of the following cases:
INLAB REPORT:
1. Submit a listing of your code for DFTsum.
2. Submit the magnitude plots.
3. Submit the corresponding analytical expressions.
Write a second Matlab function for computing the inverse DFT of (4.4). 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.
INLAB REPORT:
1. Submit the listing of your code for IDFTsum.
2. Submit the four time-domain IDFT plots.
𝑿𝑘 = ∑ 𝐀 𝑘𝑛 𝒙𝑛
𝑛=1
(4.15)
th th
where 𝐀 𝑘𝑛 is the matrix element in the 𝑘 row and 𝑛 column of A . By comparing (4.3) and
(4.15) we see that for the DFT,
𝐀 𝑘𝑛 = 𝑒 −𝑗2𝜋(𝑘−1)(𝑛−1)/𝑁
(4.16)
′
The −1 s are in the exponent because Matlab indices start at 1, not 0. For this section, we need to:
·Write a Matlab function A = DFTmatrix(N) that returns the N x N DFT matrix A.
NOTE: 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.
·Use the matrix 𝐀 to compute the DFT of the following signals. Confirm that the results are the
INLAB REPORT:
1. Print out the matrix 𝐀 for 𝑁 = 5.
2. Hand in the three magnitude plots of the DFT's.
3. How many multiplies are required to compute an 𝑁 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.
𝒙 = 𝐁𝑿
(4.18)
For this section,
1. Write an analytical expression for the elements of the inverse DFT matrix 𝐁, using the form
of (4.16).
2. Write a Matlab function B = IDFTmatrix(N) that returns the N x N inverse DFT matrix 𝐁.
3. Compute the matrices 𝐀 and 𝐁 for 𝑁 = 5. Then compute the matrix product 𝐂 = 𝐁𝐀.
INLAB REPORT:
1. Hand in your analytical expression for the elements of 𝐁.
2. Print out the matrix B for 𝑁 = 5.
3. Print out the elements of 𝐂 = 𝐁𝐀. What form does 𝐂 have? Why does it have this form?
INLAB REPORT: Report the CPU time required for each of the two implementations. Which
method is faster? Which method requires less storage?