DSPRelated.com
Forums

DSP_fft16x16t problem! and it is eating my input!

Started by Yahia Tachwali November 20, 2008
Hello everyone,

I am struggling to get the DSP_fft16x16t function in dsplib for c64x working... I am using the C6415 device cycle accurate simulator to verify the code.. The problem is that the output of DSP_fft16x16t does show the accurate results for some input and does not show the right FFT for others!!!!!!. One unhealthy symptom I found is that the DSP_fft16x16t function is overwriting the input data. I do know what I missing to avoid that. I am using very basic memory mapping CMD file. The code and cmd file is listed at the end of the post. To be more descriptive about the problem. I have tried to feed the program with different simple inputs and it fails for some frequencies:

1- when the input is dc=5.... the FFT output is right; one spike at the first element of the output with value equal to (5*128)^2
2- when the input is sinusoid scaled to 100 and frequency = sampling frequency/2...the FFT output is right; one spike at the 64th element of the output
3- when the input is sinusoid scaled to 100 and frequency = sampling frequency/4...the FFT output is right; two spikes at the 32th and 96th elements of the output
4- when the input is sinusoid scaled to 100 and frequency = sampling frequency/8...the FFT output is not totally right!!!! ; I got 3 spikes of different amplitude at

value d12 @ 16 (this sounds a good one)
value Y23 @ 48 (I do not know from where this one come!!!!)
value $52 @ 112 (this sounds a good one but why it is too small!!!)

I am suspecting two issues here... one is the twiddle factor array that I am feeding the DSP_fft16x16t and the other reason is the memory mapping of my data x,y since the values of x matrix got overwritten after running the DSP_fft16x16t function. Any suggestions or help pleaaaaase!!!!!!
/******************************************************************************
the code
******************************************************************************/
#include
#include "dsp_fft16x16t.h"
#define size 128
# define PI (3.14159265358979323846)

#pragma DATA_ALIGN(x, 8); //input data
short x[2*size];
#pragma DATA_ALIGN(y, 8);//output data
short y[2*size]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
#pragma DATA_ALIGN(z, 8); //FFT amplitude data
short z[2*size];
#pragma DATA_ALIGN(w, 8);
short w[2*size]; //twiddle factor
void main ()
{
int i;
void gen_twiddle(short *w, int n) ;
short d2s(double d);
//generating the input data
for(i=0;i<2*size;i=i+2)
{
x[i](100*cos((size/8)*PI*i/size));
x[i+1]=0;
}
gen_twiddle(w, size);
DSP_fft16x16t(w,size,x,y);
for(i=0;i {
z[i]=sqrt(y[2*i]*y[2*i]+y[2*i+1]*y[2*i+1]);
}
}

short d2s(double d)
{
d = floor(0.5 + d); // Explicit rounding to integer //
if (d >= 32767.0) return 32767;
if (d <= -32768.0) return -32768;
return (short)d;
}

void gen_twiddle(short *w, int n)
{
double M = 32767.5;
int i, j, k;

for (j = 1, k = 0; j < n >> 2; j = j << 2)
{
for (i = 0; i < n >> 2; i += j << 1)
{
w[k + 11] = d2s(M * cos(6.0 * PI * (i + j) / n));
w[k + 10] = d2s(M * sin(6.0 * PI * (i + j) / n));
w[k + 9] = d2s(M * cos(6.0 * PI * (i ) / n));
w[k + 8] = d2s(M * sin(6.0 * PI * (i ) / n));
w[k + 7] = d2s(M * cos(4.0 * PI * (i + j) / n));
w[k + 6] = d2s(M * sin(4.0 * PI * (i + j) / n));
w[k + 5] = d2s(M * cos(4.0 * PI * (i ) / n));
w[k + 4] = d2s(M * sin(4.0 * PI * (i ) / n));
w[k + 3] = d2s(M * cos(2.0 * PI * (i + j) / n));
w[k + 2] = d2s(M * sin(2.0 * PI * (i + j) / n));
w[k + 1] = d2s(M * cos(2.0 * PI * (i ) / n));
w[k + 0] = d2s(M * sin(2.0 * PI * (i ) / n));
k += 12;
}
}
w[2*n - 1] = w[2*n - 3] = w[2*n - 5] = 32767;
w[2*n - 2] = w[2*n - 4] = w[2*n - 6] = 0;
}
/******************************************************************************
the cmd file
******************************************************************************/
MEMORY
{
ISRAM : origin = 0x0, len = 0x100000
}
SECTIONS
{
.vectors > ISRAM
.text > ISRAM
.bss > ISRAM
.cinit > ISRAM
.const > ISRAM
.far > ISRAM
.stack > ISRAM
.cio > ISRAM
.sysmem > ISRAM
}
OK Guys..... sounds like I figured out what is the problem!!! but I
kindly request the DSP expert out there to help me understand one
unclear thing left out...

The problem is in the twiddle factor generator function.... I have
decided to try sizeQ2 in order to compare its results with a TI
application note (focus.ti.com.cn/cn/lit/an/spra884a/spra884a.pdf) that
shows an input and output example of the FFT function.... I have used
the twiddle factor generator utility (DOS based program) provided with
the DSPLIB in bin folder. I got the twiddle function matrix w of size
[2*510]!! I used it as is in my code and the FFT worked perfectly!

My question to the DSP experts, why is the size of w 2*510 and not
2*512? I am using FFT size 512 and I am expecting associated complex
matrix to have the size of 2*512? How come this one is working?

-Yahia

Yahia Tachwali wrote:

>Hello everyone,
>
>I am struggling to get the DSP_fft16x16t function in dsplib for c64x working... I am using the C6415 device cycle accurate simulator to verify the code.. The problem is that the output of DSP_fft16x16t does show the accurate results for some input and does not show the right FFT for others!!!!!!. One unhealthy symptom I found is that the DSP_fft16x16t function is overwriting the input data. I do know what I missing to avoid that. I am using very basic memory mapping CMD file. The code and cmd file is listed at the end of the post. To be more descriptive about the problem. I have tried to feed the program with different simple inputs and it fails for some frequencies:
>
>1- when the input is dc=5.... the FFT output is right; one spike at the first element of the output with value equal to (5*128)^2
>2- when the input is sinusoid scaled to 100 and frequency = sampling frequency/2...the FFT output is right; one spike at the 64th element of the output
>3- when the input is sinusoid scaled to 100 and frequency = sampling frequency/4...the FFT output is right; two spikes at the 32th and 96th elements of the output
>4- when the input is sinusoid scaled to 100 and frequency = sampling frequency/8...the FFT output is not totally right!!!! ; I got 3 spikes of different amplitude at
>
>value d12 @ 16 (this sounds a good one)
>value Y23 @ 48 (I do not know from where this one come!!!!)
>value $52 @ 112 (this sounds a good one but why it is too small!!!)
>
>I am suspecting two issues here... one is the twiddle factor array that I am feeding the DSP_fft16x16t and the other reason is the memory mapping of my data x,y since the values of x matrix got overwritten after running the DSP_fft16x16t function. Any suggestions or help pleaaaaase!!!!!!
>/******************************************************************************
>the code
>******************************************************************************/
>#include
>#include "dsp_fft16x16t.h"
>#define size 128
># define PI (3.14159265358979323846)
>
>#pragma DATA_ALIGN(x, 8); //input data
>short x[2*size];
>#pragma DATA_ALIGN(y, 8);//output data
>short y[2*size]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
>#pragma DATA_ALIGN(z, 8); //FFT amplitude data
>short z[2*size];
>#pragma DATA_ALIGN(w, 8);
>short w[2*size]; //twiddle factor
>void main ()
>{
> int i;
> void gen_twiddle(short *w, int n) ;
> short d2s(double d);
>//generating the input data
> for(i=0;i<2*size;i=i+2)
> {
> x[i](100*cos((size/8)*PI*i/size));
> x[i+1]=0;
> }
> gen_twiddle(w, size);
> DSP_fft16x16t(w,size,x,y);
> for(i=0;i > {
> z[i]=sqrt(y[2*i]*y[2*i]+y[2*i+1]*y[2*i+1]);
> }
>}
>
>short d2s(double d)
>{
> d = floor(0.5 + d); // Explicit rounding to integer //
> if (d >= 32767.0) return 32767;
> if (d <= -32768.0) return -32768;
>return (short)d;
>}
>
>void gen_twiddle(short *w, int n)
> {
> double M = 32767.5;
> int i, j, k;
>
> for (j = 1, k = 0; j < n >> 2; j = j << 2)
> {
> for (i = 0; i < n >> 2; i += j << 1)
> {
> w[k + 11] = d2s(M * cos(6.0 * PI * (i + j) / n));
> w[k + 10] = d2s(M * sin(6.0 * PI * (i + j) / n));
> w[k + 9] = d2s(M * cos(6.0 * PI * (i ) / n));
> w[k + 8] = d2s(M * sin(6.0 * PI * (i ) / n));
> w[k + 7] = d2s(M * cos(4.0 * PI * (i + j) / n));
> w[k + 6] = d2s(M * sin(4.0 * PI * (i + j) / n));
> w[k + 5] = d2s(M * cos(4.0 * PI * (i ) / n));
> w[k + 4] = d2s(M * sin(4.0 * PI * (i ) / n));
> w[k + 3] = d2s(M * cos(2.0 * PI * (i + j) / n));
> w[k + 2] = d2s(M * sin(2.0 * PI * (i + j) / n));
> w[k + 1] = d2s(M * cos(2.0 * PI * (i ) / n));
> w[k + 0] = d2s(M * sin(2.0 * PI * (i ) / n));
> k += 12;
> }
> }
> w[2*n - 1] = w[2*n - 3] = w[2*n - 5] = 32767;
> w[2*n - 2] = w[2*n - 4] = w[2*n - 6] = 0;
>}
>/******************************************************************************
>the cmd file
>******************************************************************************/
>MEMORY
>{
> ISRAM : origin = 0x0, len = 0x100000
>}
>SECTIONS
>{
> .vectors > ISRAM
> .text > ISRAM
> .bss > ISRAM
> .cinit > ISRAM
> .const > ISRAM
> .far > ISRAM
> .stack > ISRAM
> .cio > ISRAM
> .sysmem > ISRAM
>}

>
>
>