先前測試了FFT的使用,接下來進行FIR的測試,
目前已將C6accel程式清空,主程式只保留DSP調用需要的部分,
將測試碼獨立為一個副程式,才不會不小心把主程式搞壞,
測試代碼如下所示:
int c6accel_test_FIR(C6accel_Handle hC6accel,unsigned int nr,unsigned int nh)
{
float fc=(float)8000.0/16000.0;
short *xArray16, *hArray16, *yArray16;
int i;
float j,k,l;
unsigned int nx = nr+nh-1;
float nWaves=3.5;
// C6accel_DSP_fir_gen() test
xArray16 = (short *)pSrcBuf_16bpp;
hArray16 = (short *)pWorkingBuf_16bpp;
yArray16 = (short *)pOutBuf_16bpp;
//create nWaves cosine wave with Q.15format in nx point
for (i = 0; i < nx; i++ ) { xArray16[i] = (short) (cos(2.0*PI*nWaves*i/nx)*32767);}
printf(" %f cosine wave in 120 data are :
",nWaves);
showData(xArray16,nx);
for (i = 0; i < nh; i++ )
{
l=i;
if ( nh%2 != 0)
{ l = l-(nh-1)/2.0; } //add
else
{ l = l-(nh /2.0)+0.5 ; } //even
j = sin(l*2.0*PI*fc)/(float)(l*PI); // ideal coefficients
k = 0.54+0.46*cos(2.0*PI*l/(float)nh); //Hamming window
printf("ideal coeff = %1.4f , Hamming = %1.4f, d=%1.4f
",j,k,j*k);
j=j*k*32767; // transfor to Q.15
hArray16[i] = (short) j;
}
printf(" ideal coefficients * Hamming windows parameter are :
");
showData(hArray16,nh);
// Clear output arrays before tests begins
memset (pOutBuf_16bpp,0x0000, nr);
// Call the DSP_fir_gen function in C6Accel
C6accel_DSP_fir_gen(hC6accel,xArray16, hArray16, yArray16, nh, nr );
if (C6Accel_readCallType(hC6accel) == ASYNC)
{ C6accel_waitAsyncCall(hC6accel); } // Now wait for the callback
printf(" Data after hamming window are :
");
showData(yArray16,nr);
// Clear output arrays
memset (pOutBuf_16bpp,0x0000, nr);
C6accel_DSP_fir_r4(hC6accel,xArray16, hArray16, yArray16, nh, nr );
if (C6Accel_readCallType(hC6accel) == ASYNC)
{ C6accel_waitAsyncCall(hC6accel); } // Now wait for the callback
printf(" Data after hamming window are :
");
showData(yArray16,nr);
// Clear output arrays
memset (pOutBuf_16bpp,0x00, nr*sizeof(short));
C6accel_DSP_fir_r8(hC6accel,xArray16, hArray16, yArray16,nh,nr);
if (C6Accel_readCallType(hC6accel) == ASYNC)
{ C6accel_waitAsyncCall(hC6accel); } // Now wait for the callback
printf(" Data after hamming window are :
");
showData(yArray16,nr);
printf(" END of FIR Filtering functions test
");
return (1);
}
產生 3.5 個cosine 波型 並且加入 8位的Hamming Windows 的FIR濾波器,此方式可使用較少位數的窗函數進行連續移動的濾波轉換,
或是可改用其他濾波器(高通或低通效果),使用DSP進行(半?)即時的濾波轉換。