DSPRelated.com
Forums

dsplib problem!

Started by puffoinkazzato July 28, 2003
I'm developing with CodeComposer 2.1 and dsk6711 a simple FFT program
with dsplib. This is the code:

#include "DSPF_sp_bitrev_cplx"
#include "ProvaFFTcfg.h"

#define pi 3.14159265358979323846264338327950288419716939937510
#define FFT_SIZE 1024

#pragma DATA_MEM_BANK(PSD_W, 2); /* C62x and C67x have 16-bit banks */
#pragma DATA_ALIGN(PSD_Indeces,8)
#pragma DATA_ALIGN(FFTBuffer,8)
#pragma DATA_ALIGN(FFT_mag,8)
#pragma DATA_ALIGN(FFT_Window,8) short PSD_Indeces[FFT_SIZE];
float FFTBuffer[FFT_SIZE*2];
float FFT_mag[FFT_SIZE/2];
float FFT_Window[FFT_SIZE];
float PSD_W[2 * 768] = { //}

void CalcFFTMag(float * vect, int size, float * out)
{
int i;
float I,Q;

float alpha = 0.96043387;
float beta = 0.397824735;

// compute the fft magnitude
for (i=0; i<size/2; i++){
I = fabs(vect[i*2]); //real
Q = fabs(vect[i*2 +1]); //imag
*(out+i) = (alpha*(MAX(I,Q)) + beta*(MIN(I,Q)));
}
}

void main()
{
int i;

for(i=0;i<FFT_SIZE;i++)
FFT_Window[i] = 1.0 - powf((i - 0.5*FFT_SIZE)/(0.5*FFT_SIZE),2);

for(i=0;i<FFT_SIZE;i++)
{
FFTBuffer[i*2] = cosf(2*pi*100*0.0005*i) * FFT_Window[i];
FFTBuffer[i*2 +1] = 0;
}

bitrev_index(PSD_Indeces,FFT_SIZE);

DSPF_sp_cfftr4_dif(FFTBuffer,PSD_W, FFT_SIZE);
DSPF_sp_bitrev_cplx((double*)FFTBuffer,PSD_Indeces, FFT_SIZE);

CalcFFTMag(FFTBuffer,FFT_SIZE,FFT_mag);
}

But the application doesn't work well. Results are incorrect....
What's my fault?




Results are correct upon return from DSPF_sp_cfftr4_dif(), the problem
is that the correct results eventually are in incorrect order. That
radix 4 FFT function leaves the output in the DIGIT-reversed order (where
the digit is 4) and not in the bit-reversed order, like a radix 2 FFT
routine would scramble it.

On the contrary, the routines you've used to descramble the output
perform the bit-reverse permutation: bitrev_index() and DSPF_sp_bitrev_cplx(),
when digit-reverse permutation routines are in fact required.

What's funny, the C67xx DSPLib does not have them :) One more bug.
These routines are described and a source code is presented in
SPRA440 Bit-Reverse and Digit-Reverse: Linear-Time Small Lookup Table
Implementation for the TMS320C6000 Application Report, digitrev_index()
and digitrev().

Hope this helps.

Andrew

Oops, I did not test the DSPF_sp_cfftr4_dif()! Might be buggy by itself :)
Beware. On Mon, Jul 28 2003 "puffoinkazzato" <> wrote:

> Date: Mon, 28 Jul 2003 08:24:24 -0000
> From: "puffoinkazzato" <>
> Subject: dsplib problem!
>
> I'm developing with CodeComposer 2.1 and dsk6711 a simple FFT program
> with dsplib. This is the code:
>
> #include "DSPF_sp_bitrev_cplx"
> #include "ProvaFFTcfg.h"
>
> #define pi 3.14159265358979323846264338327950288419716939937510
> #define FFT_SIZE 1024
>
> #pragma DATA_MEM_BANK(PSD_W, 2); /* C62x and C67x have 16-bit banks */
> #pragma DATA_ALIGN(PSD_Indeces,8)
> #pragma DATA_ALIGN(FFTBuffer,8)
> #pragma DATA_ALIGN(FFT_mag,8)
> #pragma DATA_ALIGN(FFT_Window,8) > short PSD_Indeces[FFT_SIZE];
> float FFTBuffer[FFT_SIZE*2];
> float FFT_mag[FFT_SIZE/2];
> float FFT_Window[FFT_SIZE];
> float PSD_W[2 * 768] = { //}
>
> void CalcFFTMag(float * vect, int size, float * out)
> {
> int i;
> float I,Q;
>
> float alpha = 0.96043387;
> float beta = 0.397824735;
>
> // compute the fft magnitude
> for (i=0; i<size/2; i++){
> I = fabs(vect[i*2]); //real
> Q = fabs(vect[i*2 +1]); //imag
> *(out+i) = (alpha*(MAX(I,Q)) + beta*(MIN(I,Q)));
> }
> }
>
> void main()
> {
> int i;
>
> for(i=0;i<FFT_SIZE;i++)
> FFT_Window[i] = 1.0 - powf((i - 0.5*FFT_SIZE)/(0.5*FFT_SIZE),2);
>
> for(i=0;i<FFT_SIZE;i++)
> {
> FFTBuffer[i*2] = cosf(2*pi*100*0.0005*i) * FFT_Window[i];
> FFTBuffer[i*2 +1] = 0;
> }
>
> bitrev_index(PSD_Indeces,FFT_SIZE);
>
> DSPF_sp_cfftr4_dif(FFTBuffer,PSD_W, FFT_SIZE);
> DSPF_sp_bitrev_cplx((double*)FFTBuffer,PSD_Indeces, FFT_SIZE);
>
> CalcFFTMag(FFTBuffer,FFT_SIZE,FFT_mag);
> }
>
> But the application doesn't work well. Results are incorrect....
> What's my fault?
>



You can get the DIGIT-reversal assembly code (call from C) from
http://www-k.ext.ti.com/sc/technical-support/tools/dsp/ftp/c67x.htm
I have used it and it works fine.

Regards,

Kurt Vetter -----Original Message-----
From: Andrew Nesterov [mailto:]
Sent: Monday, August 04, 2003 10:09 PM
To:
Subject: [c6x] Re: dsplib problem! Results are correct upon return from DSPF_sp_cfftr4_dif(), the problem
is that the correct results eventually are in incorrect order. That
radix 4 FFT function leaves the output in the DIGIT-reversed order (where
the digit is 4) and not in the bit-reversed order, like a radix 2 FFT
routine would scramble it.

On the contrary, the routines you've used to descramble the output
perform the bit-reverse permutation: bitrev_index() and
DSPF_sp_bitrev_cplx(),
when digit-reverse permutation routines are in fact required.

What's funny, the C67xx DSPLib does not have them :) One more bug.
These routines are described and a source code is presented in
SPRA440 Bit-Reverse and Digit-Reverse: Linear-Time Small Lookup Table
Implementation for the TMS320C6000 Application Report, digitrev_index()
and digitrev().

Hope this helps.

Andrew

Oops, I did not test the DSPF_sp_cfftr4_dif()! Might be buggy by itself :)
Beware. On Mon, Jul 28 2003 "puffoinkazzato" <> wrote:

> Date: Mon, 28 Jul 2003 08:24:24 -0000
> From: "puffoinkazzato" <>
> Subject: dsplib problem!
>
> I'm developing with CodeComposer 2.1 and dsk6711 a simple FFT program
> with dsplib. This is the code:
>
> #include "DSPF_sp_bitrev_cplx"
> #include "ProvaFFTcfg.h"
>
> #define pi 3.14159265358979323846264338327950288419716939937510
> #define FFT_SIZE 1024
>
> #pragma DATA_MEM_BANK(PSD_W, 2); /* C62x and C67x have 16-bit banks */
> #pragma DATA_ALIGN(PSD_Indeces,8)
> #pragma DATA_ALIGN(FFTBuffer,8)
> #pragma DATA_ALIGN(FFT_mag,8)
> #pragma DATA_ALIGN(FFT_Window,8) > short PSD_Indeces[FFT_SIZE];
> float FFTBuffer[FFT_SIZE*2];
> float FFT_mag[FFT_SIZE/2];
> float FFT_Window[FFT_SIZE];
> float PSD_W[2 * 768] = { //}
>
> void CalcFFTMag(float * vect, int size, float * out)
> {
> int i;
> float I,Q;
>
> float alpha = 0.96043387;
> float beta = 0.397824735;
>
> // compute the fft magnitude
> for (i=0; i<size/2; i++){
> I = fabs(vect[i*2]); //real
> Q = fabs(vect[i*2 +1]); //imag
> *(out+i) = (alpha*(MAX(I,Q)) + beta*(MIN(I,Q)));
> }
> }
>
> void main()
> {
> int i;
>
> for(i=0;i<FFT_SIZE;i++)
> FFT_Window[i] = 1.0 - powf((i - 0.5*FFT_SIZE)/(0.5*FFT_SIZE),2);
>
> for(i=0;i<FFT_SIZE;i++)
> {
> FFTBuffer[i*2] = cosf(2*pi*100*0.0005*i) * FFT_Window[i];
> FFTBuffer[i*2 +1] = 0;
> }
>
> bitrev_index(PSD_Indeces,FFT_SIZE);
>
> DSPF_sp_cfftr4_dif(FFTBuffer,PSD_W, FFT_SIZE);
> DSPF_sp_bitrev_cplx((double*)FFTBuffer,PSD_Indeces, FFT_SIZE);
>
> CalcFFTMag(FFTBuffer,FFT_SIZE,FFT_mag);
> }
>
> But the application doesn't work well. Results are incorrect....
> What's my fault?
>

_____________________________________
Note: If you do a simple "reply" with your email client, only the author of
this message will receive your answer. You need to do a "reply all" if you
want your answer to be distributed to the entire group.

_____________________________________
About this discussion group:

To Join: Send an email to

To Post: Send an email to

To Leave: Send an email to

Archives: http://www.yahoogroups.com/group/c6x

Other Groups: http://www.dsprelated.com ">http://docs.yahoo.com/info/terms/