/***************************************************************** * iir_fixpt.c- Fixed-point C program for IIR filtering, * cascade of three biquads in Section 7.7.3 ****************************************************************** * System configuration: * * in(n) |----------------| out(n) * ---->| Bandpass filter|-----> * |----------------| * ****************************************************************** * System simulation configuration: * * in(n) is the input data from data file "in_int.dat" * out(n) is the output data to data file "out_int.dat" * *****************************************************************/ #include #include #include #include "iircascade_16int.h" void main() { /***************************************************************** * Define variable arrays, define and clear variables *****************************************************************/ const int section = 3; const int tap = 3; long out = 0; /* y(n), output from IIR filter */ int xn; int delay[9] = {0,0,0,0,0,0,0,0,0}; int gain = 133; int j; /***************************************************************** * 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) */ yn_out = fopen("out_int.dat","w"); /* open file for output y(n)*/ /***************************************************************** * Start of main program *****************************************************************/ while ((fscanf(xn_in,"%d",&xn)) != EOF) { /* read in x(n) from data file and processing it */ out=(((long)(int)xn*(long)(int)gain)>>16); /*************************************************************** * IIR filtering: feedback follow by feedforward and repeat * for three sections ***************************************************************/ for (j=0; j>15); delay[(j* section)]=(int)(out-(((long)(int)delay[2+(j* section)]*(long)(int16_T)DEN[j][2])>>15)); /* feedforward section */ out=(long)(int)delay[(j* section)]+(((long)(int)delay[1+(j* section)]*(long)(int16_T)NUM[j][1])>>15); out=out+(((long)(int)delay[2+(j* section)]*(long)(int16_T)NUM[j][2])>>15); /* refresh signal buffer */ delay[2+(j* section)] = delay[1+(j* section)]; delay[1+(j* section)] = delay[(j* section)]; } fprintf(yn_out,"%d\n",(int)(out<<1)); } printf("Finish"); /* complete filtering */ fcloseall(); /* close all opened files */ }