19fft_v102

Upload: vinodkumartummalur

Post on 02-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 19fft_v102

    1/32

    Copyright 2003 Texas Instruments. All rights reserved.

    DSP C5000

    Chapter 19

    Fast Fourier Transform

  • 8/10/2019 19fft_v102

    2/32

    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 offrequencies from a discrete set of timesamples.

    Where k are the index of the discretefrequencies and n the index of the time samples

    dtetxfX

    f tj

    2

    )()(

    1,,1,0for

    21

    0

    NkenxkX

    nN

    kjN

    n

  • 8/10/2019 19fft_v102

    3/32

  • 8/10/2019 19fft_v102

    4/32

    Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 4

    DFT Computation

    We can write the DFT:

    We need:

    N(N-1) complex +

    N2complex

    NjN

    n

    eNknxkX

    2

    N

    kn-

    N

    1

    0

    Wwith1,,1,0forW

    N + x128 16256 16384

    1024 1047552 1048576

    4096 16773120 16777216

  • 8/10/2019 19fft_v102

    5/32

    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 ofcomputations.

    Let us first look at the classical radix 2decimation in time.

    This particular case of the algorithm requiresthe time sequence length to be a power of 2.

    First we split the computation between odd andeven samples:

    12nk-

    N

    12/

    0

    k2n-

    N

    12/

    0

    W12W2

    N

    n

    N

    n

    nxnxkX

  • 8/10/2019 19fft_v102

    6/32

  • 8/10/2019 19fft_v102

    7/32

  • 8/10/2019 19fft_v102

    8/32

    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)

    W0

    W1

    WN/2-1

    -

    -

    -

    We need:

    N/2(N/2-1) complex + for eachN/2 DFT.

    (N/2)2 complex for eachDFT.

    N/2 complex at the input ofthe butterflies.

    N complex + for the butter-flies.

    Grand total:

    N2/2 complex +

    N/2(N/2+1) complex

  • 8/10/2019 19fft_v102

    9/32Copyright 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/2into two computations of half sizeDFT. When N=2rthis 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)

    W80

    W81

    W82

    W83

    -

    -

    -

    --

    -

    -

    -

    -

    -

    -

    -

    W80

    W80

    W81

    W81

    W80

    W80

    W80

    W80

    W80=1

    1ststage2ndstage3rdstage

  • 8/10/2019 19fft_v102

    10/32Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 10

    Number of Operations

    If N=2r, we have r=log2(N) stages. For each

    one we have: N/2complex (some of them are by 1).

    Ncomplex +.

    Thus the grand total of operations is:

    N/2log2(N)complex .

    Nlog2(N)complex +.

    N + x

    128 896 448

    1024 10240 5120

    4096 49152 24576

    These counts can be compared with the ones for the DFT

  • 8/10/2019 19fft_v102

    11/32Copyright 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 inscrambling 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 addres s

    000 000

    100 001

    010 010

    110 011

    001 100

    101 101

    011 110

    111 111

  • 8/10/2019 19fft_v102

    12/32Copyright 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 0then we add N/2 toobtain the next address. If there is a carry, itpropagates 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

  • 8/10/2019 19fft_v102

    13/32Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 13

    Algorithm Parameters 1 of 2

    The FFT can be computed according to thefollowing pseudo-code:

    For each stage

    For each group of butterfly For each butterfly

    compute butter f ly

    end

    end

    end

  • 8/10/2019 19fft_v102

    14/32Copyright 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

    Butterfliesper group

    1 2 3 N/2

    Number of

    groups N/2 N/4 N/8 1

    Twiddle

    factor

  • 8/10/2019 19fft_v102

    15/32Copyright 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

    nxkX

    1kX

    1W1

    kn-

    N

    1

    0

    N

    n

    nxN

    kX

  • 8/10/2019 19fft_v102

    16/32Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 16

    Quantization Noise

    Quantization step is :

    If words have b+1bits and x(n)belongs to[-1,1]

    If we assume that each real multiplicationgives rise to a noise source of power

    The total amount of noise power for eachX(k) is given by

    b

    2

    2

    e

    NrN

    rb

    et 2

    2/222

    logwith3

    24

    Si Q i i i i (SQ )

  • 8/10/2019 19fft_v102

    17/32Copyright 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

    Nx

    NX

    3

    12

    rbdBSQNRt

    X 66log10)(2

    2

    N SQNR(dB) ENOB

    128 48 81024 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

    Si l Q i i N i R i (SQNR)

  • 8/10/2019 19fft_v102

    18/32Copyright 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)

    W80

    W81

    W82

    W83

    -

    -

    --

    -

    -

    -

    -

    -

    W80

    W80

    W81

    W81

    W80

    W80

    W80

    W80

    N/2 butterfliesof the 1ststage

    N/4 butterfliesof the 2ndstage

    1 butterfly ofthe last stage

    Si l Q i i N i R i (SQNR)

  • 8/10/2019 19fft_v102

    19/32Copyright 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 theinputs of each butterfly by 1/2

    Xn(l)

    -W

    Xn(k)

    Xn+1(l)

    Xn+1(k)kXWlXkX

    kXWlXlX

    nnn

    nnn

    1

    1

    Xn

    (l)

    -W

    Xn(k)

    Xn+1

    (l)

    Xn+1(k)

    1/2

    1/2

    Because we have rstages, the global

    scaling factor for one output is:

    N

    r

    1

    2

    1

    Si l t Q ti ti N i R ti (SQNR)

  • 8/10/2019 19fft_v102

    20/32Copyright 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

    22

    2

    112

    3

    222

    2brb

    t

    336log10)(2

    2

    rbdBSQNRt

    X

    N SQNR(dB) ENOB

    128 66 111024 57 9,5

    4096 51 8,5

    16 bits per word

    FFT Al ith ith Bl k Fl ti P i t

  • 8/10/2019 19fft_v102

    21/32Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 21

    FFT Algorithm with Block Floating PointScaling

    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

  • 8/10/2019 19fft_v102

    22/32Copyright 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

    PCM3002ADC

    PCM3002DAC

    pipRx

    pipTx

    inBuffer

    outBuffer

  • 8/10/2019 19fft_v102

    23/32Copyright 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 twoseparate buffers.

    Each buffer is processed

    Bit-reverse scrambling

    Forward transform

    Bit reverse scrambling

    Inverse transform

    Resulting left and right buffers are interleaved in theoutput stream.

  • 8/10/2019 19fft_v102

    24/32Copyright 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 forthe C54x and C55x DSP platform.

    C54x DSPLIB functions for FFT computation

  • 8/10/2019 19fft_v102

    25/32Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 25

    Block Processing 1 of 3

    Echo( )

    Include and declarations

  • 8/10/2019 19fft_v102

    26/32Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 26

    Block Processing 2 of 3

    Dsplib functions calls

  • 8/10/2019 19fft_v102

    27/32Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 27

    C54x DSPLIB Bit Reversal

  • 8/10/2019 19fft_v102

    28/32

  • 8/10/2019 19fft_v102

    29/32

    Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 29

    C54x DSPLIB FFT

  • 8/10/2019 19fft_v102

    30/32

    Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 30

    To Run the Build Process

    Project options

  • 8/10/2019 19fft_v102

    31/32

    Copyright 2003 Texas Instruments. All rights reserved.ESIEE, Slide 31

    To Change the Size of the Processing Buffer

    Change buffer length declaration in echofunction (audio.c)Change the call to cfft and cifftaccording to the size of the FFT (must be hard coded)

    Change buffer alignment in linker .cmd file

  • 8/10/2019 19fft_v102

    32/32

    Follow on Activities for TMS320C5416 DSK

    Application 8 for the the TMS320C5416 DSK

    uses the FFT as a spectrum analyzer todisplay the power in an audio signal atvarious frequencies.

    Rather than using the optimized library

    DSPLIB for the FFT, it uses a C code versionthat is slower, but can be stepped through lineby line using Code Composer Studio.