Вы находитесь на странице: 1из 32

Copyright 2003 Texas Instruments. All rights reserved.

DSP C5000
Chapter 19
Fast Fourier Transform
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 2
Discrete Fourier Transform
Allows us to compute an approximation of
the Fourier Transform on a discrete set of
frequencies from a discrete set of time
samples.






Where k are the index of the discrete
frequencies and n the index of the time samples
+

= dt e t x f X
ft j t 2
) ( ) (
1 , , 1 , 0 for
2
1
0
= =

=
N k e n x k X
n
N
k
j
N
n

t
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 3
Inverse Discrete Fourier Transform
The inverse formula is:



Where, again, k are the index of the discrete
frequencies and n the index of the time
samples.
We have the following properties:
Discrete time periodic spectra
Periodic time discrete spectra
1 , , 1 , 0 for
1
2
1
0
= =

=
N n e k X
N
n x
n
N
k
j
N
k

t
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 4
DFT Computation
We can write the DFT:



We need:
N(N-1) complex +
N
2
complex
N
j
N
n
e N k n x k X
t 2
N
kn -
N
1
0
W with 1 , , 1 , 0 for W = = =

=

N + x
128 16256 16384
1024 1047552 1048576
4096 16773120 16777216
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 5
Fast Fourier Transform 1 of 3
Cooley-Tukey algorithm:
Based on decimation, leads to a factorization of
computations.
Let us first look at the classical radix 2
decimation in time.
This particular case of the algorithm requires
the time sequence length to be a power of 2.
First we split the computation between odd and
even samples:
| | | | | |
( ) 1 2n k -
N
1 2 /
0
k2n -
N
1 2 /
0
W 1 2 W 2
+

=
+ + =
N
n
N
n
n x n x k X
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 6
Fast Fourier Transform 2 of 3
Using the following property:



The DFT can be rewritten:




For k=0, 1, , N-1
| | | | | |
kn -
2
N
1 2 /
0
k -
N
kn -
2
N
1 2 /
0
W 1 2 W W 2

=

=
+ + =
N
n
N
n
n x n x k X
2
N
2
N
W W =
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 7
Fast Fourier Transform 3 of 3
Using the property that:



The entire DFT can be computed with only
k=0, 1, ,N/2-1.



and
k
N
2
N
k
N
W W =
+
| | | | | |
kn -
2
N
1 2 /
0
k -
N
kn -
2
N
1 2 /
0
W 1 2 W W 2

=

=
+ + =
N
n
N
n
n x n x k X
| | | |
kn -
2
N
1 2 /
0
k -
N
kn -
2
N
1 2 /
0
W 1 2 W W 2
2

=

=
+ =
(

+
N
n
N
n
n x n x
N
k X
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 8
Butterfly
This leads to basic building block of the
FFT, the butterfly.
TFD N/2
TFD N/2
x(0)
x(2)
x(N-2)
x(1)
x(3)
x(N-1)
X(0)
X(1)
X(N/2-1)
X(N/2)
X(N/2+1)
X(N-1)
W
0

W
1

W
N/2-1

-
-
-
We need:
N/2(N/2-1) complex + for each
N/2 DFT.
(N/2)
2
complex for each
DFT.
N/2 complex at the input of
the butterflies.
N complex + for the butter-
flies.
Grand total:
N
2
/2 complex +
N/2(N/2+1) complex
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 9
Recursion
If N/2 is even, we can further split the computation of
each DFT of size N/2 into two computations of half size
DFT. When N=2
r
this can be done until DFT of size 2 (i.e.
butterfly with two elements).
x(0)
x(4)
x(2)
x(6)
x(1)
x(5)
x(3)
x(7)
X(0)
X(1)
X(2)
X(3)
X(4)
X(5)
X(6)
X(7)
W
8
0

W
8
1

W
8
2

W
8
3

-
-
-
- -
-
-
-
-
-
-
-
W
8
0

W
8
0

W
8
1

W
8
1

W
8
0

W
8
0

W
8
0

W
8
0

W
8
0
=1
1
st
stage 2
nd
stage 3
rd
stage
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 10
Number of Operations
If N=2
r
, we have r=log
2
(N) stages. For each
one we have:
N/2 complex (some of them are by 1).
N complex +.
Thus the grand total of operations is:
N/2 log
2
(N) complex .
N log
2
(N) complex +.
N + x
128 896 448
1024 10240 5120
4096 49152 24576
These counts can be compared with the ones for the DFT
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 11
Shuffling the Data, Bit Reverse Ordering
At each step of the algorithm, data are split
between even and odd values. This results in
scrambling the order.
x(0)
x(1)
x(2)
x(3)
x(4)
x(5)
x(6)
x(7)
x(0)
x(2)
x(4)
x(6)
x(1)
x(3)
x(5)
x(7)
x(0)
x(4)
x(2)
x(6)
x(1)
x(5)
x(3)
x(7)
Recursion of the algorithm
index address
000 000
100 001
010 010
110 011
001 100
101 101
011 110
111 111
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 12
Reverse Carry Propagation
This scrambling when we use radix 2 FFT can
be obtained by the Reverse Carry Propagation
(RCP) algorithm.







We start with address 0 then we add N/2 to
obtain the next address. If there is a carry, it
propagates towards the least significant bit.
When the data arrive in natural order, they are
scrambled in this way.
n Address[x(n+1)] Address[x(n)]
000 RCP(000+100)=100 000
001 RCP(100+100)=010 100
010 RCP(010+100)=110 010
011 RCP(110+100)=001 110
100 RCP(001+100)=101 001
101 RCP(101+100)=011 101
110 RCP(011+100)=111 011
111 111
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 13
Algorithm Parameters 1 of 2
The FFT can be computed according to the
following pseudo-code:
For each stage
For each group of butterfly
For each butterfly
compute butterfly
end
end
end
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 14
Algorithm Parameters 2/2
The parameters are shown below:
1st stage 2nd stage 3rd stage Last stage
Node
Spacing
1 2 3 N/2
Butterflies
per group
1 2 3 N/2
Number of
groups
N/2 N/4 N/8 1
Twiddle
factor

( )
/ 2
0
N k
N
W
k

=
( )
/ 4
0,1
N k
N
W
k

=
( )
/ 8
0, , 3
N k
N
W
k

=
0, , / 2 1
k
N
W
k N

=
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 15
Scaling
The DFT computation for each k is :



To prevent overflow we need to have:


This is guaranteed provided a scale factor 1/N

| | | |
kn -
N
1
0
W

=
=
N
n
n x k X
1 s k X
1 W
1

kn -
N
1
0
s
|
.
|

\
|
=

=
N
n
n x
N
k X
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 16
Quantization Noise
Quantization step is :

If words have b+1 bits and x(n) belongs to
[-1,1]
If we assume that each real multiplication
gives rise to a noise source of power
The total amount of noise power for each
X(k) is given by
b
= A 2
2
e
o
( )
( ) N r N
r b
e t 2
2 / 2
2 2
log with
3
2
4 = = =

o o
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 17
Signal to Quantization Noise Ratio (SQNR)
DFT case
If we assume x(n) uniform in [-1,1], after
scaling, variance of data become:


And because each X(k) comes from N
summations:

SQNR for DFT with scaling is given by:
2
2
3
1
N
x
= o
N
X
3
1
2
= o
r b dB SQNR
t
X
6 6 log 10 ) (
2
2
=
|
|
.
|

\
|
=
o
o
N SQNR(dB) ENOB
128 48 8
1024 30 5
4096 18 3
ENOB: effective number of bits, gives the effective resolution given a SNR. Based on the
assumption that 6dB of SNR equates to 1 bit of precision.
16 bits per word
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 18
Signal to Quantization Noise Ratio (SQNR)
FFT case 1 of 3
The computation of one X(k) requires N-1 butterflies:
x(0)
x(4)
x(2)
x(6)
x(1)
x(5)
x(3)
x(7)
X(0)
X(1)
X(2)
X(3)
X(4)
X(5)
X(6)
X(7)
W
8
0

W
8
1

W
8
2

W
8
3

-
-
- -
-
-
-
-
-
W
8
0

W
8
0

W
8
1

W
8
1

W
8
0

W
8
0

W
8
0

W
8
0

N/2 butterflies
of the 1
st
stage
N/4 butterflies
of the 2
nd
stage
1 butterfly of
the last stage
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 19
Signal to Quantization Noise Ratio (SQNR)
FFT case 2 of 3
Butterfly computation




To prevent overflow, we only need to scale the
inputs of each butterfly by 1/2
X
n
(l)
-
W
X
n
(k)
X
n+1
(l)
X
n+1
(k)
( ) ( ) ( )
( ) ( ) ( ) k X W l X k X
k X W l X l X
n n n
n n n


1
1
=
+ =
+
+
X
n
(l)
-
W
X
n
(k)
X
n+1
(l)
X
n+1
(k)
1/2
1/2
Because we have r stages, the global
scaling factor for one output is:
N
r
1
2
1
=
|
.
|

\
|
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 20
Signal to Quantization Noise Ratio (SQNR)
FFT case 3 of 3
Quantization noise source at one stage is attenuated by
scale factors of all the following stages.
This gives an equivalent noise source of:


for each output.
SQNR for FFT with scaling is given by:
3
2
2
2
1
1 2
3
2
2 2
2
b
r
b
t

~
|
|
.
|

\
|
|
.
|

\
|
= o
3 3 6 log 10 ) (
2
2
=
|
|
.
|

\
|
= r b dB SQNR
t
X
o
o
N SQNR(dB) ENOB
128 66 11
1024 57 9,5
4096 51 8,5
16 bits per word
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 21
FFT Algorithm with Block Floating Point
Scaling
Input data in bit reverse order
Set-up for next stage
Set-up for next group
Set-up for next butterfly
Scale inputs of butterfly (1/2)
More butterflies ?
More groups ?
More stages ?
End of algorithm
Compute butterfly
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 22
Case Study C54x
Use of audioFFT
*

(
*
) this program is the same as \ti\examples\dsk5416\bios\audio except for some slight
modifications that will be emphazised when necessary
Block
processing
PCM3002
ADC
PCM3002
DAC
pipRx
pipTx
inBuffer
outBuffer
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 23
Audio Program
Block processing is echo() function in
audio.c :
In the original program: Data from input
stream are copied directly in output stream.
In the modified program :
The input stream is split between left and right in two
separate buffers.
Each buffer is processed
Bit-reverse scrambling
Forward transform
Bit reverse scrambling
Inverse transform
Resulting left and right buffers are interleaved in the
output stream.
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 24
DSPLIB functions
The DSP Library (DSPLIB) is a collection of
high-level optimized DSP function modules for
the C54x and C55x DSP platform.
C54x DSPLIB functions for FFT computation
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 25
Block Processing 1 of 3
Echo( )
Include and declarations
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 26
Block Processing 2 of 3
Dsplib functions calls
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 27
C54x DSPLIB Bit Reversal
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 28
Block Processing 3 of 3
Linker .cmd file
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 29
C54x DSPLIB FFT

Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 30
To Run the Build Process
Project options
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 31
To Change the Size of the Processing Buffer
Change buffer length declaration in echo function (audio.c)
Change the call to cfft and cifft according to the size of the FFT (must be hard coded)
Change buffer alignment in linker .cmd file
Copyright 2003 Texas Instruments. All rights reserved. ESIEE, Slide 32
Follow on Activities for TMS320C5416 DSK
Application 8 for the the TMS320C5416 DSK
uses the FFT as a spectrum analyzer to
display the power in an audio signal at
various frequencies.
Rather than using the optimized library
DSPLIB for the FFT, it uses a C code version
that is slower, but can be stepped through line
by line using Code Composer Studio.