/////////////////////////////////////////////////////////////////////// // Filename: FIRfilter.c // // Synopsis: Does floating-point FIR filters // // Authors: Keith Hoover, with changes by Mark A. Yoder // // Date of Last Revision: 18-Mar-2004 // /////////////////////////////////////////////////////////////////////// void FIRfilter(float *inbuf, float *outbuf, float *coeff, int buffSize, int Norder) { int i,j; float sum; static float x[20]; // BAD Hack. Need to know number of coefficients. for(j=0; j<buffSize; j++) { /* Update past input sample array, where x[0] holds present sample, x[1] holds sample from 1 sample period ago, x[N] holds sample from N sampling periods ago. This time-consuming loop could be eliminated if circular buffering were to be employed. */ for(i=Norder; i >= 0;i--) x[i]=x[i-1]; x[0] = inbuf[j]; sum = 0.0; for(i=0; i<=Norder; i++) /* Perform FIR filtering (convolution) */ sum += x[i]*coeff[i]; outbuf[j] = sum; /* Send to buffer (both channels ) */ } }