/***************************************************************** * fir_fixpt.c - C program for NL-tap FIR filtering in * Section 6.6.3 ****************************************************************** * System configuration: * * * in(n) |----------------| out(n) * ---->| Bandpass filter|-----> * |----------------| * ****************************************************************** * System simulation configuration: * * in(n) is the input data from data file "in.dat" * out(n) is the output data to data file "out.dat" * *****************************************************************/ #include #include #include #include "coeff_16int.h" void main() { /***************************************************************** * Define variable arrays, define and clear variables *****************************************************************/ long yn = 0; /* y(n), output from IIR filter */ int xn; int xnbuf[96]; int i,j,k; long scale = 32768; /***************************************************************** * Declare file pointers *****************************************************************/ FILE *xn_in; /* file pointer of x(n) */ FILE *yn_out; /* file pointer of y(n) */ xn_in = fopen("in_int.dat","r");/* open file for input x(n) */ /*Note that the data cannot be expressed in exp format for %d */ yn_out = fopen("out_int.dat","w");/* open file for output y(n)*/ /***************************************************************** * Start of main program *****************************************************************/ for(k=0;k0;i--) { xnbuf[i]=xnbuf[i-1]; } xnbuf[0]=xn; /************************************************************* * FIR filtering: * y(n) = Sum[x(n-i)*coeff(i)] for i = 0 to NL-1 *************************************************************/ yn = 0; for (j=0; j< NL; j++) { yn += (long)(xnbuf[j] * (int16_T)NUM[j]); } fprintf(yn_out,"%d\n",(int)(yn/scale)); } printf("Finish"); /* Complete filtering */ fcloseall(); /* close all opened files */ }