FIR filter library (low pass filter)

I converted the code from this old thread to an arduino library: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279123369/3
I searched for a low pass filter using FIR but could not find any in the new forum. Perhaphs this library will be useful for someone else.
GitHub - sebnil/FIR-filter-Arduino-Library: FIR filter Arduino Library
Credits to Rene Knuvers for the initial code and to AlphaBeta for making it libraryesque. I just did the work of converting it to a working Arduino library. The main purpose of this thread is to have at least one FIR filter thread active and hopefully make improvements to the library code.

I used it in my project building a selfbalancing robot.

Example:

#include <FIR.h>
#define FILTERTAPS 5
FIR fir;

void setup() {

	Serial.begin(115200);	// open the serial port, I like them fast ;-)

	// declare variables for coefficients
	// these should be calculated by hand, or using a tool
	// in case a phase linear filter is required, the coefficients are symmetric
	// for time optimization it seems best to enter symmetric values like below
	float coef[FILTERTAPS] = { 0.021, 0.096, 0.146, 0.096, 0.021};
	fir.setCoefficients(coef);

	  //declare gain coefficient to scale the output back to normal
	float gain = 0.38; // set to 1 and input unity to see what this needs to be
	fir.setGain(gain);
}

void loop() {

	// declare input and output variables
	float input = 1; // without a real input, looking at the step respons (input at unity, 1) would be nice to see
	float output = 0; // output as a 0, but that doesn't really matter

	// This is the loop that takes care of calling the FIR filter for some samples

	for (byte n = 0; n < FILTERTAPS + 2; n++) { 		// If you like to see the step response, take at least as many cycles as the length of your FIR filter (FILTERTAPS + 1 or 2)
		Serial.print("n= ");		// print the sample number
		Serial.println(n, DEC);
		Serial.println("Now calling fir...");
		output = fir.process(input);		// here we call the fir routine with the input. The value 'fir' spits out is stored in the output variable.
		Serial.print("fir presented the following value= ");
		Serial.println(output);		// just for debugging or to understand what it does, print the output value
	}

	while (true) {};			// endless loop
}

hi
i believe that there is a mistake in tour code.
i checked it for a 17 taps low pass filter and the step response was wrong, then i changed the example code a bit so i would get the impulse response which is suppose to return the filter coefficients but is was wrong too.

fir_try.ino (1.78 KB)

Thank you for this lib. I planned to write a 4 tap low pass FIR und found your post here. It just took a few minutes to include your lib and to use two filter channels. 5 tap filter works also fine for me. Great work, helped me a lot.