I have a C simulation running on PC.
Part of this simulation is doing fft of 16 bit samples.
I found on the TMS320C64x DSP Library Programmer’s Reference a "C-equivalent" code for DSP_fft16x16r function.
http://focus.ti.com/lit/ug/spru565b/spru565b.pdf
The problem is that the result is not bit exact with the DSP output.
I noticed that there is a C-code of two different functions for generating the twiddle factors.
The first one one produced correct results on the DSP , and the second produced correct results on the PC.
Problem is the results (with different twiddle factors) are not bit exact!!!
1.:
int gen_twiddle(short *w, int n, double scale)
{
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(scale * cos(6.0 * PI * (i + j) / n));
w[k + 10] = d2s(scale * sin(6.0 * PI * (i + j) / n));
w[k + 9] = d2s(scale * cos(6.0 * PI * (i ) / n));
w[k + 8] = d2s(scale * sin(6.0 * PI * (i ) / n));
w[k + 7] = d2s(scale * cos(4.0 * PI * (i + j) / n));
w[k + 6] = d2s(scale * sin(4.0 * PI * (i + j) / n));
w[k + 5] = d2s(scale * cos(4.0 * PI * (i ) / n));
w[k + 4] = d2s(scale * sin(4.0 * PI * (i ) / n));
w[k + 3] = d2s(scale * cos(2.0 * PI * (i + j) / n));
w[k + 2] = d2s(scale * sin(2.0 * PI * (i + j) / n));
w[k + 1] = d2s(scale * cos(2.0 * PI * (i ) / n));
w[k + 0] = d2s(scale * sin(2.0 * PI * (i ) / n));
k += 12;
}
}
return k;
}
2.
void tw_gen(short * w, int N)
{
int i,j, k;
double x_t, y_t, theta1, theta2, theta3;
const double M = 32767.5;
//const double M = 16383.0;
for (j=1, k=0; j <= N>>2; j = j<<2)
{
for (i=0; i < N>>2; i+=j)
{
theta1 = 2*PI*i/N;
x_t = M*cos(theta1);
y_t = M*sin(theta1);
w[k] = (short)x_t;
w[k+1] = (short)y_t;
theta2 = 4*PI*i/N;
x_t = M*cos(theta2);
y_t = M*sin(theta2);
w[k+2] = (short)x_t;
w[k+3] = (short)y_t;
theta3 = 6*PI*i/N;
x_t = M*cos(theta3);
y_t = M*sin(theta3);
w[k+4] = (short)x_t;
w[k+5] = (short)y_t;
k+=6;
}
}
}
Why are the twiddles different? and how can i be bit exact with the PC implementation?
many thanks.
Oz barak.