Programming example: C program example of floating point to fixed point conversion[Copy link]
This example illustrates how to convert a C program from floating point to fixed point. This is a C language program that performs a low-pass filter on a speech signal (0.3~3.4kHz). The cutoff frequency of the low-pass filter is 800Hz, and the filter uses a 19-point finite impulse response FIR filter. The sampling frequency of the speech signal is 8kHz, and each speech sample value is stored in the insp.dat file as a 16-bit integer. Example 1.7 C language floating-point program for speech signal 800Hz 19-point FIR low-pass filter. #i nclude const int length=180/*The voice frame length is 180 points = 22.5ms@8kHz sampling*/ void filter(int xin[],int xout[],int n,float h[]);/*Filter subroutine description*/ /*19-point filter coefficients*/ static float h[19]= {0.01218354,-0.009012882,-0.02881839,-0.04743239,-0.04584568, -0.008692503,0.06446265,0.1544655,0.2289794,0.257883, static int xl[length+20]; ... void filter(int xin[], int xout[], int n, float h[]) { int i,j; float sum; for(i=0;ifor(i=0;i<length;i++)" color]="" font][="" l9点fir低通滤波c语言定点程序。[="" main()[="" nclude="" 滤波后语音文件*="" 输入语音文件*="" ,indata[length],outdata[length];[=""> const int length=180; void filter (int xin[], int xout[], int n, int h[]); static int h[19]={399,-296,-945,-1555,-1503,-285,2112,5061,7503,8450,[/ font] 7503, 5061, 2112, -285, -1503, -1555, -945, -296, 399}; /*Q15*/[/ color] static int x1[length+20]; / *Low-pass filter fixed-point subroutine*/ void filter(int xin[],int xout[],int n,int h []) int i, j; long sum; for(i=0;i<length ;i++)x1[n+i-111=xin]; for(i=0;i<1ength;i++) sum=0; for(j=0;j<n;j++)sum+=(long)h[j]*x1[i-j+n-1]; xout=sum>>15; for(i=0 ;i<(n-1);i++)x1[ni-2]=xin[length-i-1]; } The main program is exactly the same as the floating point one. "