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.

DSPLIB: DSPF_sp_fftSPxSP radix question

I'm looking at the DSPF_sp_fftSPxSP function description in the TMS320C67x DSP Library Programmer's Reference Guide (spru657c).  This appears to be a copy of the comments in the DSPF_sp_fftSPxSP.h file from the TMS320C67x DSP Library.  There is a section in both that reads:

DSPF_sp_fftSPxSP(512, &x[0],&w[0],y,brev,2, 0,512);

is equivalent to:

DSPF_sp_fftSPxSP(512, &x[2*0], &w[0] , y,brev,128,0,512)

DSPF_sp_fftSPxSP(128, &x[2*0], &w[2*384],y,brev,4,0,512)

DSPF_sp_fftSPxSP(128, &x[2*128],&w[2*384],y,brev,4,128,512)

DSPF_sp_fftSPxSP(128, &x[2*256],&w[2*384],y,brev,4,256,512)

DSPF_sp_fftSPxSP(128, &x[2*384],&w[2*384],y,brev,4,384,512)

The four 128 point sub FFTs in the "equivalent to" section are called with a radix of 4.  I'm wondering if this is a typo in the documentation and should be calling these with a radix of 2 or does the DSPF_sp_fftSPxSP function allow a non "power of 4" point FFT to called with a radix of 4.

  • Yes, this is a typo; radix 2 should be used in this case.  Radix 4 should only be used when the FFT size is a power of 4.

  • vikesfan,

     can  you tell me if DSPF_sp_fftSPxSP replace the real_fft function  in the follow code ?

    thanks.

     

    -Tanger

    ////////////////////////////////////////////////////////////////////////////////////

    #define SIZE  128
    #define SIZE_BY_TWO 64
    #define NUM_STAGE  6
     
     void        real_fft (float *farray_ptr, int isign)
     {
     
       _double_           ftmp1_real, ftmp1_imag, ftmp2_real, ftmp2_imag;
       int       i, j;
       static int      first = TRUE;
     
       void            cmplx_fft (float *, int);
       void            fill_tbl ();
     
       /* If this is the first call to the function, fill up the
          phase table  */
       if (first == TRUE) {
         fill_tbl ();
         first = FALSE;
       }
     
       /* The FFT part */
       if (isign == 1) {
     
         /* Perform the complex FFT */
         cmplx_fft (farray_ptr, isign);
     
         /* First, handle the DC and foldover frequencies */
         ftmp1_real = *farray_ptr;
         ftmp2_real = *(farray_ptr + 1);
         *farray_ptr = (float)(ftmp1_real + ftmp2_real);
         *(farray_ptr + 1) = (float)(ftmp1_real - ftmp2_real);
     
         /* Now, handle the remaining positive frequencies */
         for (i = 2, j = SIZE - i; i <= SIZE_BY_TWO; i = i + 2, j = SIZE - i) {
     
           ftmp1_real = *(farray_ptr + i) + *(farray_ptr + j);
           ftmp1_imag = *(farray_ptr + i + 1) - *(farray_ptr + j + 1);
           ftmp2_real = *(farray_ptr + i + 1) + *(farray_ptr + j + 1);
           ftmp2_imag = *(farray_ptr + j) - *(farray_ptr + i);
     
           *(farray_ptr + i) = (ftmp1_real + phs_tbl [i] * ftmp2_real -
                          phs_tbl [i + 1] * ftmp2_imag) / 2.0;
           *(farray_ptr + i + 1) = (ftmp1_imag + phs_tbl [i] * ftmp2_imag +
                              phs_tbl [i + 1] * ftmp2_real) / 2.0;
           *(farray_ptr + j) = (ftmp1_real + phs_tbl [j] * ftmp2_real +
                          phs_tbl [j + 1] * ftmp2_imag) / 2.0;
           *(farray_ptr + j + 1) = (-ftmp1_imag - phs_tbl [j] * ftmp2_imag +
                              phs_tbl [j + 1] * ftmp2_real) / 2.0;
         }
       }
     
       /* The IFFT part */
       else {
     
         /* First, handle the DC and foldover frequencies */
     
         ftmp1_real = *farray_ptr;
         ftmp2_real = *(farray_ptr + 1);
         *farray_ptr = (ftmp1_real + ftmp2_real) / 2.0;
         *(farray_ptr + 1) = (ftmp1_real - ftmp2_real) / 2.0;
     
         /* Now, handle the remaining positive frequencies */
     
         for (i = 2, j = SIZE - i; i <= SIZE_BY_TWO; i = i + 2, j = SIZE - i) {
     
           ftmp1_real = *(farray_ptr + i) + *(farray_ptr + j);
           ftmp1_imag = *(farray_ptr + i + 1) - *(farray_ptr + j + 1);
           ftmp2_real = -(*(farray_ptr + i + 1) + *(farray_ptr + j + 1));
           ftmp2_imag = -(*(farray_ptr + j) - *(farray_ptr + i));
     
           *(farray_ptr + i) = (ftmp1_real + phs_tbl [i] * ftmp2_real +
                          phs_tbl [i + 1] * ftmp2_imag) / 2.0;
           *(farray_ptr + i + 1) = (ftmp1_imag + phs_tbl [i] * ftmp2_imag -
                              phs_tbl [i + 1] * ftmp2_real) / 2.0;
           *(farray_ptr + j) = (ftmp1_real + phs_tbl [j] * ftmp2_real -
                          phs_tbl [j + 1] * ftmp2_imag) / 2.0;
           *(farray_ptr + j + 1) = (-ftmp1_imag - phs_tbl [j] * ftmp2_imag -
                              phs_tbl [j + 1] * ftmp2_real) / 2.0;
         }
     
         /* Perform the complex IFFT */
         cmplx_fft (farray_ptr, isign);
       }
     
       return;
     }           /* end real_fft () */
     
     
     
     void        cmplx_fft (float *farray_ptr, int isign)
     {
       int       i, j, k, ii, jj, kk, ji, kj;
       _double_           ftmp, ftmp_real, ftmp_imag;
     
       /* Rearrange the input array in bit reversed order */
       for (i = 0, j = 0; i < SIZE-2; i = i + 2) {
         if (j > i) {
           ftmp = (_double_)*(farray_ptr+i);
           *(farray_ptr+i) = *(farray_ptr+j);
           *(farray_ptr+j) = ftmp;
     
           ftmp = (_double_)*(farray_ptr+i+1);
           *(farray_ptr+i+1) = *(farray_ptr+j+1);
           *(farray_ptr+j+1) = ftmp;
         }
         k = SIZE_BY_TWO;
         while (j >= k) {
           j -= k;
           k >>= 1;
         }
         j += k;
       }
     
       /* The FFT part */
       if (isign == 1) {
         for (i = 0; i < NUM_STAGE; i++) {           /* i is stage counter */
           jj = (2 << i);                      /* FFT size */
           kk = (jj << 1);                     /* 2 * FFT size */
           ii = SIZE / jj;                     /* 2 * number of FFT's */
           for (j = 0; j < jj; j = j + 2) {          /* j is sample counter */
             ji = j * ii;                      /* ji is phase table index */
             for (k = j; k < SIZE; k = k + kk) {     /* k is butterfly top */
               kj = k + jj;                    /* kj is butterfly bottom */
     
             /* Butterfly computations */
               ftmp_real =  *(farray_ptr + kj) * phs_tbl [ji] -
                            *(farray_ptr + kj + 1) * phs_tbl [ji + 1];
     
               ftmp_imag =  *(farray_ptr + kj + 1) * phs_tbl [ji] +
                            *(farray_ptr + kj) * phs_tbl [ji + 1];
     
               *(farray_ptr + kj) = ( *(farray_ptr + k) - ftmp_real) / 2.0;
               *(farray_ptr + kj + 1) = (*(farray_ptr + k + 1) - ftmp_imag) / 2.0;
     
               *(farray_ptr + k) = (*(farray_ptr + k) + ftmp_real) / 2.0;
               *(farray_ptr + k + 1) = (*(farray_ptr + k + 1) + ftmp_imag) / 2.0;
             }
           }
         }
       }
     
       /* The IFFT part */
       else {
         for (i = 0; i < NUM_STAGE; i++) {           /* i is stage counter */
           jj = (2 << i);                      /* FFT size */
           kk = (jj << 1);                     /* 2 * FFT size */
           ii = SIZE / jj;                     /* 2 * number of FFT's */
           for (j = 0; j < jj; j = j + 2) {          /* j is sample counter */
             ji = j * ii;                      /* ji is phase table index */
             for (k = j; k < SIZE; k = k + kk) {     /* k is butterfly top */
               kj = k + jj;                    /* kj is butterfly bottom */
     
             /* Butterfly computations */
               ftmp_real = *(farray_ptr + kj) * phs_tbl [ji] +
               *(farray_ptr + kj + 1) * phs_tbl [ji + 1];
     
               ftmp_imag = *(farray_ptr + kj + 1) * phs_tbl [ji] -
               *(farray_ptr + kj) * phs_tbl [ji + 1];
     
               *(farray_ptr + kj) = *(farray_ptr + k) - ftmp_real;
               *(farray_ptr + kj + 1) = *(farray_ptr + k + 1) - ftmp_imag;
     
               *(farray_ptr + k) = *(farray_ptr + k) + ftmp_real;
               *(farray_ptr + k + 1) = *(farray_ptr + k + 1) + ftmp_imag;
             }
           }
         }
       }
       return;
     }           /* end of cmplx_fft () */