ELEC 342
Chapter 12
Chapter 12 Discrete Fourier Transform (DFT)
DTFT vs DFT
In chapter 11 we learned about the Discrete time Fourier Transform (DTFT). This
is also sometimes called the Fourier transform for discrete time signals. The DTFT
is a paper and pencil tool. It is not well suited for numerical calculations on a
digital computer.
Recall the DTFT analysis equation.
∞
𝑋𝑋(𝛺𝛺) = � 𝑥𝑥 [𝑘𝑘 ]𝑒𝑒 −𝑗𝑗𝑗𝑗𝑗𝑗
𝑘𝑘=−∞
Two things that will give a computer difficulties are
a) The infinite summation
b) That Ω is a continuous quantity.
To address these for the computer there are two fixes needed
a) Truncate the infinite summation so that it is from 0 to M-1.
b) Don’t calculate 𝑋𝑋(𝛺𝛺) for all values of 𝛺𝛺. Calculate it only for some values.
I.e. sample 𝑋𝑋(𝛺𝛺).
With these two ideas we have
𝑀𝑀−1
For i=0,…,R-1.
What should R be?
𝑋𝑋(Ω𝑖𝑖 ) = � 𝑥𝑥 [𝑘𝑘 ]𝑒𝑒 −𝑗𝑗Ω𝑖𝑖 𝑘𝑘
𝑘𝑘=0
In fact, what we have is R linear equations. We can write them as a matrix
equation.
𝑥𝑥[0]
𝑋𝑋(Ω0 )
𝑒𝑒 −𝑗𝑗𝛺𝛺0(1) … 𝑒𝑒 −𝑗𝑗𝛺𝛺0(𝑀𝑀−1)
𝑒𝑒 −𝑗𝑗Ω0(0)
−𝑗𝑗𝛺𝛺
(0)
−𝑗𝑗𝛺𝛺
(1)
−𝑗𝑗𝛺𝛺
(𝑀𝑀−1)
1
𝑋𝑋(𝛺𝛺1 )
𝑥𝑥[1]
𝑒𝑒 1
… 𝑒𝑒 1
��
� = � 𝑒𝑒
�
�
⋮
⋮
⋮
⋮
⋱
⋮
𝑋𝑋(𝛺𝛺𝑅𝑅−1 )
𝑒𝑒 −𝑗𝑗𝛺𝛺𝑅𝑅−1(0) 𝑒𝑒 −𝑗𝑗𝛺𝛺𝑅𝑅−1 (1) … 𝑒𝑒 −𝑗𝑗𝛺𝛺𝑅𝑅−1(𝑀𝑀−1) 𝑥𝑥[𝑀𝑀 − 1]
As you can see the dimensions of these vectors/matrices are Rx1, RxM and Mx1
respectively.
1
ELEC 342
Chapter 12
2
One important property that we would like transforms to have is that they are
invertible. Can you tell me what R would need to be for this new transform that
we are building to be invertible?
The answer is that 𝑅𝑅 ≥ 𝑀𝑀. The convention is to choose R=M.
Once we decide on the number of frequencies we will sample we must decide
how to sample them. As we did for sampling in the time domain (ch 9) we will
choose to uniformly sample in the frequency domain. Also, because all DTFT
spectrums are periodic in 2𝜋𝜋 we will uniformly sample over the interval [0,2𝜋𝜋).
Thus, we choose,
2𝜋𝜋𝜋𝜋
Ω𝑖𝑖 =
, 𝑖𝑖 = 0,1, … 𝑀𝑀 − 1
𝑀𝑀
This leads us to a new transform that can be calculated on a computer. It is called
the Discrete Fourier Transform (DFT). Its analysis equation is
𝑀𝑀−1
2𝜋𝜋𝜋𝜋
𝑋𝑋[𝑟𝑟] = � 𝑥𝑥[𝑘𝑘]𝑒𝑒 −𝑗𝑗 𝑀𝑀 𝑘𝑘 ,
𝑘𝑘=0
𝑟𝑟 = 0,1, … , 𝑀𝑀 − 1
The inverse DRT can be calculated by taking the inverse of the large matrix above.
This gives us
𝑀𝑀−1
2𝜋𝜋𝜋𝜋
1
� 𝑋𝑋[𝑟𝑟]𝑒𝑒 𝑗𝑗 𝑀𝑀 𝑘𝑘 , 𝑘𝑘 = 0,1, … , 𝑀𝑀 − 1
𝑥𝑥 [𝑘𝑘 ] =
𝑀𝑀
𝑟𝑟=0
Now while the DFT equations can be calculated on a computer, what relationship
do they have to the DTFT. The answer to that is
𝑋𝑋[𝑟𝑟] ≈ 𝑋𝑋(Ω)]Ω=2𝜋𝜋𝜋𝜋
𝑀𝑀
Now why is the relationship here only approximate?
The answer is the truncation of the infinite summation.
To understand the effects of this truncation, consider x1[k] as the
original signal, that we can take a DTFT on and get 𝑋𝑋1 (𝛺𝛺).
Then consider x2[k] that is what the DFT will be on. We can get x2[k] from x1[k] by
𝑥𝑥2 [𝑘𝑘 ] = 𝑥𝑥1 [𝑘𝑘 ]𝑤𝑤[𝑘𝑘]
Where w[k] is a window signal. It is defined as
1 𝑘𝑘 = 0,1, … 𝑁𝑁 − 1
𝑤𝑤[𝑘𝑘 ] = �
0
𝑜𝑜𝑜𝑜ℎ𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒
Note that this signal is called the rectangular window.
ELEC 342
Chapter 12
3
Note that taking the DFT of x1[k] is exactly the same thing as taking the DFT of
x2[k].
The effect of the multiplication by the rectangular window is obvious in the time
domain. What is its effect in the frequency domain?
Recall that multiplication in the time domain is convolution in the frequency
domain.
Thus,
𝑋𝑋2 (Ω) =
1
� 𝑋𝑋1 (𝜃𝜃)𝑊𝑊 (Ω − 𝜃𝜃)𝑑𝑑𝑑𝑑
2𝜋𝜋
〈2𝜋𝜋〉
For this we need to know the spectrum of w[k]. That is
𝑁𝑁Ω
sin
2 𝑒𝑒 −𝑗𝑗𝑁𝑁−1
2
𝑊𝑊 (Ω) =
Ω
sin
2
Plotting the magnitude spectrum we have:
Main
|W(
)|
Lobe
Side
Side
Lobes
Lobes
2
Now in doing the convolution
/M
ELEC 342
Chapter 12
𝑋𝑋2 (Ω) =
4
1
� 𝑋𝑋1 (𝜃𝜃)𝑊𝑊 (Ω − 𝜃𝜃)𝑑𝑑𝑑𝑑
2𝜋𝜋
〈2𝜋𝜋〉
We first flip 𝑊𝑊(Ω) which has no impact on the magnitude response since it is
even. To calculate 𝑋𝑋2 (Ω) at Ω = 0 we have the picture below. Here 𝑋𝑋1 (Ω) is a
perfect LPF.
At
=0
W(
-
)
X ( )
1
To get the value of 𝑋𝑋2 (Ω) for Ω = 0 we multiply the two curves and then
integrate. Note that the sidelobes outside the box get wiped out.
Now as Ω increases, some of the side lobes to the right “fall off” the box and are
wiped out, while others on the left “fall on” the box and are used. This causes
small variations in 𝑋𝑋2 (Ω)
ELEC 342
Chapter 12
5
growing. Mainlobe not yet at edge of rectangle
W(
-
)
X (
1
)
Eventually Ω grows so much that the main lobe starts to fall off the rectangle.
at
c the edge of the rectangle
W(
-
)
X ( )
1
ELEC 342
Chapter 12
6
Finally Ω grows to the point where the main lobe is completely off the rectangle
and we are back to side lobes falling off and on the rectangle.
large enough that main lobe is off the rectangle
W(
-
)
X ( )
1
The spectrum of 𝑋𝑋2 (Ω) looks something like
The variations are called “ripples”
Side lobes
Falling on/off
X2(Ω)
Main lobe
Falling off
Ω
ELEC 342
Chapter 12
7
Comparing 𝑋𝑋1 (Ω) to 𝑋𝑋2 (Ω) there are 3 differences
1. The ripples both when 𝑋𝑋1 (Ω) was 1 and when it was 0. These ripples are
caused by the side lobes falling on and off the rectangle during
perturbation.
2. There is spectral content in 𝑋𝑋2 (Ω) far away from where there was any
spectral content in 𝑋𝑋1 (Ω). This is again caused by the sidelobes which go
out very far. This is called spectral leakage.
3. In 𝑋𝑋1 (Ω) there was a very sharp transition from where it was 1 to where it
was 0. But in 𝑋𝑋2 (Ω) there is a more gradual transition from the where it is
high to where it is low. This is caused by the main lobe having a finite width.
This is going to make anything sharp in 𝑋𝑋1 (Ω) be smeared or blurred when
we get 𝑋𝑋2 (Ω) i.e. when we take the DFT.
Can we alleviate these effects?
a. We can make the main lobe get thinner by increasing M, the length of the
DFT. Increasing M has its own difficulties i) it means more work to do the
DFT. ii) we may not have enough samples of x1[k] to make a longer signal.
We have some work arounds for this.
b. The height of the sidelobes are affected by the shape of the window. We
have only talked about rectangular windows so far. Later in the filter design
chapter 15 we will talk about different window shapes.
Extending a Signal – zero padding
Given a real-life time signal the action of trying to estimate its spectrum is an area
called Spectral Estimation. This is a very big field, and deals with many situations,
both impediments like noise, or uncertainty, and extra bits of information one
might have.
In this section one simple technique from spectral estimation is introduced,
namely zero padding. It is best illustrated with an example.
Say we have a signal x[k] for k=0,1,…,127.
We take the 128 point DFT and get X(r). As mentioned before
𝑋𝑋(𝑟𝑟) ≈ 𝑋𝑋(𝛺𝛺)]Ω=2𝜋𝜋𝜋𝜋
128
ELEC 342
Chapter 12
8
Thus we get an approximate version of the spectrum at r=0 or X(0) or 𝑋𝑋(𝛺𝛺)]Ω=0
and then the next point at r=1 or X(1) gives us an approximate version of the
spectrum at 𝑋𝑋(𝛺𝛺)]Ω= 2𝜋𝜋 =0.0491 . and so on. But what if one wants to know the
128
spectrum between those points. I.e. what if one wants more resolution?
The answer is to increase M beyond 128. If we have more of the signal x[k] that is
easy. But what if we only have 128 samples of x[k] and we can’t get more.
One solution is zero padding. If we want to have a 512 point DFT weform x1[k]
𝑥𝑥1 [𝑘𝑘 ] = �
𝑥𝑥[𝑘𝑘]
0
𝑘𝑘 = 0,1, … ,127
𝑘𝑘 = 128,129, … ,511
Then taking the 512 point DFT of x1[k] we have
𝑋𝑋1 (𝑟𝑟) ≈ 𝑋𝑋(𝛺𝛺)]Ω=2𝜋𝜋𝜋𝜋
512
This gives me more resolution, for some more work.
There are other more complex ways of extending a signal which are beyond the
scope of 342.
FFT vs DFT
In matlab the command you use to do the DFT is ‘fft’. FFT stands for Fast Fourier
Transform. The output of the FFT is the same as the DFT (except for round off
issues) provided, of course, they have the same input. But the FFT as the name
suggests, is faster.
First, lets examine the DFT
𝑀𝑀−1
2𝜋𝜋𝜋𝜋
𝑋𝑋[𝑟𝑟] = � 𝑥𝑥[𝑘𝑘]𝑒𝑒 −𝑗𝑗 𝑀𝑀 𝑘𝑘 ,
𝑘𝑘=0
𝑟𝑟 = 0,1, … , 𝑀𝑀 − 1
To do this equation for one value of r, there are M multiplies and M-1 adds. These
are complex mults and adds.
To do the entire DFT this equation must be evaluated M times (one for each r).
That means overall there are order M2 mults and order M2 adds. We say the
complexity of the DFT is O(M2).
ELEC 342
Chapter 12
9
In the 1960’s Cooley and Tukey came up with a way to calculate the DFT using
only 𝑂𝑂(𝑀𝑀 log 2 𝑀𝑀) operations. Their method only worked if M was a power of 2.
I.e. M=2C where C is a positive integer.
Being able to do the DFT in 𝑂𝑂(𝑀𝑀 log 2 𝑀𝑀) operations is called a Fast Fourier
Transform (FFT). As mentioned above there is no difference in the output of the
DFT and the FFT (except for round off differences), the FFT is just faster.
Later in the 1960’s and 1970’s methods were found to do the DFT for any length
of M (not just powers of 2) in only 𝑂𝑂(𝑀𝑀 log 2 𝑀𝑀). i.e. FFT’s exist for any length M.
However, the methods for FFT are quite different for different values of M, where
as the Cooley Tukey method can re-use code as one goes to different powers of 2.
MATLAB doesn’t have a command DFT. It always uses the command FFT to
calculate the DFT.
MATLAB does not want to program all the ways of doing an FFT for any value M.
They’ve decided to only do a fast implementation for powers of 2 (i.e. they
decided to only implement the original Cooley Tukey FFT). If you ask for an FFT for
M not a power of 2, they will just calculate the (slow – O(M2)) DFT.
Thus we almost always contrive to do use power of 2 length DFT/FFT’s when we
use MATLAB.