Hi everybody,
I am using the C6416 DSK with CCS 3.1.0 and the C6400 DSPLIB. I wanted to use the function DSP_fft16x16t. I included -l"dsp64x.lib" in my project and it compiles and runs fine. However, the values produced by the FFT seem to be wrong compared to another FFT function and MATLAB. The relevant code parts are basically:
// double word data alignment
#pragma DATA_ALIGN(pin,8);
#pragma DATA_ALIGN(pout,8);
#pragma DATA_ALIGN(w,8);
// global variables for input, output and twiddle factors
Int16* pin;
Int16* pout;
Int16* w;
void main()
{
// local variables
unsigned int i;
float* input;
float* output;
int fftRadix2Factor = 6;
int fftLength = 1 << fftRadix2Factor; // 64 point fft
// ... initialization of board and allocation of pointers etc.
// creating an impulse as input
for (i=0; i<fftLength; ++i)
{
input[2*i] = 0.0;
input[2*i+1] = 0.0;
}
input[0] = 0.5;
DSP_fltoq15(input,pin,2*fftLength); // transform to Q.15 values
for (i=0; i<2*fftLength; ++i) // scaling according to DSPLIB programmer's reference
{
pin[i] = (pin[i] >> fftRadix2Factor);
}
gen_twiddle(w, fftLength); // twiddle factors according to the function provided in "dsp_fft16x16t.h"
DSP_fft16x16t(w, fftLength, pin, pout); // apply fft
DSP_q15tofl(pout,output,2*fftLength); // transform back to floating point values
// put out output values
for (i=0; i<fftLength; ++i)
{
printf("FFT Bin %i: %f +%f j\n", i, output[2*i],output[2*i+1]);
}
}
This produces the following values:
FFT Bin 0: 0.007813 +0.000000 j
FFT Bin 1: 0.000000 +0.000000 j
FFT Bin 2: -0.007813 +-0.007813 j
FFT Bin 3: -0.007813 +0.007813 j
FFT Bin 4: 0.000000 +0.000000 j
FFT Bin 5: 0.000000 +0.000000 j
FFT Bin 6: 0.000000 +0.000000 j
FFT Bin 7: 0.000000 +0.000000 j
FFT Bin 8: 0.000000 +0.000000 j
FFT Bin 9: 0.000000 +0.000000 j
FFT Bin 10: 0.000000 +0.000000 j
FFT Bin 11: 0.000000 +0.000000 j
FFT Bin 12: 0.000000 +0.000000 j
FFT Bin 13: 0.000000 +0.000000 j
FFT Bin 14: 0.000000 +0.000000 j
FFT Bin 15: 0.000000 +0.000000 j
FFT Bin 16: 0.007813 +0.000000 j
FFT Bin 17: 0.000000 +0.000000 j
FFT Bin 18: -0.007813 +-0.007813 j
FFT Bin 19: -0.007813 +0.007813 j
FFT Bin 20: 0.000000 +0.000000 j
FFT Bin 21: 0.000000 +0.000000 j
FFT Bin 22: 0.000000 +0.000000 j
FFT Bin 23: 0.000000 +0.000000 j
FFT Bin 24: 0.000000 +0.000000 j
FFT Bin 25: 0.000000 +0.000000 j
FFT Bin 26: 0.000000 +0.000000 j
FFT Bin 27: 0.000000 +0.000000 j
FFT Bin 28: 0.000000 +0.000000 j
FFT Bin 29: 0.000000 +0.000000 j
FFT Bin 30: 0.000000 +0.000000 j
FFT Bin 31: 0.000000 +0.000000 j
FFT Bin 32: 0.007813 +0.000000 j
FFT Bin 33: 0.000000 +0.000000 j
FFT Bin 34: -0.007813 +-0.007813 j
FFT Bin 35: -0.007813 +0.007813 j
FFT Bin 36: 0.000000 +0.000000 j
FFT Bin 37: 0.000000 +0.000000 j
FFT Bin 38: 0.000000 +0.000000 j
FFT Bin 39: 0.000000 +0.000000 j
FFT Bin 40: 0.000000 +0.000000 j
FFT Bin 41: 0.000000 +0.000000 j
FFT Bin 42: 0.000000 +0.000000 j
FFT Bin 43: 0.000000 +0.000000 j
FFT Bin 44: 0.000000 +0.000000 j
FFT Bin 45: 0.000000 +0.000000 j
FFT Bin 46: 0.000000 +0.000000 j
FFT Bin 47: 0.000000 +0.000000 j
FFT Bin 48: 0.007813 +0.000000 j
FFT Bin 49: 0.000000 +0.000000 j
FFT Bin 50: -0.007813 +-0.007813 j
FFT Bin 51: -0.007813 +0.007813 j
FFT Bin 52: 0.000000 +0.000000 j
FFT Bin 53: 0.000000 +0.000000 j
FFT Bin 54: 0.000000 +0.000000 j
FFT Bin 55: 0.000000 +0.000000 j
FFT Bin 56: 0.000000 +0.000000 j
FFT Bin 57: 0.000000 +0.000000 j
FFT Bin 58: 0.000000 +0.000000 j
FFT Bin 59: 0.000000 +0.000000 j
FFT Bin 60: 0.000000 +0.000000 j
FFT Bin 61: 0.000000 +0.000000 j
FFT Bin 62: 0.000000 +0.000000 j
FFT Bin 63: 0.000000 +0.000000 j
The fft on the same signal in matlab gives constant 0.5, which is fftLength*0.007813. Therefore, my question is, whether I need to apply some sort of scaling in between, to avoid overflow or something during the computation of the fft? Or is there anything else wrong in my usage of the DSPLIB I didn't spot? When I omit the scaling recommended in the programmer's reference, the output values are the same, but multiplied with fftLength. By the way, when I send in a constant real signal, say input[2*i] = 0.5, the output is as expected an impulse at bin 0.
Thank you very much and kind regards,
Matthias