/***************************************************************** * iir2.c - C program for first-order IIR filtering ****************************************************************** * System configuration: * * * x(n) |----------------| y(n) * ---->| Lowpass filter |-----> * |----------------| * ****************************************************************** * System simulation configuration: * * x(n) is the input data from data file "xn.dat" * y(n) is the output data to data file "yn.dat" * *****************************************************************/ #include #include #include /*Global declaration */ int in_buffer[100]; int out_buffer[100]; #define TRUE 1 /*Function */ static int processing(int *input, int *output); static void dataIO(void); /*----- Main program ----- */ void main() { /***************************************************************** * Declare file pointers *****************************************************************/ int *input = &in_buffer[0]; /* input pointer */ int *output = &out_buffer[0]; /* output pointer */ /***************************************************************** * Start of main program *****************************************************************/ while(TRUE) { /* read in x(n) from data file and processing it */ /************************************************************* * IIR filtering: * y(n) = (1-alpha)*y(n-1)+alpha*x(n) *************************************************************/ /* Read using Probe Point connected to a host file. */ dataIO(); processing(input, output); } } /* function for signal processing */ static int processing(int *input, int *output) { int size = 100; float yn = 0.0; /* y(n), output from IIR filter */ float alpha = 0.25; /* alpha = 0.25 */ float alpha1 = 0.75; /* alpha1 = 1 - alpha = 0.75 */ while(size--){ /* *output++ = *input++*0.5; */ *output = (int)((alpha1*yn + alpha*((float)*input++))+0.5); yn = (float)*output++; } return(TRUE); } /* dataIO - function for data I/O */ static void dataIO () { return; }