/************************************************************* * mov_avg.c - C program for moving-average filtering ************************************************************** * System configuration: * * x(n) |-----------------------| y(n) * ---->| moving-average filter |-----> * |-----------------------| * 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 const float bnCoef[4] = {0.25, 0.25, 0.25, 0.25}; void main() { void datamov(); // function to update signal vector float fir(); // function to perform FIR filtering /************************************************************* * Define variables and arrays *************************************************************/ int i; // array index int order = 4; // order of moving-average filter int input; // input data from integer file float xn = 0; // x(n), input from xn.dat file float yn = 0.0; // y(n), output from FIR filter float xnBuf[4]; // signal buffer for FIR filter /********************************************************** * Declare file pointers, open files, clear array **********************************************************/ FILE *xn_in; // file pointer of x(n) FILE *yn_out; // file pointer of y(n) xn_in = fopen("xn.dat","r"); // open file for input x(n) yn_out = fopen("yn.dat","w");// open file for output y(n) for (i=0; i