int c6accel_test_code(C6accel_Handle hC6accel,unsigned int n)
{
int i,j;
float k,l;
double T;
short *WN16;
short *inBufs;
short *outBufs;
int Npoint = 16;
short *FFT_Value;
float *testBufs;
printf("not used set parameter n, use %d instand of it \n",Npoint);
if (IsPowOfTwo(Npoint) != 1 ){ printf("number of FFT data must power of 4 \n"); return(0);}
WN16 = (short*)pWorkingBuf_16bpp;
gen_twiddle_fft16x16(WN16,Npoint); //產生 混合基 迴轉因子
inBufs = (short *)pSrcBuf_16bpp;
memset (inBufs,0x00,2*Npoint*sizeof(short)); /* Clear input arrays*/
testBufs=(float*)malloc(sizeof(float)*2*Npoint);
for (i=0;i<Npoint;i++)
{
testBufs[2*i] =(float)cos(2.0*PI*i/Npoint);
//testBufs[2*i]=1.0;
testBufs[2*i+1] = 0.0;
}
for (i=0;i<2*Npoint;i++)
{
testBufs[i]=testBufs[i]*32767/(Npoint/2);
inBufs[i]=(short)testBufs[i];
//test 產生小數點誤差
inBufs[i]=inBufs[i]/100;
inBufs[i]=inBufs[i]*100;
} //trans to Q.15 Format
printf("building Data (with scale 2/Npoint )are : \n ");
showData(inBufs,2*Npoint); //show FFT data on screen
printf("twiddle Data are : \n ");
showData(WN16,2*Npoint); //show WN data on screen
outBufs = (short*)pOutBuf_16bpp;
memset (outBufs,0x00,2*Npoint*sizeof(short)); /* Clear output arrays*/
// Call the fft16x16 function in C6Accel
C6accel_DSP_fft16x16 (hC6accel,WN16,Npoint,inBufs,(short*)outBufs);
if (C6Accel_readCallType(hC6accel) == ASYNC)
{
// Now wait for the callback
C6accel_waitAsyncCall(hC6accel);
}
printf("Data after FFT are : \n ");
showData(outBufs,2*Npoint); //show data before FFT
printf("Data after FFT values are : \n ");
for(i=0;i<Npoint;i++)
{
k=outBufs[2*i];
l=outBufs[2*i+1];
k=k/32767.0;
l=l/32767.0;
k=k*k;
l=l*l;
k = sqrt(k+l);
printf("\t%f",k);
if ( (i+1) % 8 == 0 ){printf("\n"); }
}
printf("\n");
memset (inBufs,0x00,2*Npoint*sizeof(short)); // Clear input arrays
//move data from outBuf to inBuf
for (i = 0; i < 2*Npoint ; i++ )
{ inBufs[i]=outBufs[i]; }
// Clear output arrays
memset (outBufs,0x00,2*Npoint*sizeof(short));
gen_twiddle_ifft16x16(WN16,Npoint);
C6accel_DSP_ifft16x16 (hC6accel,WN16,Npoint,inBufs,(short*)outBufs);
if (C6Accel_readCallType(hC6accel) == ASYNC)
{
// Now wait for the callback
C6accel_waitAsyncCall(hC6accel);
}
for (i = 0; i < 2*Npoint ; i++ )
{ outBufs[i]=outBufs[i]*2; }
printf("Data after IFFT(with ifft wn ) are : \n ");
showData(outBufs,2*Npoint); //show data before IFFT
return (1);
}
上述程式,可加在c6accel的DSP_function內,在appMain進行調用,便可測試。
上一篇的問題:
1、使用 實部/虛部 為一組的方式擺放,進行FFT時因其格式為Q.15,輸出最大值只有+1,
測試後,發現將所有輸入資料 標準化後 乘上 2/N 後,FFT輸出資料可正確以標準化顯示,最大值為1 (代表能量最大值)
資料乘上N後,就跟Matlab測試資料相符。
2、使用C6Accel的FFT為混合基,使用C6accel內所提供的代碼 gen_twiddle_fft16x16 可正確產生,參數使用N,會產生2*N筆資料量大小。
3、不同,IFFT使用gen_twiddle_ifft16x16,若使用上述FFT後的資料,Q.15的資料拿來 ifft 使用,輸出資料*2後,可還原到原始產生資料。
4、仍未確認,但可將該程式清空,將程式整併 到 appMain的 .C檔 以及.H檔,刪除不需要的部分。