/*--------------------------------------------------------- * * Finite Impulse Response (FIR) Filter (Uniprocessor) * */ #include #include"fir.h" #include // convention: weights[0] is multiplied by least delayed input short int weights[TAPS], inputVector[TAPS]; int vectorStart=0; long int fir(short int in) { int j; long int sum = 0; // 40 bits would be preferred // keep vectorStart bounded, code works for all % implementations vectorStart=(vectorStart+TAPS-1)%TAPS; inputVector[vectorStart] = in; for (j = 0; j < TAPS; j++) // inner product of weights sum += weights[j] * inputVector[(j+vectorStart)%TAPS]; return (sum); }