Uploaded by Jesper Petersen

# DFTeksempel

```Lecture 7 - The Discrete Fourier
Transform
7.1 The DFT
The Discrete Fourier Transform (DFT) is the equivalent of the continuous Fourier
Transform for signals known only at instants separated by sample times (i.e.
a finite sequence of data).
Let be the continuous signal which is the source of the data. Let samples
.
be denoted The Fourier Transform of the original signal, , would be
&quot;!\$#%'&amp;
(*)
+/102,3 ,
.
+ )
We could regard each sample as an impulse having area 45 . Then, since the
integrand exists only at the sample points:
6!\$#%7&amp;
&amp;
(98;: =+ &lt;&gt;;?
+/A02B3 @
8;:
CD- +/EGF D- +/10H?IF F D- +/10J?IF H- +/A0 +=&lt;&gt;;?
ie.
&quot;!\$#%K&amp;
: L +=&lt;
JNMOE
D- +/10J?
We could in principle evaluate this for any # , but with only data points to start
with, only final outputs will be significant.
You may remember that the continuous Fourier transform could be evaluated
QP
over a finite interval (usually the fundamental period @ ) rather than from
to
82
F P
if the waveform was periodic. Similarly, since there are only a finite number
of input data points, the DFT treats the data as if it were periodic (i.e. to
S
H is the same as R to H .)
Hence the sequence shown below in Fig. 7.1(a) is considered to be one period of
the periodic sequence in plot (b).
(a)
1
0.8
0.6
0.4
0.2
0
0
1
2
3
4
5
6
7
8
9
10
11
(b)
1
0.8
0.6
0.4
0.2
0
0
5
10
15
&amp;TU
Figure 7.1: (a) Sequence of
20
25
30
samples. (b) implicit periodicity in DFT.
Since the operation treats the data as if it were periodic, we evaluate the
&lt;
DFT
VXW equation for the fundamental frequency (one cycle per sequence, : ? Hz,
: ? rad/sec.) and its harmonics (not forgetting the d.c. component (or average) at
#Y&amp;Z ).
i.e. set #Y&amp;Z[
H\
\
S]
^
\
]`_
\
S]
or, in general
_
&amp;
: L +=&lt;
JaMOE
ec f J
D- + /\$bdg
83
Z
&amp; ih
_
S
H
U
_
is the Discrete Fourier Transform of the sequence .
We may write this equation in matrix form as:
jkk
C
kk
kl
..
.
S
where p
mnn
jkk
n
&amp; lk nn
o
kk kk p V
p
pvq
p u
p
..
.
V
p q
r
p u
r
p w
r
pts
Tp
Tp
Tp
V
p : +=&lt; p : + p : + q V
&amp;Zxy[z{ !\}| and p &amp;Zp : etc. ~
&amp; .
m nn
+=&lt; nn
: + V nn
: + q n
o
p
:
jkk
mnn
C
kk
kl
..
.
nn
n
o
DFT – example
Let the continuous signal be
 @ 
F 
K&amp;   F  \$UH\   O \ dc
2Hz
1Hz
10
8
6
4
2
0
−2
−4
0
1
2
3
4
5
6
7
8
9
10
Figure 7.2: Example signal for DFT.
Let us sample at 4 times per second (ie.
values of the discrete samples are given by:
W  @ F
&amp;t F \$5 V \$\{
84

= 4Hz) from &amp;r to &amp;
by putting &amp;r&amp;
J
s
s
q
. The
i.e.
&amp;t , &amp; , &amp;t ,  &amp;Z
Therefore
jkkl
mn
kjlk
C n
&amp;
 o
_
&amp;
,
&amp;ZR
L q
L q
d- + /c b f J &amp;
A ! f J
E
JNMOE
!
!
mnn kjlk
m n
kjlk
m n
C n
\$ n
&amp;
R! 
! o
o
H
o

!
!R
The magnitude of the DFT coefficients is shown below in Fig. 7.3.
20
|F[n]|
15
10
5
0
0
1
2
3
f (Hz)
Figure 7.3: DFT of four point sequence.
Inverse Discrete Fourier Transform
The inverse transform of
_
&amp;
: L +=&lt;
JaMOE
d- +/bdegc f J
85
is
: =+ &lt;
L
f MOE
4&amp;
:
i.e. the inverse matrix is
ric) matrix.
&lt;
_
D-U / bdec f J
times the complex conjugate of the original (symmet-
Note that the
coefficients are complex. We can assume that the 4 values
_
are real (this is the simplest case; there are situations (e.g. radar) in which two
inputs, at each , are treated as a complex pair, since they are the outputs from o

and o demodulators).

and
(reIn the process of taking the inverse transform the terms
:V
_
_
member that the spectrum is symmetrical about ) combine to produce frequency components, only one of which
VXW is considered to: be valid (the one at the
V ; the higher frequency
Hz where
lower of the two frequencies,
:V _ 
_*] ?
component is at an “aliasing frequency” (
)).
_&iexcl;
From the inverse transform formula, the contribution to of
is:
f &amp; &pound;
_
S
For all real 8:
- + /bde c + f &brvbar;&gt; J &amp;
But
i.e.
S
_
&amp;
&ordf;&copy;
e c f J&curren;F
D- / bdg
_
_
&amp;
VXW
 - +  /   J
1 for all : L +=&lt;
JaMOE
_
_
and
8;:
D- / bde c + f &gt;&quot;J&yen;
8 :
D- +/bde c + f &gt;&brvbar;J
ec f J
-  \$/ bdec&uml;&sect; J &amp;Z-  \$/ bdg
(i.e. the complex conjugate)
86
&cent;
_
(7.2)
Substituting into the Equation for f 4&amp;
f above gives,
J F &copy; .- +/ bdegc f JH&yen;
d- / db egc f &curren;
_
_
&pound;
f &amp;
ie.
&pound;&laquo;&not;&pound;
_
&yen;  \
i.e. a sampled sinewave at
For the special case of
contribution of C to
nent.
VXW f
: ?
Hz, of magnitude
2.
3.
implies a d.c. value of
&ordf;&copy; 
V {&amp; R! &cedil;
V &amp;
: &plusmn; &brvbar; &plusmn; &amp; s ] &ordf;&amp;r
i.e.
_

&amp;&ordm;H
component
V &amp;
\
&yen; &uml;&macr;6&deg; \
_
_
&yen;
d &yen;
V
: &plusmn; _ &plusmn;
:
&lt;
VE
&amp;r
s
C&amp;
(as expected)
implies a fundamental component of peak amplitude
&sup2;&sup3;&uml;&acute; &amp; &sup1; o
with phase given by
:
&amp; V
_
VXW
- / J &amp;T
&amp;&micro; , &amp;S&para;&middot; 4 (i.e. sum of all samples) and the
_ 4 is E &curren;&amp; : &lt; &amp; average of &curren;&amp; d.c. compo-
Interpretation of example
C&amp;r\$
&pound;
\
f &amp; T&plusmn;
F&sup2;\$&sup3;&uml;&acute; &plusmn;  &pound; _
_
or
1.
_
&shy;&brvbar;&reg;
since

o &curren;&amp;tKU
– no other
e c &raquo;V J &amp; D- / bd&frac14;

S
_
\
Y
o
component here) and this implies a
W
4Hd- / J &amp;  \{
since &uml;&macr;D&deg;\{i&amp;t for all 87
(as expected)
(as expected)
6
5
|F[n]|
4
3/sqrt(2)
3
sqrt(2)
2
1
0
0
1
f (Hz)
2
3
Figure 7.4: DFT of four point signal.
Thus, the conventional way of displaying a spectrum is not as shown in Fig. 7.3
but as shown in Fig. 7.4 (obviously, the information content is the same):
In typical applications,
is much greater than  ; for example, for
UR  ,
 UR  are the complex conjugates of&amp;&frac12;
has U components, but ^
^

\$
,
V
V
EV &Agrave;
&lt;
&Agrave;
A
&lt;
&lt;
&Agrave;
_
leaving &lt;B&frac34;E &iquest; as the d.c. component, &lt;BE V &frac34;&Acirc; &iquest; V to &lt;BE V &frac34;&Acirc; &iquest; &Atilde; V as complete a.c. com-
s
ponents and
frequency _
&lt;
&lt;BE V s
&amp;
&lt;V&Agrave;
&frac34;&Acirc; &iquest; &Atilde; V
:V
.
s{&Aacute;
&Aacute;
sG&Aacute;
&Aacute;
as the cosine-only component at the highest distinguishable
f&Agrave;
f&Agrave;b
Most computer programmes evaluate &frac34;: &iquest; (or &frac34;: &iquest;
for the power spectral den&Aacute;
&Aacute;
&Aacute;
&Aacute;
sity) which gives the correct “shape” for the spectrum, except for the values at
:
&amp;Z and V .
_
7.2 Discrete Fourier Transform Errors
To what degree does the DFT approximate the Fourier transform of the function
underlying the data? Clearly the DFT is only an approximation since it provides
only for a finite set of frequencies. But how correct are these discrete values
themselves? There are two main types of DFT errors: aliasing and “leakage”:
88
7.2.1 Aliasing
This is another manifestation of the phenomenon which we have now encountered
several times. If the initial samples are not sufficiently closely spaced to represent
high-frequency components present in the underlying function, then the DFT values will be corrupted by aliasing. As before, the solution is either to increase the
sampling rate (if possible) or to pre-filter the signal in order to minimise its highfrequency spectral content.
7.2.2 Leakage
Recall that the continuous Fourier transform of a periodic waveform requires the
P
F P or over an integer number
integration to be performed over the interval - to
of cycles of the waveform. If we attempt to complete the DFT over a non-integer
number of cycles of the input signal, then we might expect the transform to be
corrupted in some way. This is indeed the case, as will now be shown.
Consider the case of an input signal which is a sinusoid with a fractional num:
ber of cycles in the data samples. The DFT for this case (for &amp;&Auml; to &amp; V )
_
_
is shown below in 7.5.
8
|F[n]|
6
4
2
0
0
2
4
freq
6
8
Figure 7.5: Leakage.
We might have expected the DFT to give an output at just the quantised frequen89
cies either side of the true frequency. This certainly does happen but we also find
non-zero outputs at all other frequencies. This smearing effect, which is known
as leakage, arises because we are effectively calculating the Fourier series for the
waveform in Fig. 7.6, which has major discontinuities, hence other frequency
components.
1
0.5
0
−0.5
−1
0
5
10
15
20
25
30
35
40
45
50
Figure 7.6: Leakage. The repeating waveform has discontinuities.
Most sequences of real data are much more complicated than the sinusoidal sequences that we have so far considered and so it will not be possible to avoid introducing discontinuities when using a finite number of points from the sequence
in order to calculate the DFT.
The solution is to use one of the window functions which we encountered in the
design of FIR filters (e.g. the Hamming or Hanning windows). These window
functions taper the samples towards zero values at both endpoints, and so there
is no discontinuity (or very little, in the case of the Hanning window) with a
hypothetical next period. Hence the leakage of spectral content away from its
correct location is much reduced, as in Fig 7.7.
(a)
(b)
7
5
6
4
5
4
3
3
2
2
1
1
0
0
2
4
6
0
8
0
2
4
6
Figure 7.7: Leakage is reduced using a Hanning window.
90
8
7.3 The Fast Fourier Transform
The time taken to evaluate a DFT on a digital computer depends principally on the
number of multiplications involved, since these
V are the slowest operations. With
the DFT, this number is directly related to
(matrix multiplication of a vector),
where
is the length of the transform. For most problems,
is chosen to be
at least 256 in order to get a reasonable approximation for the spectrum of the
sequence under consideration – hence computational speed becomes a major consideration.
Highly efficient computer algorithms for estimating Discrete Fourier Transforms have been developed since the mid-60’s. These are known as Fast Fourier
Transform (FFT) algorithms and they rely on the fact that the standard DFT involves a lot of redundant calculations:
Re-writing
_
&amp;
: L +=&lt;
JaMOE
D- +/ bde c f J
as
_
&amp;
: L +=&lt;
J
JNMOE
dp : f J
it is easy to realise that the same values of p : f are calculated many times as the
computation proceeds. Firstly, the integer product repeats for different comJ
_
binations of and ; secondly, p : f is a periodic function with only distinct
_
values.
For example, consider
of 2)
&amp;9
(the FFT is simplest by far if
is an integral power
!
&lt;
+
/
+
/
b
d
c
&AElig;
&Aring;
p &amp;t&amp; - s &Atilde;X&Ccedil; &amp; &Egrave;
t
&amp; &Eacute;= say Z
V &copy;
Then &Eacute; &amp;
!
&Eacute;Rq&amp; !5&Eacute;i&amp; &Eacute;
&Eacute;s &amp; &copy;
&Eacute;&Atilde; &amp; &Eacute;
&Eacute; u &amp;&Ecirc;!
&Eacute;5&Euml;%&amp;&Ecirc;!5&Eacute;&Igrave;&amp;9&Eacute;
From the above, it can be seen that:
91
&Aring;
&Eacute; ~
&amp; pt&Aring; s
p &Aring;&Atilde;
p &Aring;u
pv&Aring; &Euml;
Also, if
_
&amp; p &Aring;E
&amp; p &Aring; V&lt;
&amp; p &Aring;
&amp; pv&Aring; q
falls outside the range 0-7, we still get one of the above values:
eg. if
_
&amp;t
and i&amp;r&Iacute;^
&Aring;
p &Aring; q &Atilde; &amp;t&Eacute; q &Atilde; &amp;&ordm;&Eacute; s&Icirc; &Eacute; q &amp;t&Eacute; q
7.3.1 Decimation-in-time algorithm
Let us begin by splitting the single summation over samples into 2 summations,
:
each with V samples, one for even and the other for odd.
J
J+=V &lt; for odd and write:
Substitute &Iuml;S&amp; V for even and &Iuml;S&amp;
e =+ &lt;
Lb
V&ETH;
8 V &ETH; &lt; &gt;
4&Iuml;&cedil;dp : f F
&Iuml; F dp :  f
&amp;
_
&ETH; OM E
&ETH; MOE
e =+ &lt;
Lb
Note that
+ / bde c &ETH; f
V&ETH; f
&ETH;
8V &ETH; f &gt;
+
/
d
b
c
e
&amp; - b
9
p : t
&amp; &amp;rp e f
b
e =+ &lt;
Lb
e =+ &lt;
&ETH;
&ETH; Lb
&ETH;
&amp;
4&Iuml;&cedil;dp e f F p :
&Iuml; F dp e f
_
b
b
&ETH; OM E
&ETH; MOE
Therefore
ie.
_
&amp;t&Ntilde;&Ograve;
_
&ETH;
F p :i
&Oacute;
_
:
Thus the -point DFT
can be obtained from two V -point transforms,
_
one on even input data, &Ntilde;&Ograve; , and one on odd input data, &Oacute;
. Although the fre:
_
_
quency index ranges over values, only V values of &Ntilde;&Ograve; and &Oacute;
need to be
:
_
_
_
V
computed since &Ntilde;&Ocirc; and &Oacute;
are periodic in with period .
_
For example, for
_
&amp;9
_
:
92
&Otilde;
&Otilde;
even input data d&Ouml;\$
odd input data &amp;t&Ntilde;&Ograve; &brvbar;&amp;t&Ntilde;&Ograve;&brvbar;
4H&amp;t&Ntilde;&Ograve;4
&amp;t&Ntilde;&Ograve;
C&amp;t&Ntilde;&Ograve; 4H&amp;t&Ntilde;&Ograve;&brvbar;
&times;&amp;t&Ntilde;&Ograve;4
4&Iacute;H&amp;t&Ntilde;&Ograve; 
F p &Aring;E &Oacute;
F p &Aring;&lt; &Oacute;
F p &Aring;V &Oacute;
F pr&Aring; q &Oacute;
F pt&Aring; s &Oacute;
F p &Aring; &Oacute;
F p &Aring; &Atilde;u &Oacute;
F pv&Aring; &Euml; &Oacute;
&times;
&brvbar;d  d4H &Iacute;
C

C&amp;t&Ntilde;&Ograve;C
&amp;t&Ntilde;&Ograve;
&Ntilde;&Ograve; &amp;&amp;t
t&Ntilde;&Ograve; 
&Aring;E
p &Aring;&lt; &Oacute;
p &Aring;V &Oacute;
p &Aring; &Oacute;
prq &Oacute;
C

This is shown graphically on the flow graph of Fig 7.8:
G[0]
f[0]
f[2]
f[4]
f[6]
N/2
point
DFT
f[1]
f[3]
f[5]
f[7]
N/2
point
DFT
F[0]
G[3]
H[0]
F[7]
H[3]
Figure 7.8: FFT flow graph 1.
Assuming than
is a power of , we can repeat the above process on the two
:V
:
-point transforms, breaking them down to -point transforms, etc , until we
come down to -point transforms. For
&amp;s  , only one further stage is needed
(i.e. there are &Oslash; stages, where &amp;ZH&Ugrave; ), as shown below in Fig 7.9.
Thus the FFT is computed by dividing up, or decimating, the sample sequence
into sub-sequences until only -point DFT’s remain. Since it is the input, or
time, samples which are divided up, this algorithm is known as the decimationin-time (DIT) algorithm. (An equivalent algorithm exists for which the output, or
frequency, points are sub-divided – the decimation-in-frequency algorithm.)
The basic computation at the heart of the FFT is known as the butterfly because
of its criss-cross appearance. For the DIT FFT algorithm, the butterfly computation is of the form of Fig 7.10
93
f[0]
f[4]
f[2]
f[6]
f[1]
f[5]
f[3]
f[7]
F[0]
N/4 point
DFT
N/4 point
DFT
N/4 point
DFT
N/4 point
DFT
F[7]
Figure 7.9: FFT flow graph 2.
&Uacute;
&Uacute; F
&Ucirc;
p*: &Uuml;
R
&agrave;
&aacute;
&Yacute;
&THORN; &THORN;
&agrave;
&THORN; &THORN;
&agrave; &agrave;
&agrave;
&THORN; &THORN;
&agrave;
&THORN; &THORN;
&agrave; &agrave;
&agrave;
&THORN;&agrave; &agrave;&THORN;
&THORN; &THORN;
F p :&Uuml; &agrave; &agrave; &agrave;
&THORN; &THORN;
&agrave; &agrave;
&THORN; &THORN;
&agrave;
&agrave;
&THORN; &THORN; R&THORN; &szlig; &Uacute; &Uuml;
p
:
&Ucirc; &agrave;
&Ucirc;
&Yacute;
p :&Uuml;
*
Figure 7.10: Butterfly operation in FFT.
&Uacute;
&Ucirc;
where and are complex numbers. Thus a butterfly computation requires one
complex multiplication and 2 complex additions.
Note also, that the input samples are “bit-reversed” (see table below) because at
each stage of decimation the sequence input samples is separated into even- and
odd- indexed samples.
(NB: the bit-reversal algorithm only applies if
94
is an integral power of ).
Index
[
0
1
2
3
4
5
6
7
Binary
Bit-reversed Bit-reversed
representation
Binary
index
000
000
0
001
100
4
010
010
2
011
110
6
100
001
1
101
101
5
110
011
3
111
111
7
7.3.2 Computational speed of FFT
V
complex multiplications. At each stage of the FFT (i.e.
The DFT requires
:V
each halving) complex multiplications are required to combine the results of
the previous stage. Since there are B&acirc;BU&atilde; V stages, the number of complex multiplications required to evaluate an -point DFT with the FFT is approximately
e
E
because multiplications by factors such as p : , p : b
|e &auml; &acirc;BU&atilde; V (approximately
&auml;e
p : and p&micro;: &aring; are really just complex additions and subtractions).
V
32
256
1,024
(DFT)
1,024
65,536
1,048,576
:V
,
&acirc;,U&atilde; V
(FFT) saving
80
92 &aelig;
1,024
98 &aelig;
5,120
99.5 &aelig;
7.3.3 Practical considerations
If is not a power of , there are 2 strategies available to complete an
FFT.
-point
1. take advantage of such factors as possesses. For example, if is divisi
ble by (e.g.
&amp;&Auml;R ), the final decimation stage would include a  -point
transform.
95
2. pack the data with zeroes; e.g. include 16 zeroes with the 48 data points
(for &amp;vR ) and compute a &times;\$ -point FFT. (However, you should again be
wary of abrupt transitions between the trailing (or leading) edge of the data
and the following (or preceding) zeroes; a better approach might be to pack
the data with more realistic “dummy values”).
96
```