for ( i=0;i
{
INPUT=sin(PI*2*i/SAMPLENUMBER*3)*1024;//+sin(PI*2*i/SAMPLENUMBER*8)*100+sin(PI*2*i/SAMPLENUMBER*60)*1024;// ---1024
}
}
void main(void)
{
int i;
Uint16 ReceivedChar[10];
Uint16 cnt;
Uint16 cntf;
int16 sendchar;
int n;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
InitScibGpio();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
/////////////////////////////////////////////////////
void FFT(float dataR[SAMPLENUMBER],float dataI[SAMPLENUMBER])
{
int x0,x1,x2,x3,x4,x5,x6,x7,xx;
int i,j,k,b,r,m,L;
float TR,TI,temp;
/********** following code invert sequence ************/
/********** 实现倒序 ************/
for ( i=0;i
{ x7=SAMPLENUMBER;
x0=x1=x2=x3=x4=x5=x6=0;
x0=i&0x01;
x1=(i/2)&0x01;
x2=(i/4)&0x01;
x3=(i/8)&0x01;
x4=(i/16)&0x01;
x5=(i/32)&0x01;
x6=(i/64)&0x01;
xx=x0*x7/2+x1*x7/4+x2*x7/8+x3*x7/16+x4*x7/32+x5*x7/64+x6;
dataI[xx]=dataR;/*虚部此时暂时没用,暂时做缓存数组*/
}
for ( i=0;i
{
dataR=dataI; dataI=0;
}
/**************计算*SAMPLENUMBER=2^(m)中的m******************/
m=0;
for (j=SAMPLENUMBER;j>1;j=j/2)
{m=m+1;}
//printf("%d\n",m);
/************** following code FFT *******************/
for ( L=1;L<=m;L++ )
{ /* for(1) */
b=1; i=L-1;
while ( i>0 )
{
b=b*2; i--;
} /* b= 2^(L-1) */
for ( j=0;j<=b-1;j++ ) /* for (2) */
{ r=1; i=m-L;
while ( i>0 ) /* r=2^(m-L)*j,用于计算Wr */
{r=r*2; i--;}
r=r*j;
for ( k=j;k
{
TR=dataR[k]; TI=dataI[k]; temp=dataR[k+b];
dataR[k]=dataR[k]+dataR[k+b]*cos_tab[r]+dataI[k+b]*sin_tab[r];
dataI[k]=dataI[k]-dataR[k+b]*sin_tab[r]+dataI[k+b]*cos_tab[r];
dataR[k+b]=TR-dataR[k+b]*cos_tab[r]-dataI[k+b]*sin_tab[r];
dataI[k+b]=TI+temp*sin_tab[r]-dataI[k+b]*cos_tab[r];
} /* END for (3) */
} /* END for (2) */
} /* END for (1) */
for ( i=0;i
{
w=sqrt(dataR*dataR+dataI*dataI);
}
} /* END FFT */
void InitForFFT()
{
int i;
for ( i=0;i
{
sin_tab=sin(PI*2*i/SAMPLENUMBER);
cos_tab=cos(PI*2*i/SAMPLENUMBER);
}
}
//===========================================================================
// No more.
//===========================================================================