In matlab, an efficient FIR filter is implemented by calling
outputsignal = filter(B,1,inputsignal);where
Figure 5.6 lists a second-order FIR filter implementation in the C programming language.
Appendix I lists a C++ class for general FIR filters, observing programming conventions used in the Synthesis Tool Kit (STK) [15].
typedef double *pp; // pointer to array of length NTICK typedef double word; // signal and coefficient data type typedef struct _fir3Vars { pp outputAout; pp inputAinp; word b0; word b1; word b2; word s1; word s2; } fir3Vars; void fir3(fir3Vars *a) { int i; word input; for (i=0; i<NTICK; i++) { input = a->inputAinp[i]; a->outputAout[i] = a->b0 * input + a->b1 * a->s1 + a->b2 * a->s2; a->s2 = a->s1; a->s1 = input; } } |