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.

Problem with DSP_FFT and IFFT....!

HI!

In the documentation provided  (   TMS320C64x+ DSP Little-Endian DSP Library Programmer’s Reference) , it is mentioned that for calculating  32 bit FFT the input data must be scaled by 2^(log2(nx)) to completely prevent overflow. As per the documnet the input data should be scaled by a factor of 8.

               But, in the sample code provided with DSP library, to calculate 32 bit FFT ,a scaling factor of 3 is used to scale 256 point data .Could you plz clarify this point..

On what basis is the Scaling factor selected.

Also, for calculating the twiddle factor for FFT and IFFT using the functions  gen_twiddle_fft32x32 and gen_twiddle_ifft32x32, the scaling factor must be 2147483647.5.

After calculating the IFFT should the input be downscaled to obtain correct results.

I have tried to calculate 512 point FFT and IFFT  of an raw file(.raw).

It consists of 512*512 data. The IFFT result obtained  is incorrect. 

 

Here is my code. 

 

#include <stdio.h>

#include <stdint.h>

#include <math.h>

#include <string.h>

#include "C:\Program Files\Texas instruments\dsplib_c66x_3_0_0_7\inc\dsplib.h"

#include <ti\dsplib\src\DSP_fft32x32\c66\gen_twiddle_fft32x32.h>

#include <ti\dsplib\src\DSP_ifft32x32\c66\gen_twiddle_ifft32x32.h>

#include <ti\dsplib\src\DSP_fft32x32\DSP_fft32x32.h>

#include <ti\dsplib\src\DSP_ifft32x32\DSP_ifft32x32.h>

 

#define row_width 512

#define image_height 512

#define SCALE 9

 

#define LENGTH row_width * 2

 

#pragma DATA_ALIGN(fft, 8);

int32_t fft[LENGTH];

 

#pragma DATA_ALIGN(twiddle, 8);

int32_t twiddle[LENGTH];

 

#pragma DATA_ALIGN(itwiddle, 8);

int32_t itwiddle[LENGTH];

 

#pragma DATA_ALIGN(result, 8);

int32_t result[LENGTH];

 

#pragma DATA_ALIGN(tempin, 8);

int32_t tempin[2*row_width];

 

#pragma DATA_ALIGN(input_to_fft, 8);

int32_t input_to_fft[image_height*row_width];

 

void main(void)

{

 int i,n;

 FILE *fpr,*fpw,*fpin;

 int m = 0;

 int16_t *gRxBuffer = (int16_t *) malloc (row_width*image_height*sizeof(int16_t));

    memset(gRxBuffer,0,row_width*sizeof(int16_t));

 

   int32_t *gTxBuffer = (int32_t *) malloc (row_width*image_height*sizeof(int32_t));

    memset(gTxBuffer,0,row_width*sizeof(int32_t));

 

 

    fpr = fopen( "D:\\3d_reconstruction\\Phantom\\image_0000.raw", "rb");

    fread(gRxBuffer,sizeof(int32_t),row_width*image_height, fpr);

    fclose(fpr);

 

  gen_twiddle_fft32x32(twiddle, (int)row_width,2147483647.5);

  gen_twiddle_ifft32x32(itwiddle, (int)row_width,2147483647.5);

 

   for(i=0;i<image_height;i++)

  {

  memset(tempin,0,2*row_width*sizeof(int32_t));

  memset(fft,0,2*row_width*sizeof(int32_t));

  memset(result,0,2*row_width*sizeof(int32_t));

 

 

 

    for(m=0; m<row_width; m++)

    {

    tempin[2*m] = (*(gRxBuffer +(i*row_width)+ m) >> SCALE);

 

    // tempin[2*m] =( *(gRxBuffer + m ))>> SCALE ;

    input_to_fft[m+(i*row_width)]=tempin[2*m];

    }

 

 

 DSP_fft32x32(twiddle, (int)row_width, tempin, fft);

 

 DSP_ifft32x32(itwiddle, (int)row_width, fft, result);

 

 for(n=0;n<row_width;n++)

 {

*( gTxBuffer + (i*row_width) + n) = result[2*n]<< SCALE;

}

 

 

}

 

 fpw = fopen("F:\\output.raw", "wb");

fwrite(gTxBuffer, sizeof(int32_t),row_width*image_height, fpw);

// fwrite(gTxBuffer, sizeof(short),row_width, fpw);

 

 fclose(fpw);

 

 fpin = fopen("F:\\input.raw", "wb");

fwrite(input_to_fft, sizeof(int32_t),row_width*image_height, fpin);

 

   fclose(fpin);

}


Could you please point out the source of error..

 

Thank you

Sohal

  • hello, Sohal

    the scale by 2^log2(n) is to make sure the fft and ifft does not overflow. It depends on your input data range. If your data is within 23 bit, then you do not need to scale. If you still scale the input, then you will lose precision. The scale by 3 in the example is just for the data range used in the example.

    and in your code, there is an ifft directly after fft, I would suggest you to check the fft output (ifft input) signal range, to make sure the ifft does not overflow.

    thanks and regards,

    Xiaozhou Huang