DSPRelated.com
Forums

problem about DSP_fft16x16

Started by jogg...@gmail.com December 13, 2009
Hi,all
I am trying to use FFT functions from dsplib_v210 and run into some problems. The result generated by DSP_fft16x16 and DSP_fft16x16r is significantly different from the result generated by Matlab, and minor difference is acceptable because of computation precision. The results generated by DSP_fft16x32 and DSP_fft32x32 are correct.

I am using FFT for the first time and have several choices for it.
When should extended precision be chose?
Thanks in advance.

Regards
Jogging

_____________________________________
Thanks, Khawar
My program is very simple and is adapted from the test example provided by
Ti. I run it on the PC.
DSP_fft16x16 is for a 16 point input.
The input is just a sequence of 1.
But the result is incorrect.
The following is my code.

Thanks
Jogging

int TestFFT16x16()
{
// clock_t t_overhead, t_start, t_stop;
// clock_t t_cn, t_i, t_sa;
int i, j, k, m, n, radix, fail;

/* --------------------------------
*/
/* Compute the overhead of calling clock() twice to get timing info.
*/
/* --------------------------------
*/
// t_start = clock();
// t_stop = clock();
// t_overhead = t_stop - t_start;

for (j = 0; j < NUM_INPUTS; j++) {
for (i = 0; i < 2*N + 2*PAD; i++)
{
// x[j][i] = x[j][i] >> 4;
x[j][i] = 0;
if((i >= PAD) && (i < PAD+32))
x[j][i] = 1;//(i-PAD);
}
}

for (j = 16, k = 1, fail = 0; j <= N; k++, j *= 2) {
for (n = 31, m = 1; (j & (1 << n)) == 0; n--, m++)
;
radix = m & 1 ? 2 : 4;

/*
-------------------------------- */
/* Generate twiddle factors for fft of size
'j' */
/*
-------------------------------- */
gen_twiddle_fft16x16(&w_fft[0][PAD], j);
gen_twiddle_ifft16x16(&w_ifft[0][PAD], j);

/*
-------------------------------- */
/* Copy vector to all
inputs. */
/*
-------------------------------- */
memcpy(x_cn, x, sizeof(x_cn));
// memcpy(x_i, x, sizeof(x_i));
// memcpy(x_sa, x, sizeof(x_cn));

// memcpy(y_i, y_cn, sizeof(y_i));
// memcpy(y_sa, y_cn, sizeof(y_sa));
/*
-------------------------------- */
/* Check the results arrays, and report any
failures. */
/*
-------------------------------- */
for(i = 0; i < NUM_INPUTS; i++) {
// t_cn = time_cn(i, j) - t_overhead;
DSP_fft16x16_cn(&w_fft[i][PAD], j,
&x_cn[i][PAD], &y_cn[i][PAD]);
DSP_ifft16x16_cn(&w_ifft[i][PAD], j,
&y_cn[i][PAD], &z_cn[i][PAD]);
// t_i = time_i(i, j) - t_overhead;
// t_sa = time_sa(i, j) - t_overhead;
}

// printf("DSP_fft16x16\tIter#: %d\t", k);
//
// if (memcmp(y_cn, y_i, sizeof(y_cn))) {
// fail++;
// printf("Result Failure (y_i) ");
// }
// else
// printf("Result Successful (y_i) ");
//
// if (memcmp(y_cn, y_sa, sizeof(y_cn))) {
// fail++;
// printf("Result Failure (y_sa) ");
// }
// else
// printf("Result Successful (y_sa) ");
//
//
// printf("\tRadix = %d\tN = %d\tnatC: %d\tintC: %d\tSA: %d\n",
radix, j, t_cn, t_i, t_sa);
}

return (fail);
}

On Tue, Dec 15, 2009 at 4:57 AM, khawer12 wrote:

> hello jogging,
>
> The choice of precision is dependent on the application. If the application
> requires precision which can only be met by using DSP_fft32x32 then you will
> have to use that function.
> regarding DSP_fft16x16 function, it works fine. just make sure that the
> twiddle factor array is correct.
> If you are still not been able to solve your problem after using correct
> twiddle factor array then post your code on the group.
> i hope someone will come up with some idea to correct it.
> Regards,
> Khawar Shahzad.
> --- In c..., joggingsong@... wrote:
> >
> > Hi,all
> > I am trying to use FFT functions from dsplib_v210 and run into some
> problems. The result generated by DSP_fft16x16 and DSP_fft16x16r is
> significantly different from the result generated by Matlab, and minor
> difference is acceptable because of computation precision. The results
> generated by DSP_fft16x32 and DSP_fft32x32 are correct.
> >
> > I am using FFT for the first time and have several choices for it.
> > When should extended precision be chose?
> > Thanks in advance.
> >
> > Regards
> > Jogging
>

_____________________________________
Jogging-

> My program is very simple and is adapted from the test example provided by
> Ti. I run it on the PC.

Can you explan "run it on the PC"? Using CCS? Or some other program for comparison purposes?

> DSP_fft16x16 is for a 16 point input.
> The input is just a sequence of 1.
> But the result is incorrect.
> The following is my code.

As there are a number of "DSP_fft...something" routines, suggest to do this search:

DSP_fft site:dsprelated.com

You should see a lot of previous posts about using these functions. My guess is that you have a data alignment issue.

-Jeff

> int TestFFT16x16()
> {
> // clock_t t_overhead, t_start, t_stop;
> // clock_t t_cn, t_i, t_sa;
> int i, j, k, m, n, radix, fail;
>
> /* --------------------------------
> */
> /* Compute the overhead of calling clock() twice to get timing info.
> */
> /* --------------------------------
> */
> // t_start = clock();
> // t_stop = clock();
> // t_overhead = t_stop - t_start;
>
> for (j = 0; j < NUM_INPUTS; j++) {
> for (i = 0; i < 2*N + 2*PAD; i++)
> {
> // x[j][i] = x[j][i] >> 4;
> x[j][i] = 0;
> if((i >= PAD) && (i < PAD+32))
> x[j][i] = 1;//(i-PAD);
> }
> }
>
> for (j = 16, k = 1, fail = 0; j <= N; k++, j *= 2) {
> for (n = 31, m = 1; (j & (1 << n)) == 0; n--, m++)
> ;
> radix = m & 1 ? 2 : 4;
>
> /*
> -------------------------------- */
> /* Generate twiddle factors for fft of size
> 'j' */
> /*
> -------------------------------- */
> gen_twiddle_fft16x16(&w_fft[0][PAD], j);
> gen_twiddle_ifft16x16(&w_ifft[0][PAD], j);
>
> /*
> -------------------------------- */
> /* Copy vector to all
> inputs. */
> /*
> -------------------------------- */
> memcpy(x_cn, x, sizeof(x_cn));
> // memcpy(x_i, x, sizeof(x_i));
> // memcpy(x_sa, x, sizeof(x_cn));
>
> // memcpy(y_i, y_cn, sizeof(y_i));
> // memcpy(y_sa, y_cn, sizeof(y_sa));
> /*
> -------------------------------- */
> /* Check the results arrays, and report any
> failures. */
> /*
> -------------------------------- */
> for(i = 0; i < NUM_INPUTS; i++) {
> // t_cn = time_cn(i, j) - t_overhead;
> DSP_fft16x16_cn(&w_fft[i][PAD], j,
> &x_cn[i][PAD], &y_cn[i][PAD]);
> DSP_ifft16x16_cn(&w_ifft[i][PAD], j,
> &y_cn[i][PAD], &z_cn[i][PAD]);
> // t_i = time_i(i, j) - t_overhead;
> // t_sa = time_sa(i, j) - t_overhead;
> }
>
> // printf("DSP_fft16x16\tIter#: %d\t", k);
> //
> // if (memcmp(y_cn, y_i, sizeof(y_cn))) {
> // fail++;
> // printf("Result Failure (y_i) ");
> // }
> // else
> // printf("Result Successful (y_i) ");
> //
> // if (memcmp(y_cn, y_sa, sizeof(y_cn))) {
> // fail++;
> // printf("Result Failure (y_sa) ");
> // }
> // else
> // printf("Result Successful (y_sa) ");
> //
> //
> // printf("\tRadix = %d\tN = %d\tnatC: %d\tintC: %d\tSA: %d\n",
> radix, j, t_cn, t_i, t_sa);
> }
>
> return (fail);
> }
>
> On Tue, Dec 15, 2009 at 4:57 AM, khawer12 wrote:
>
>> hello jogging,
>>
>> The choice of precision is dependent on the application. If the application
>> requires precision which can only be met by using DSP_fft32x32 then you will
>> have to use that function.
>> regarding DSP_fft16x16 function, it works fine. just make sure that the
>> twiddle factor array is correct.
>> If you are still not been able to solve your problem after using correct
>> twiddle factor array then post your code on the group.
>> i hope someone will come up with some idea to correct it.
>> Regards,
>> Khawar Shahzad.
>> --- In c..., joggingsong@... wrote:
>> >
>> > Hi,all
>> > I am trying to use FFT functions from dsplib_v210 and run into some
>> problems. The result generated by DSP_fft16x16 and DSP_fft16x16r is
>> significantly different from the result generated by Matlab, and minor
>> difference is acceptable because of computation precision. The results
>> generated by DSP_fft16x32 and DSP_fft32x32 are correct.
>> >
>> > I am using FFT for the first time and have several choices for it.
>> > When should extended precision be chose?
>> > Thanks in advance.
>> >
>> > Regards
>> > Jogging
>> >

_____________________________________
Jogging-

> For each functions about FFT calculation, C code of each function
> is available. I run it on the PC.
>
> After reading the document several times, I think the problem
> is caused by the fact
> "All stages except the last one scale by two the stage output
> data". I need to right shift the result to obtain correct result.

My guess is the doc is saying that:

-input should be 16-bit (short int)

-output will be 16-bit, with no need
for scaling since scaling is
handled inherently

As a note, some of the TI functions, when implemented as C code, require a final right shift by 15 to get 16-bit
output; i.e. they are accumulating 32-bit values internally. This one sounds different.

> The document also says that All data are in short precision or Q.15 format.
> What does it mean? The data must be in the range of (-1,1)?

Yes, input should be -32768 to 32767. So if you have input data between -1.0 and 1.0, then you should multiply by
32767 before running the TI code.

-Jeff
> On Fri, Dec 18, 2009 at 10:56 PM, Jeff Brower wrote:
>
>> Jogging-
>> > My program is very simple and is adapted from the test example provided
>> by
>> > Ti. I run it on the PC.
>>
>> Can you explan "run it on the PC"? Using CCS? Or some other program for
>> comparison purposes?
>> > DSP_fft16x16 is for a 16 point input.
>> > The input is just a sequence of 1.
>> > But the result is incorrect.
>> > The following is my code.
>>
>> As there are a number of "DSP_fft...something" routines, suggest to do this
>> search:
>>
>> DSP_fft site:dsprelated.com
>>
>> You should see a lot of previous posts about using these functions. My
>> guess is that you have a data alignment issue.
>>
>> -Jeff
>> > int TestFFT16x16()
>> > {
>> > // clock_t t_overhead, t_start, t_stop;
>> > // clock_t t_cn, t_i, t_sa;
>> > int i, j, k, m, n, radix, fail;
>> >
>> > /* ----------------------
>> > */
>> > /* Compute the overhead of calling clock() twice to get timing info.
>> > */
>> > /* ----------------------
>> > */
>> > // t_start = clock();
>> > // t_stop = clock();
>> > // t_overhead = t_stop - t_start;
>> >
>> > for (j = 0; j < NUM_INPUTS; j++) {
>> > for (i = 0; i < 2*N + 2*PAD; i++)
>> > {
>> > // x[j][i] = x[j][i] >> 4;
>> > x[j][i] = 0;
>> > if((i >= PAD) && (i < PAD+32))
>> > x[j][i] = 1;//(i-PAD);
>> > }
>> > }
>> >
>> > for (j = 16, k = 1, fail = 0; j <= N; k++, j *= 2) {
>> > for (n = 31, m = 1; (j & (1 << n)) == 0; n--, m++)
>> > ;
>> > radix = m & 1 ? 2 : 4;
>> >
>> > /*
>> > ---------------------- */
>> > /* Generate twiddle factors for fft of size
>> > 'j' */
>> > /*
>> > ---------------------- */
>> > gen_twiddle_fft16x16(&w_fft[0][PAD], j);
>> > gen_twiddle_ifft16x16(&w_ifft[0][PAD], j);
>> >
>> > /*
>> > ---------------------- */
>> > /* Copy vector to all
>> > inputs. */
>> > /*
>> > ---------------------- */
>> > memcpy(x_cn, x, sizeof(x_cn));
>> > // memcpy(x_i, x, sizeof(x_i));
>> > // memcpy(x_sa, x, sizeof(x_cn));
>> >
>> > // memcpy(y_i, y_cn, sizeof(y_i));
>> > // memcpy(y_sa, y_cn, sizeof(y_sa));
>> > /*
>> > ---------------------- */
>> > /* Check the results arrays, and report any
>> > failures. */
>> > /*
>> > ---------------------- */
>> > for(i = 0; i < NUM_INPUTS; i++) {
>> > // t_cn = time_cn(i, j) - t_overhead;
>> > DSP_fft16x16_cn(&w_fft[i][PAD], j,
>> > &x_cn[i][PAD], &y_cn[i][PAD]);
>> > DSP_ifft16x16_cn(&w_ifft[i][PAD], j,
>> > &y_cn[i][PAD], &z_cn[i][PAD]);
>> > // t_i = time_i(i, j) - t_overhead;
>> > // t_sa = time_sa(i, j) - t_overhead;
>> > }
>> >
>> > // printf("DSP_fft16x16\tIter#: %d\t", k);
>> > //
>> > // if (memcmp(y_cn, y_i, sizeof(y_cn))) {
>> > // fail++;
>> > // printf("Result Failure (y_i) ");
>> > // }
>> > // else
>> > // printf("Result Successful (y_i) ");
>> > //
>> > // if (memcmp(y_cn, y_sa, sizeof(y_cn))) {
>> > // fail++;
>> > // printf("Result Failure (y_sa) ");
>> > // }
>> > // else
>> > // printf("Result Successful (y_sa) ");
>> > //
>> > //
>> > // printf("\tRadix = %d\tN = %d\tnatC: %d\tintC: %d\tSA: %d\n",
>> > radix, j, t_cn, t_i, t_sa);
>> > }
>> >
>> > return (fail);
>> > }
>> >
>> > On Tue, Dec 15, 2009 at 4:57 AM, khawer12 >
>> wrote:
>> >
>> >> hello jogging,
>> >>
>> >> The choice of precision is dependent on the application. If the
>> application
>> >> requires precision which can only be met by using DSP_fft32x32 then you
>> will
>> >> have to use that function.
>> >> regarding DSP_fft16x16 function, it works fine. just make sure that the
>> >> twiddle factor array is correct.
>> >> If you are still not been able to solve your problem after using correct
>> >> twiddle factor array then post your code on the group.
>> >> i hope someone will come up with some idea to correct it.
>> >>
>> >>
>> >> Regards,
>> >> Khawar Shahzad.
>> >>
>> >>
>> >> --- In c... , joggingsong@...
>> wrote:
>> >> >
>> >> > Hi,all
>> >> > I am trying to use FFT functions from dsplib_v210 and run into some
>> >> problems. The result generated by DSP_fft16x16 and DSP_fft16x16r is
>> >> significantly different from the result generated by Matlab, and minor
>> >> difference is acceptable because of computation precision. The results
>> >> generated by DSP_fft16x32 and DSP_fft32x32 are correct.
>> >> >
>> >> > I am using FFT for the first time and have several choices for it.
>> >> > When should extended precision be chose?
>> >> > Thanks in advance.
>> >> >
>> >> > Regards
>> >> > Jogging

_____________________________________
Thanks, Jeff

For each functions about FFT calculation, C code of each function is
available. I
run it on the PC.

After reading the document several times, I think the problem is caused by
the fact
"All stages except the last one scale by two the stage output data".
I need to right shift the result to obtain correct result.

The document also says that All data are in short precision or Q.15 format.
What does it mean? The data must be in the range of (-1,1)?
In practice, it is very likely that the input is beyond the range.

Best Regards
Jogging

On Fri, Dec 18, 2009 at 10:56 PM, Jeff Brower wrote:

> Jogging-
> > My program is very simple and is adapted from the test example provided
> by
> > Ti. I run it on the PC.
>
> Can you explan "run it on the PC"? Using CCS? Or some other program for
> comparison purposes?
> > DSP_fft16x16 is for a 16 point input.
> > The input is just a sequence of 1.
> > But the result is incorrect.
> > The following is my code.
>
> As there are a number of "DSP_fft...something" routines, suggest to do this
> search:
>
> DSP_fft site:dsprelated.com
>
> You should see a lot of previous posts about using these functions. My
> guess is that you have a data alignment issue.
>
> -Jeff
> > int TestFFT16x16()
> > {
> > // clock_t t_overhead, t_start, t_stop;
> > // clock_t t_cn, t_i, t_sa;
> > int i, j, k, m, n, radix, fail;
> >
> > /* ----------------------
> > */
> > /* Compute the overhead of calling clock() twice to get timing info.
> > */
> > /* ----------------------
> > */
> > // t_start = clock();
> > // t_stop = clock();
> > // t_overhead = t_stop - t_start;
> >
> > for (j = 0; j < NUM_INPUTS; j++) {
> > for (i = 0; i < 2*N + 2*PAD; i++)
> > {
> > // x[j][i] = x[j][i] >> 4;
> > x[j][i] = 0;
> > if((i >= PAD) && (i < PAD+32))
> > x[j][i] = 1;//(i-PAD);
> > }
> > }
> >
> > for (j = 16, k = 1, fail = 0; j <= N; k++, j *= 2) {
> > for (n = 31, m = 1; (j & (1 << n)) == 0; n--, m++)
> > ;
> > radix = m & 1 ? 2 : 4;
> >
> > /*
> > ---------------------- */
> > /* Generate twiddle factors for fft of size
> > 'j' */
> > /*
> > ---------------------- */
> > gen_twiddle_fft16x16(&w_fft[0][PAD], j);
> > gen_twiddle_ifft16x16(&w_ifft[0][PAD], j);
> >
> > /*
> > ---------------------- */
> > /* Copy vector to all
> > inputs. */
> > /*
> > ---------------------- */
> > memcpy(x_cn, x, sizeof(x_cn));
> > // memcpy(x_i, x, sizeof(x_i));
> > // memcpy(x_sa, x, sizeof(x_cn));
> >
> > // memcpy(y_i, y_cn, sizeof(y_i));
> > // memcpy(y_sa, y_cn, sizeof(y_sa));
> > /*
> > ---------------------- */
> > /* Check the results arrays, and report any
> > failures. */
> > /*
> > ---------------------- */
> > for(i = 0; i < NUM_INPUTS; i++) {
> > // t_cn = time_cn(i, j) - t_overhead;
> > DSP_fft16x16_cn(&w_fft[i][PAD], j,
> > &x_cn[i][PAD], &y_cn[i][PAD]);
> > DSP_ifft16x16_cn(&w_ifft[i][PAD], j,
> > &y_cn[i][PAD], &z_cn[i][PAD]);
> > // t_i = time_i(i, j) - t_overhead;
> > // t_sa = time_sa(i, j) - t_overhead;
> > }
> >
> > // printf("DSP_fft16x16\tIter#: %d\t", k);
> > //
> > // if (memcmp(y_cn, y_i, sizeof(y_cn))) {
> > // fail++;
> > // printf("Result Failure (y_i) ");
> > // }
> > // else
> > // printf("Result Successful (y_i) ");
> > //
> > // if (memcmp(y_cn, y_sa, sizeof(y_cn))) {
> > // fail++;
> > // printf("Result Failure (y_sa) ");
> > // }
> > // else
> > // printf("Result Successful (y_sa) ");
> > //
> > //
> > // printf("\tRadix = %d\tN = %d\tnatC: %d\tintC: %d\tSA: %d\n",
> > radix, j, t_cn, t_i, t_sa);
> > }
> >
> > return (fail);
> > }
> >
> > On Tue, Dec 15, 2009 at 4:57 AM, khawer12 >
> wrote:
> >
> >> hello jogging,
> >>
> >> The choice of precision is dependent on the application. If the
> application
> >> requires precision which can only be met by using DSP_fft32x32 then you
> will
> >> have to use that function.
> >> regarding DSP_fft16x16 function, it works fine. just make sure that the
> >> twiddle factor array is correct.
> >> If you are still not been able to solve your problem after using correct
> >> twiddle factor array then post your code on the group.
> >> i hope someone will come up with some idea to correct it.
> >>
> >>
> >> Regards,
> >> Khawar Shahzad.
> >>
> >>
> >> --- In c... , joggingsong@...
> wrote:
> >> >
> >> > Hi,all
> >> > I am trying to use FFT functions from dsplib_v210 and run into some
> >> problems. The result generated by DSP_fft16x16 and DSP_fft16x16r is
> >> significantly different from the result generated by Matlab, and minor
> >> difference is acceptable because of computation precision. The results
> >> generated by DSP_fft16x32 and DSP_fft32x32 are correct.
> >> >
> >> > I am using FFT for the first time and have several choices for it.
> >> > When should extended precision be chose?
> >> > Thanks in advance.
> >> >
> >> > Regards
> >> > Jogging
> >> >
>
Jogging,

my comments are interspersed and prefixed with
Also cleaned up your code a bit to removed unused/commented out lines and for clarity.

R. Williams

---------- Original Message -----------
From: jogging song
To: khawer12
Cc: c...
Sent: Fri, 18 Dec 2009 14:04:21 +0800
Subject: [c6x] Re: problem about DSP_fft16x16

>
>
> Thanks, Khawar
> My program is very simple and is adapted from the test example provided by
> Ti. I run it on the PC.
> DSP_fft16x16 is for a 16 point input.
> The input is just a sequence of 1.
> But the result is incorrect.
> The following is my code.
>
> Thanks
> Jogging
>
Commented out code statements are removed for clarity

Questions: what is value of 'PAD'

Questions: what is value of 'N'

Questions: what is value of 'NUM_INPUTS'

Questions: what is sizing/definition of all arrays

> int TestFFT16x16()

> {

> int i, j, k, m, n, radix, fail;

>

> commented out code removed, clock overhead calculation

>

> for (j = 0; j < NUM_INPUTS; j++)

> {

> make wild assumption that '<' is lower presidence than '+'

> note, N and PAD do not change so 2N+2PAD should be pre-calculated

> before loop and only reference the result in the 'for' statement

> to eliminate the repetitive math operations

> for (i = 0;

> i < 2*N + 2*PAD; // should be written: i < (2*N + 2*PAD)

> i++)

> {

> commented out code removed, shift

> x[j][i] = 0; initialize whole two dim array to 0

>

> initialize several sections of 2 dim array to 1

> make wild assumption that '<' is lower presidence than '+'

> if((i >= PAD) && (i < PAD+32))

> x[j][i] = 1;//(i-PAD);

> } // endif()

> } // end for()

>

> extracted fixed initializer

> initialize 'return' value

> note 'fail' never updated

> fail=0;

>

> note 'j' is 16,32,64,128,256,512, etc

> note 'k' not used, so removed

>

> for (j = 16; j <= N; j *= 2)

> {

> 'n' not used, 'm' not used, so removed 'for' statement

>

> radix is never used, so removed assignment statement

>

>

> /* ---------------------- */

> /* Generate twiddle factors for fft of size 'j' */

> /* ---------------------- */

> w_fft and w_ifft are not defined within this function

> this may cause problems if sizing not correct

> note defining more/new twiddle factors on each pass through loop

> because 'j' doubles in each pass through 'for' loop

> sets first row (only) in twiddle factor arrays, with offset

> note ONLY first row set, all other values undefined

> gen_twiddle_fft16x16(&w_fft[0][PAD], j);

> gen_twiddle_ifft16x16(&w_ifft[0][PAD], j);

>

> /* ---------------------- */

> /* Copy vector to all inputs. */

> /* ---------------------- */

> x_cn and x are not defined within this function,

> this may cause problems if sizing not correct

> memcpy(x_cn, x, sizeof(x_cn));

>

> removed commented out code, memcpy statements

>

> /* ---------------------- */

> /* Check the results arrays, and report any failures. */

> I do not see any 'check results' nor 'report failures'

> /* ---------------------- */

> for(i = 0; i < NUM_INPUTS; i++)

> {

> removed commented out code

> DSP_fft16x16_cn(

> &w_fft[i][PAD], // row of twiddle factors

> j, // number twiddle factors in row

> &x_cn[i][PAD], // row in input array, with offset

> &y_cn[i][PAD]); // row in output array, with offset

>

> DSP_ifft16x16_cn(

> &w_ifft[i][PAD], // row of twiddle factors

> j, // number twiddle factors in row

> &y_cn[i][PAD], // row in input array, with offset

> &z_cn[i][PAD]); // row in output array, with offset

> removed commented out code, time calc

> } // end for()

> removed commented out code, print statements

> } // end for()

>

> always returns '0'

> return (fail);

> }

>
What happened?

I know the revised code was in the post when I sent it.

R. Williams

---------- Original Message -----------
From: "Richard Williams"
To: jogging song , khawer12
Cc: c...
Sent: Fri, 18 Dec 2009 10:16:59 -0700
Subject: Re: [c6x] Re: problem about DSP_fft16x16

>
>
> Jogging,
>
> my comments are interspersed and prefixed with
> Also cleaned up your code a bit to removed unused/commented out lines and for clarity.
>
> R. Williams
> ---------- Original Message -----------
> From: jogging song
> To: khawer12
> Cc: c...
> Sent: Fri, 18 Dec 2009 14:04:21 +0800
> Subject: [c6x] Re: problem about DSP_fft16x16
>
> >
> >
> > Thanks, Khawar
> > My program is very simple and is adapted from the test example provided by
> > Ti. I run it on the PC.
> > DSP_fft16x16 is for a 16 point input.
> > The input is just a sequence of 1.
> > But the result is incorrect.
> > The following is my code.
> >
> > Thanks
> > Jogging
> >
------- End of Original Message -------
Jogging,

Here is a re-send of the code with my comments.

R. Williams

> ---------- Original Message -----------
> From: jogging song
> To: khawer12
> Cc: c...
> Sent: Fri, 18 Dec 2009 14:04:21 +0800
> Subject: [c6x] Re: problem about DSP_fft16x16
>
> >
> >
> > Thanks, Khawar
> > My program is very simple and is adapted from the test example provided by
> > Ti. I run it on the PC.
> > DSP_fft16x16 is for a 16 point input.
> > The input is just a sequence of 1.
> > But the result is incorrect.
> > The following is my code.
> >
> > Thanks
> > Jogging
Commented out code statements are removed for clarity

Questions: what is value of 'PAD'

Questions: what is value of 'N'

Questions: what is value of 'NUM_INPUTS'

Questions: what is sizing/definition of all arrays

> int TestFFT16x16()

> {

> int i, j, k, m, n, radix, fail;

>

> commented out code removed, clock overhead calculation

>

> for (j = 0; j < NUM_INPUTS; j++)

> {

> make wild assumption that '<' is lower presidence than '+'

> note, N and PAD do not change so 2N+2PAD should be pre-calculated

> before loop and only reference the result in the 'for' statement

> to eliminate the repetitive math operations

> for (i = 0;

> i < 2*N + 2*PAD; // should be written: i < (2*N + 2*PAD)

> i++)

> {

> commented out code is removed, shift

> x[j][i] = 0; initialize whole two dim array to 0

>

> initialize several sections of 2 dim array to 1

> make wild assumption that '<' is lower presidence than '+'

> if((i >= PAD) && (i < PAD+32))

> x[j][i] = 1;//(i-PAD);

> } // endif()

> } // end for()

>

> extracted fixed initializer

> initialize 'return' value

> note 'fail' never updated

> fail=0;

>

> note 'j' is 16,32,64,128,256,512, etc

> note 'k' not used, so removed

>

> for (j = 16; j <= N; j *= 2)

> {

> 'n' not used, 'm' not used, so removed 'for' statement

>

> radix is never used, so removed assignment statement

>

>

> /* ---------------------- */

> /* Generate twiddle factors for fft of size 'j' */

> /* ---------------------- */

> w_fft and w_ifft are not defined within this function

> this may cause problems if sizing not correct

> note defining more/new twiddle factors on each pass through loop

> because 'j' doubles in each pass through 'for' loop

> sets first row (only) in twiddle factor arrays, with offset

> gen_twiddle_fft16x16(&w_fft[0][PAD], j);

> gen_twiddle_ifft16x16(&w_ifft[0][PAD], j);

>

> /* ---------------------- */

> /* Copy vector to all inputs. */

> /* ---------------------- */

> x_cn and x are not defined within this function,

> this may cause problems if sizing not correct

> memcpy(x_cn, x, sizeof(x_cn));

>

> removed commented out code, memcpy statements

>

> /* ---------------------- */

> /* Check the results arrays, and report any failures. */

> I do not see any 'check results' nor 'report failures'

> note: after first loop iteration, references undefined

> rows within the twiddle factors array.

> /* ---------------------- */

> for(i = 0; i < NUM_INPUTS; i++)

> {

> removed commented out code

> DSP_fft16x16_cn(

> &w_fft[i][PAD], // row of twiddle factors

> j, // number twiddle factors in row

> &x_cn[i][PAD], // row in input array, with offset

> &y_cn[i][PAD]); // row in output array, with offset

>

> DSP_ifft16x16_cn(

> &w_ifft[i][PAD], // row of twiddle factors

> j, // number twiddle factors in row

> &y_cn[i][PAD], // row in input array, with offset

> &z_cn[i][PAD]); // row in output array, with offset

> removed commented out code, time calc

> } // end for()

> removed commented out code, print statements

> } // end for()

>

> always returns '0'

> return (fail);

> }

>

_____________________________________
Stephane,

I access emails via Yahoo.com as individual emails.

I used a on-line email web page provided by my ISP.
My browser is Mozila FireFox, version 3.0.15
"Mozilla Firefox for Ubuntu canonical - 1.0"

My OS is Ubuntu (a Linux version)

My email format is HTML.

Note: MY 'sent' mail box shows the code as the last ~1/2 of the email.

BTW:
The email in question, in my 'sent' box shows single spacing, indenting, etc.
The email I received via yahoo is double spaced and internal line spaces are shrank to a single space.
-----------------
Steps I took to produce the original email:
--copied the email from Jogging to the clip board
--opened a new .txt file
--pasted the clip board to the .txt file
--edited the .txt file
--wrote the reply-all email,
--copied the .txt file to the clip board
--pasted the clip board into the email.
--sent the email.

The email server, at my ISP, is running the 'Open WebMail' application dated February 2005.

R. Williams

---------- Original Message -----------
From: Webmaster
To: Richard Williams
Cc: c...
Sent: Fri, 18 Dec 2009 14:53:49 -0400
Subject: Re: problem about DSP_fft16x16

> Richard,
>
> I moderated the post and didn't see the code. A couple of questions:
> - How did you send your message? Did you use the group interface onDSPRelated.com or did you send a message with your email clientdirectly to c...?
> - Was your code part of the message or did you sent it as an attachment?
>
> Stephane
>
> On 18/12/2009 2:35 PM, Richard Williams wrote:
>
> What happened?
>
> I know the revised code was in the post when I sent it.
>
> R. Williams
>
> ---------- Original Message -----------
> From: "Richard Williams"
> To: jogging song , khawer12
> Cc: c...
> Sent: Fri, 18 Dec 2009 10:16:59 -0700
> Subject: Re: [c6x] Re: problem about DSP_fft16x16
>
> >
> >
> > Jogging,
> >
> > my comments are interspersed and prefixed with
> > Also cleaned up your code a bit to removed unused/commented outlines and for clarity.
> >
> > R. Williams
> >
> >
> > ---------- Original Message -----------
> > From: jogging song
> > To: khawer12
> > Cc: c...
> > Sent: Fri, 18 Dec 2009 14:04:21 +0800
> > Subject: [c6x] Re: problem about DSP_fft16x16
> >
> > >
> > >
> > > Thanks, Khawar
> > > My program is very simple and is adapted from the testexample provided by
> > > Ti. I run it on the PC.
> > > DSP_fft16x16 is for a 16 point input.
> > > The input is just a sequence of 1.
> > > But the result is incorrect.
> > > The following is my code.
> > >
> > > Thanks
> > > Jogging
> > >
> >
> >
> ------- End of Original Message -------
>

------- End of Original Message -------
Hi,all
I have a problem about input format.
In digital signal processing, is input data usually normalized to the
range (0,1).
That's the reason why input format requirement is Q.15?

Regards
Jogging

On Sun, Dec 20, 2009 at 2:57 PM, jogging song wrote:

> Thanks, Jeff
> According the comparison between DSP_fft16 result and matlab result, I
> think
> the result need to right shift to obtain expected result.
> http://wiki.davincidsp.com/index.php/FFT_Implementation_With_No_Data_Scaling
> It seems that this website provides another version that data scaling is
> not applied in
> the FFT routines.
>
> Regards
> Jogging
> On Sat, Dec 19, 2009 at 2:11 AM, Jeff Brower wrote:
>
>> Jogging-
>>
>> > For each functions about FFT calculation, C code of each function
>> > is available. I run it on the PC.
>> >
>> > After reading the document several times, I think the problem
>> > is caused by the fact
>> > "All stages except the last one scale by two the stage output
>> > data". I need to right shift the result to obtain correct result.
>>
>> My guess is the doc is saying that:
>>
>> -input should be 16-bit (short int)
>>
>> -output will be 16-bit, with no need
>> for scaling since scaling is
>> handled inherently
>>
>> As a note, some of the TI functions, when implemented as C code, require a
>> final right shift by 15 to get 16-bit
>> output; i.e. they are accumulating 32-bit values internally. This one
>> sounds different.
>>
>> > The document also says that All data are in short precision or Q.15
>> format.
>> > What does it mean? The data must be in the range of (-1,1)?
>>
>> Yes, input should be -32768 to 32767. So if you have input data between
>> -1.0 and 1.0, then you should multiply by
>> 32767 before running the TI code.
>>
>> -Jeff
>> > On Fri, Dec 18, 2009 at 10:56 PM, Jeff Brower >> >wrote:
>> >
>> >>
>> >>
>> >> Jogging-
>> >>
>> >>
>> >> > My program is very simple and is adapted from the test example
>> provided
>> >> by
>> >> > Ti. I run it on the PC.
>> >>
>> >> Can you explan "run it on the PC"? Using CCS? Or some other program for
>> >> comparison purposes?
>> >>
>> >>
>> >> > DSP_fft16x16 is for a 16 point input.
>> >> > The input is just a sequence of 1.
>> >> > But the result is incorrect.
>> >> > The following is my code.
>> >>
>> >> As there are a number of "DSP_fft...something" routines, suggest to do
>> this
>> >> search:
>> >>
>> >> DSP_fft site:dsprelated.com
>> >>
>> >> You should see a lot of previous posts about using these functions. My
>> >> guess is that you have a data alignment issue.
>> >>
>> >> -Jeff
>> >>
>> >>
>> >> > int TestFFT16x16()
>> >> > {
>> >> > // clock_t t_overhead, t_start, t_stop;
>> >> > // clock_t t_cn, t_i, t_sa;
>> >> > int i, j, k, m, n, radix, fail;
>> >> >
>> >> > /* ----------------------
>> >> > */
>> >> > /* Compute the overhead of calling clock() twice to get timing info.
>> >> > */
>> >> > /* ----------------------
>> >> > */
>> >> > // t_start = clock();
>> >> > // t_stop = clock();
>> >> > // t_overhead = t_stop - t_start;
>> >> >
>> >> > for (j = 0; j < NUM_INPUTS; j++) {
>> >> > for (i = 0; i < 2*N + 2*PAD; i++)
>> >> > {
>> >> > // x[j][i] = x[j][i] >> 4;
>> >> > x[j][i] = 0;
>> >> > if((i >= PAD) && (i < PAD+32))
>> >> > x[j][i] = 1;//(i-PAD);
>> >> > }
>> >> > }
>> >> >
>> >> > for (j = 16, k = 1, fail = 0; j <= N; k++, j *= 2) {
>> >> > for (n = 31, m = 1; (j & (1 << n)) == 0; n--, m++)
>> >> > ;
>> >> > radix = m & 1 ? 2 : 4;
>> >> >
>> >> > /*
>> >> > ---------------------- */
>> >> > /* Generate twiddle factors for fft of size
>> >> > 'j' */
>> >> > /*
>> >> > ---------------------- */
>> >> > gen_twiddle_fft16x16(&w_fft[0][PAD], j);
>> >> > gen_twiddle_ifft16x16(&w_ifft[0][PAD], j);
>> >> >
>> >> > /*
>> >> > ---------------------- */
>> >> > /* Copy vector to all
>> >> > inputs. */
>> >> > /*
>> >> > ---------------------- */
>> >> > memcpy(x_cn, x, sizeof(x_cn));
>> >> > // memcpy(x_i, x, sizeof(x_i));
>> >> > // memcpy(x_sa, x, sizeof(x_cn));
>> >> >
>> >> > // memcpy(y_i, y_cn, sizeof(y_i));
>> >> > // memcpy(y_sa, y_cn, sizeof(y_sa));
>> >> > /*
>> >> > ---------------------- */
>> >> > /* Check the results arrays, and report any
>> >> > failures. */
>> >> > /*
>> >> > ---------------------- */
>> >> > for(i = 0; i < NUM_INPUTS; i++) {
>> >> > // t_cn = time_cn(i, j) - t_overhead;
>> >> > DSP_fft16x16_cn(&w_fft[i][PAD], j,
>> >> > &x_cn[i][PAD], &y_cn[i][PAD]);
>> >> > DSP_ifft16x16_cn(&w_ifft[i][PAD], j,
>> >> > &y_cn[i][PAD], &z_cn[i][PAD]);
>> >> > // t_i = time_i(i, j) - t_overhead;
>> >> > // t_sa = time_sa(i, j) - t_overhead;
>> >> > }
>> >> >
>> >> > // printf("DSP_fft16x16\tIter#: %d\t", k);
>> >> > //
>> >> > // if (memcmp(y_cn, y_i, sizeof(y_cn))) {
>> >> > // fail++;
>> >> > // printf("Result Failure (y_i) ");
>> >> > // }
>> >> > // else
>> >> > // printf("Result Successful (y_i) ");
>> >> > //
>> >> > // if (memcmp(y_cn, y_sa, sizeof(y_cn))) {
>> >> > // fail++;
>> >> > // printf("Result Failure (y_sa) ");
>> >> > // }
>> >> > // else
>> >> > // printf("Result Successful (y_sa) ");
>> >> > //
>> >> > //
>> >> > // printf("\tRadix = %d\tN = %d\tnatC: %d\tintC: %d\tSA: %d\n",
>> >> > radix, j, t_cn, t_i, t_sa);
>> >> > }
>> >> >
>> >> > return (fail);
>> >> > }
>> >> >
>> >> > On Tue, Dec 15, 2009 at 4:57 AM, khawer12 >> >
>> >> wrote:
>> >> >
>> >> >> hello jogging,
>> >> >>
>> >> >> The choice of precision is dependent on the application. If the
>> >> application
>> >> >> requires precision which can only be met by using DSP_fft32x32 then
>> you
>> >> will
>> >> >> have to use that function.
>> >> >> regarding DSP_fft16x16 function, it works fine. just make sure that
>> the
>> >> >> twiddle factor array is correct.
>> >> >> If you are still not been able to solve your problem after using
>> correct
>> >> >> twiddle factor array then post your code on the group.
>> >> >> i hope someone will come up with some idea to correct it.
>> >> >>
>> >> >>
>> >> >> Regards,
>> >> >> Khawar Shahzad.
>> >> >>
>> >> >>
>> >> >> --- In c... , joggingsong@...
>> >> wrote:
>> >> >> >
>> >> >> > Hi,all
>> >> >> > I am trying to use FFT functions from dsplib_v210 and run into
>> some
>> >> >> problems. The result generated by DSP_fft16x16 and DSP_fft16x16r is
>> >> >> significantly different from the result generated by Matlab, and
>> minor
>> >> >> difference is acceptable because of computation precision. The
>> results
>> >> >> generated by DSP_fft16x32 and DSP_fft32x32 are correct.
>> >> >> >
>> >> >> > I am using FFT for the first time and have several choices for it.
>> >> >> > When should extended precision be chose?
>> >> >> > Thanks in advance.
>> >> >> >
>> >> >> > Regards
>> >> >> > Jogging
>>
>