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.

Why are there '-' signs only at the big endian part?

Hi,

When I read the example file of DSPLIB for C66, gen_twiddle_fft16x32.c, I do not understand the minus sign on line w[k + 3] and w[k + 1] at the big endian part. I only realize that big endian will reverse the access sequence of the elements. Why are there '-' signs at the big endian part?

Thanks,

/* ======================================================================== */
/* GEN_TWIDDLE -- Generate twiddle factors for TI's custom FFTs. */
/* */
/* USAGE */
/* This routine is called as follows: */
/* */
/* int gen_twiddle_fft16x32(short *w, int n) */
/* */
/* short *w Pointer to twiddle-factor array */
/* int n Size of FFT */
/* */
/* The routine will generate the twiddle-factors directly into the */
/* array you specify. The array needs to be approximately 2*N */
/* elements long. (The actual size, which is slightly smaller, is */
/* returned by the function.) */
/* ======================================================================== */
#ifdef _LITTLE_ENDIAN
int gen_twiddle_fft16x32(short *w, int n)
{
int i, j, k;
double M = 32767.5;

for (j = 1, k = 0; j < n >> 2; j = j << 2) {
for (i = 0; i < n >> 2; i += 2*j) {

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 += 4;
}
}
return k;
}
#else
int gen_twiddle_fft16x32(short *w, int n)
{
int i, j, k;
double M = 32767.5;

for (j = 1, k = 0; j < n >> 2; j = j << 2) {
for (i = 0; i < n >> 2; i += 2*j) {

w[k + 3] =-d2s(M * sin(2.0 * PI * (i+j) / n));
w[k + 2] = d2s(M * cos(2.0 * PI * (i+j) / n));

w[k + 1] =-d2s(M * sin(2.0 * PI * i / n));
w[k + 0] = d2s(M * cos(2.0 * PI * i / n));

k += 4;
}
}
return k;
}
#endif

  • Robert,

    Finding the author may be difficult. Do you get the same answer in both cases?

    Regards,
    RandyP

  • If I recall correctly, the actual routine doesn't change, and the Double Word accesses grabbing the Byte's of big endian data are going to be out of order.  And the 4-point butter fly is used, and when we look at the smallest butterflies we see there are 3 Addition and 1 Subtraction in the mix.  Well, the coeff, that would have been the one subtraction is now in the addition spot, so make the coef for it be negative and it's fixed.  But the one that would have been a subtraction is now in an addition spot, so we got to make the coef negative to make it effectively a subtraction.

    Note, this code base has been in place for years with C62x, C64x, C64x+ devices before C66x.

    EDIT: I just saw Randy's post, and while I didn't write this one for a 16x32FFT, I wrote what was probably the first optimized FFT routine on C6201 about 17yrs ago and I used the technique I described for the twiddle factors to avoid having two separate hand optimized FFT routines (one for big endian and one for little endian.)

    Best Regards,
    Chad