DSPRelated.com
Forums

problem about DSP_fft16x16

Started by jogg...@gmail.com December 13, 2009
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
Jogging-

> 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.

Did the "no scaling" version work for you?

-Jeff

> 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

_____________________________________