Low pass filter for Arduino/ESP8266/ESP32

Low pass filter for Arduino/ESP8266/ESP32

A low pass filter written as class for Arduino code

class LowPassFilter {
  
  private:
    float filter_constant;
    
  public:

    float output;
    
    LowPassFilter(float filter_constant) {
      // Constructor
      this->output = 0;
      this->filter_constant = filter_constant;
    }
    
    void feed(float input) {
      this->output = (this->output)*(1.00 - this->filter_constant) + input * (this->filter_constant);
    }
    
};

Top use it, simply instanciate a LowPassFilter object:

LowPassFilter lpf1(FILTER_CONSTANT);

Then feed values into it:

lpf1.feed(sample);

The output of the filter can be accessed using:

lpf1.output