DFT
IDFT
IB Paper 6: Signal and Data Analysis
Handout 6: The Discrete Fourier Transform J Lasenby
Signal Processing Group, Engineering Department, Cambridge, UK
Lent 2009
1 / 25 DFT IDFT
Digital Sampling and the DTFT (revisited)
1.5
f(T)
f(2T) f(t)
0.5
f(3T)
0
T
0.5
2T
3T
4T
5T
6T
7T
8T
9T
f(4T)
1
1.5
Figure 1: Digital sampling of a continuous waveform
2 / 25
DFT
IDFT
Given the sampled values of some signal f (t ), i.e.
{f (), ...f (T ), f (0), f (+T ), f (2T ), ..., f (+)}
the discrete time Fourier transform (DTFT) shows how to determine the frequency content:
Fs ( ) =
n=
f (nT )ejnT
(1)
As in slide 14, handout 5. (See below for examples of DTFT of a cosine wave and DTFT of a double exponential).
3 / 25 DFT IDFT
f(t)=cos( t)
c
FT
F() =c =+c
DISCRETETIME SAMPLING f(nT)=cos(cnT)
Fs()=1/T
F(m0) F () s
DTFT
20 0
Figure 2: FT and DTFT of a cosine wave with frequency c
4 / 25
DFT
IDFT
f(t)=exp(|t|)
FT F()
DISCRETETIME SAMPLING
F ()=1/T
s
F(m0)
DTFT f(nT)=exp(|nT|)
Fs()
20 0 0
0 20
Figure 3: FT and DTFT of a double exponential
5 / 25 DFT IDFT
This is ne in theory, but in practice there are two reasons why you cant compute the DTFT of a signal:
We dont have access to all of the data points from to
+ (even if we did, the computing time would be innite).
Fs ( ) is dened over the continuous range of frequencies
from to +. Hence it is impossible to calculate and store Fs ( ) for all frequency values. The discrete Fourier transform (DFT) is a way to bypass these practical diculties:
6 / 25
DFT
IDFT
A nite set of N samples:
Suppose we have a nite number (N) of (evenly spaced) data points, say t = 0, T , 2T , 3T , ..., (N 1)T which we wish to transform to frequency space. We can write this set of samples of our original continuous signal as
N 1
fs (t ) =
n =0
N 1
f (t )(t nT )
n =0
f (nT )(t nT )
so that fs (t ) takes the function values at the N time steps 0 to (N 1)T and zero elsewhere. Now suppose we try to Fourier transform this function i.e establish the DTFT.
7 / 25 DFT IDFT
Fs ( ) =
N 1 n =0
N 1
f (t )(t nT )
ej t dt
=
giving
n =0
f (t )ej t (t nT )dt
N 1
Fs ( ) =
n =0
f (nT )ejnT
which is simply the DTFT with the innite limits replaced by nite ones. Provided we have enough of the original continuous signal within the time window 0, ..., N 1, the truncated DTFT will be similar to the full DTFT.
8 / 25
DFT
IDFT
However, what we would really like is an entirely discrete formulation i.e. given a nite set of sampled values we obtain an approximation to its FT in the form of a nite set of frequency values. The sensible way of achieving this would be to periodically extend our nite set of samples. We know that the FT of a periodic function takes discrete values
F ( ) =
n=
cn e
jn0 t
j t
dt =
n=
cn
ej ( n0 )t dt
= 2
n=
cn ( n0 )
and that the FT of a sampled signal is repeated every interval of the sampling frequency. We therefore know that the FT of the periodic extension of fs (t ) will also be a periodic function dened at discrete frequency values.
9 / 25 DFT IDFT
If we do repeat our set of samples at intervals along the time axis so that we have a periodic function, we can see from gure 4 that the period of this periodic function is T NT . Let us call this periodic function f s (t ).
Figure 4: Periodic repetition of the nite set of samples fs (t )
Being periodic, f s (t ) can be expanded as a Fourier series f s (t ) = where 1 ck = T
T 0
k =
ck ejk0 t 2 2 NT T
10 / 25
fs (t )ejk0 t dt
for
0 =
DFT
IDFT
We can explicitly evaluate the ck as follows 1 T 1 T 1 T 1 T
T 0
ck
= = = =
fs (t )ejk0 t dt
T N 1 0 N 1 n =0 0 N 1 n =0 n =0 T
f (t )(t nT )ejk0 t dt f (t )ejk0 t (t nT )dt
jk 0 nT
f (nT )e
1 = T
N 1 n =0
f (nT )ej2k N
(2)
Comparing this with our equation on slide 8, Fs ( ) = N=01 f (nT )ejnT we see that we can write: n T ck = Fs (k 0 )
11 / 25 DFT IDFT
But we saw in Handout 3 that D (n0 ) = Tcn was the function we chose for our Fourier Transform. Introducing standard notation, we abbreviate Fs (k 0 ) as Fk and f (nT ) as fn , so that we can write the discrete values of the spectrum as
N 1
Fk =
n =0
fn ej2k N
(3)
We know that the FT of a sampled signal repeats itself every interval of the sampling frequency therefore, the frequency values of interest to us in equation (3) will range over 0 to 0 = 2/T 2N/NT = N 0 .
12 / 25
DFT
IDFT
Since Fs (0 )[= Fs (N 0 )] will have the same value as Fs (0), i.e.
N 1 N 1
Fs (N 0 ) =
n =0
f (nT )e
j2n N N
n =0
f (nT ) = Fs (0)
we will only need to know values for k in the range from 0 to (N 1). Equation (3) is the DISCRETE FOURIER TRANSFORM or DFT of our original nite set of samples fs (t ). We note that it is really the FT of the periodic extension of the nite set, giving a FT which is itself discrete and periodic.
13 / 25 DFT IDFT
F0=Fs(0)
Fs()
F1=Fs(0/N) F2=Fs(20/N)
=0
=(N1)0/N
Figure 5: Sampling in frequency
14 / 25
DFT
IDFT
Comments:
This is now a quantity which any computer can in principle
evaluate for any observed signal.
Note that we can interpret component Fk as the frequency
content of the signal at frequency k0 /N or k 0 .
The DFT is periodic, i.e. Fk +N = Fk
For real signals Fk = Fk (Easy to see this from equation).
15 / 25 DFT IDFT
Inverse Discrete Fourier Transform
The grid of N frequency values chosen for the DFT is convenient in that the transform can be inverted from the N values of Fk . To derive the inverse DFT, rst multiply the forward DFT by ej2km/N and then sum over m = 0 to N 1:
N 1 m =0 N 1 N 1
Fm e
j2km/N
= =
m =0 n =0 N 1 N 1 n =0
fn
fn ej2m
k n N
(4) (5)
m =0
ej2m
k n N
16 / 25
DFT
IDFT
The inner summation over m is a Geometric Progression (GP), k n with factor = ej2 N . Hence we have:
N 1 m =0
j2m k N n
1 ej2 (k n) 1 ej2
k n N
0 N
if k = n if k = n
The second case above for k = n follows immediately because N m1 ej0 = N. =0 Equation (5) now becomes
N 1 m =0
Fm ej2km/N = Nfk
(6)
17 / 25 DFT IDFT
We therefore have an expression for the Inverse Discrete Fourier Transform (IDFT): 1 fk = N
N 1 n =0
Fn ej2kn/N
(7)
To summarise: the expressions for the DFT and the IDFT of a sampled signal fn are:
N 1
Fk
n =0
fn ej2 N , Fk ej2 N ,
nk
nk
0 k N 1
(8)
fn =
1 N
N 1 k =0
0 n N 1
(9)
18 / 25
DFT
IDFT
Other considerations
Fast algorithms - particularly elegant and fast methods exist
for computing the DFT, known generically as the Fast Fourier Transform, or FFT algorithms. The most well-known FFT algorithms are only used when N is a power of 2. However, other classes exist, such as for N a power of 4.
In our DFT derivation we periodically repeated the data in the
time domain and then took the FT of this sampled, periodic signal to produce another discrete, periodic signal.
19 / 25 DFT IDFT
The eects of truncating a data sequence (ie taking a nite
set of samples) and performing this periodic repetition might be to introduce some discontinuities. This will lead to high frequency components in the Fourier transform. One way of avoiding this is to apply a window to our data sequence. A variety of window shapes can be used which better preserve the spectral information of the original (untruncated) signal and this is a large area of study known as windowing or tapering. Because we know that multiplication in the time domain is equivalent to convolution in the frequency domain, we can quantify exactly what the eect on the spectrum is of applying this window function.
20 / 25
DFT
IDFT
Example:
Let us now give an example of calculating a DFT. Consider the four sample values
{fn } = {1, 2, 1, 0}
Figure 6: Sampling in frequency
21 / 25 DFT IDFT
We now want to calculate Fk for k = 0, 1, 2, 3. F0 = {fo ej2 (00)/4 + f1 ej2 (10)/4 + f2 ej2 (20)/4
+ f3 ej2 (30)/4 } = {1 + 2 + 1 + 0} = 4
F1 = {fo ej2 (01)/4 + f1 ej2 (11)/4 + f2 ej2 (21)/4
+ f3 ej2 (31)/4 } = {1 + 2ej /2 + 1ej + 0} = 2j
F2 = {fo ej2 (02)/4 + f1 ej2 (12)/4 + f2 ej2 (22)/4
+ f3 ej2 (32)/4 } = {1 + 2ej + 1ej2 + 0}= 2 2 = 0
F3 = {fo ej2 (03)/4 + f1 ej2 (13)/4 + f2 ej2 (23)/4
+ f3 ej2 (33)/4 } = {1 + 2ej3/2 + 1ej3 + 0}= 2j
22 / 25
DFT
IDFT
Therefore, the DFT is given by
{Fk } = {4, 2j, 0, 2j }
Check that Fk = FN k .
23 / 25 DFT IDFT
The Spectrogram
Now that we have the concept of a Fourier Transform of a nite set of samples, we can understand the concept of the spectrogram. Figure 7 shows how we can form the DFT of a small section of signal at a given time and display the resulting frequency content as a function of time.
Figure 7: Spectrogram of section of ute music
24 / 25
DFT
IDFT
A continuously decreasing tone?
Figure 8: Spectrogram of Shepard Tone
A Shepard tone, named after Roger Shepard, is a sound consisting of a superposition of sine waves separated by octaves. This creates the auditory illusion of a tone that continually ascends or descends in pitch, yet which ultimately seems to get no higher or lower. J. Lasenby (2009)
25 / 25