[開發記錄] 函式庫調用 - 使用C6accel 資料庫進行FFT函式調用 之其二

来源:互联网 发布:名不虚传软件下载 编辑:程序博客网 时间:2024/05/20 21:48

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 Formatprintf("building Data (with scale 2/Npoint )are : \n ");showData(inBufs,2*Npoint);//show FFT data on screenprintf("twiddle Data are : \n ");showData(WN16,2*Npoint);//show WN data on screenoutBufs = (short*)pOutBuf_16bpp;memset (outBufs,0x00,2*Npoint*sizeof(short));/* Clear output arrays*/    // Call the fft16x16 function in C6AccelC6accel_DSP_fft16x16 (hC6accel,WN16,Npoint,inBufs,(short*)outBufs);if (C6Accel_readCallType(hC6accel) == ASYNC){// Now wait for the callbackC6accel_waitAsyncCall(hC6accel);}printf("Data after FFT are : \n ");showData(outBufs,2*Npoint);//show data before FFTprintf("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 inBuffor (i = 0; i < 2*Npoint ; i++ ){inBufs[i]=outBufs[i];}// Clear output arraysmemset (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 callbackC6accel_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進行調用,便可測試。


目前已可正確進行FFT、IFFT,

上一篇的問題:

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檔,刪除不需要的部分。



原创粉丝点击