Dear community,
I am using a C6713 DSK, CCS 2.21 with DSPLIB (installed a few days ago - assuming a late-ish version). I have attempted implement a simple fft code to make sure I fully understand its workings before I use it in my application.
I am having difficulty ensuring that it is working correctly - when comparing it to matlab results. I think part of my confusion is the representation of numbers on the C6713 when they are truncated or something like that.
I have tested the fft using some simple sequences,
1) All zero input vector --> result: all zero out --> Conc: Correct
2) All zero, except the first value is 1+j0 --> output all 1+j0 --> Correct
3) All zero, except first value is j1 --> output all j1 --> Correct
4) So without knowing what to test next, I tried all 1+j0 --> expect [ N 0 0 0 ...] (N=size of fft) --> result:
[0] 1.0 [1] 0.0 [2] -1.010972e+37 [3] 1.053691e+37 [4] 7.49285e+27 [5] -1.299105e+27 ....
So not what I expect, some very large numbers which could be zero.
What does my testing suggest is wrong? or am I miss reading the output? Any suggestions or input would be really great.
Code, the main, and then the functions (sorry for posting it here - but the upload attach would not work!)
for (i=0; i< (N-1); i++)
{
v[2*i] = (float)1.0; // real
v[2*i+1] = 0.0; // imag
}
//v[2] = 1;
bitrev_index(table,N);
gen_twiddle(w, N);
bit_rev(w,N>>1); // OR bit_rev(w,N);
// FFT
DSPF_sp_cfftr2_dit(v,w,N);
DSPF_sp_bitrev_cplx((double*)v,table,N);
void bit_rev(float* x, int n)
{
int i, j, k;
float rtemp, itemp;
j = 0;
for(i=1; i < (n-1); i++)
{
k = n >> 1;
while(k <= j)
{
j -= k;
k >>= 1;
}
j += k;
if(i < j)
{
rtemp = x[j*2];
x[j*2] = x[i*2];
x[i*2] = rtemp;
itemp = x[j*2+1];
x[j*2+1] = x[i*2+1];
x[i*2+1] = itemp;
}
}
}
int gen_twiddle(float *w, int n)
{
double delta = 2 * PI / n;
int i;
for(i = 0; i < n/2; i++)
{
w[2 * i + 1] = sin(i * delta);
w[2 * i] = cos(i * delta);
}
return n;
}
void bitrev_index(short *index, int n)
{
int i, j, k, radix = 2;
short nbits, nbot, ntop, ndiff, n2, raddiv2;
nbits = 0;
i = n;
while (i > 1)
{
i = i >> 1;
nbits++;
}
raddiv2 = radix >> 1;
nbot = nbits >> raddiv2;
nbot = nbot << raddiv2 - 1;
ndiff = nbits & raddiv2;
ntop = nbot + ndiff;
n2 = 1 << ntop;
index[0] = 0;
for ( i = 1, j = n2/radix + 1; i < n2 - 1; i++)
{
index[i] = j - 1;
for (k = n2/radix; k*(radix-1) < j; k /= radix)
j -= k*(radix-1);
j += k;
}
index[n2 - 1] = n2 - 1;
}
void main()
{
int i;
printf("\n BEGIN \n");
DSK6713_LED_init(); //init LED from BSL
for (i=0; i< (N-1); i++)
{
v[2*i] = (float)1.0; // real
v[2*i+1] = 0.0; // imag
}
//v[2] = 1;
bitrev_index(table,N);
gen_twiddle(w, N);
bit_rev(w,N>>1); // OR bit_rev(w,N);
// FFT
DSPF_sp_cfftr2_dit(v,w,N);
DSPF_sp_bitrev_cplx((double*)v,table,N);
//Note that you must align the data and the twiddle-factor's on a 8-byteboundary.
for (i=0; i< N; i+=2)
{
printf("%f %f\n", v[i],v[i+1]);
}