This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

FFT problem in 6713

Hi All,
I am using the DSPF_sp_cfftr2_dit() function to calculate 256 point fft followed by DSPF_sp_bitrev_cplx() for bit reversal.
 
/* nFFT=256; workbuf has 512 elements after inserting 0s in the imaginary positions ; twiddle is of length nFFT, bit_rev_table is of length 16
*/
 DSPF_sp_cfftr2_dit(workbuf,twiddle,nFFT);/*input in normal order, output in order bit-reversed coefficient table in bit-reversed order*/
 
 /*required for bit reversing the output of the fft fxn*/
 DSPF_sp_bitrev_cplx((double*)workbuf,bit_rev_table,nFFT);
 
furthermore and twiddle is generated by functions given in SPRU657B (dsplib prog guide) and bit_rev_table is generated by
bitrev_index()
{
int count, j, k, radix = 2;
short nbits, nbot, ntop, ndiff, n2, raddiv2;
nbits = 0;
count = nFFT;
while (count > 1)
{
count = count >> 1;
nbits++;
}
raddiv2 = radix >> 1;
nbot = nbits >> raddiv2;
nbot = nbot << raddiv2 - 1;
ndiff = nbits & raddiv2;
ntop = nbot + ndiff;
n2 = 1 << ntop;
bit_rev_table[0] = 0;
for ( count = 1, j = n2/radix + 1; count < n2 - 1; count++)
{
bit_rev_table[count] = j - 1;
for (k = n2/radix; k*(radix-1) < j; k /= radix)
j -= k*(radix-1);
j += k;
}
bit_rev_table[n2 - 1] = n2 - 1;
}
 
am I doing it correctly? I am asking this because the plot of workbuf in the CCS and the one in Matlab do not match.
 
Thanks
TK

  • Did you bit-reverse your twiddle table?  Here's some code I got working several years ago:

    old code said:

    // In the following code 'n' is the FFT size as given in
    // complex samples, i.e. there are 2*n floats with the
    // even numbered floats representing the real part and
    // the odd numbered floats representing the imaginary part


    void fft_r2_init(float *w1, int n, short *br_table)
    {
        int i;

        for(i=0; i<n; i++)        // initialize bit-rev table to zero
            br_table[ i ] = 0;

        bitrev_index(br_table, n);

        gen_twiddle(w1, n);        // generate twiddle table of n/2 complex twiddles
        DSPF_sp_bitrev_cplx((double *)w1, br_table, n/2);        // put twiddle table in bit-reversed order

    }

    void fft_r2(float *x1, float *w1, int n, short *br_table)
    {
        DSPF_sp_cfftr2_dit(x1, w1, n);    // in-place FFT
        DSPF_sp_bitrev_cplx((double *)x1, br_table, n);

    }

    Make sure you get the sizes write.  Specifically when you bit-reverse the twiddle table make sure you pass n/2.

    Brad

  • Hi Brad

    shouldn't the br_table be of sqrt(n) size rather than n?

     

    ~Nishank

  • Hi all,

    I managed to get it work with:

    bir_rev(br_table,n);

    gen_w_r2(w,2*n);

    DSPF_sp_bitrev_cplx((double*)w,br_table,n);

     

    where n in number of complex samples