giuliomoro@148: /* giuliomoro@148: * IirFilter.h giuliomoro@148: * giuliomoro@148: * Created on: 17 Sep 2015 giuliomoro@148: * Author: giulio giuliomoro@148: */ giuliomoro@148: giuliomoro@148: #ifndef IIRFILTER_H_ giuliomoro@148: #define IIRFILTER_H_ giuliomoro@148: giuliomoro@148: #define IIR_FILTER_STAGE_COEFFICIENTS (5) giuliomoro@148: #define IIR_FILTER_STAGE_STATES (IIR_FILTER_STAGE_COEFFICIENTS - 1) giuliomoro@148: giuliomoro@148: class IirFilterStage{ //TODO : to save (some) memory we should only store the coefficients pointers here, giuliomoro@148: //so that IirFilter can share them among multiple stages if needbe) giuliomoro@148: private: giuliomoro@148: double coefficients[IIR_FILTER_STAGE_COEFFICIENTS]; // these are b0,b1,b2,a1,a2 giuliomoro@148: double states[IIR_FILTER_STAGE_STATES]; // these are xprev, xprevprev, yprev, yprevprev giuliomoro@148: public: giuliomoro@148: IirFilterStage(); giuliomoro@148: void setCoefficients(double* newCoefficients); giuliomoro@148: void setStates(double* newStates); giuliomoro@148: double process(double in); giuliomoro@148: void process(double* inout, int length); giuliomoro@148: void process(double* in, double* out, int length); giuliomoro@148: }; giuliomoro@148: giuliomoro@148: class IirFilter{ giuliomoro@148: private: giuliomoro@148: struct IirFilterStage** stages; giuliomoro@148: int numberOfStages; giuliomoro@148: void dealloc(); giuliomoro@148: public: giuliomoro@148: IirFilter(); giuliomoro@148: IirFilter(int newNumberOfStages); giuliomoro@148: IirFilter(int newNumberOfStages, double *newCoefficients); giuliomoro@148: void setCoefficients(double* newCoefficients); giuliomoro@148: void setStates(double* newStates); giuliomoro@148: void setNumberOfStages(int newNumberOfStages); giuliomoro@148: double process(double in); giuliomoro@148: void process(double* inout, int length); giuliomoro@148: void process(double* in, double* out, int length); giuliomoro@148: }; giuliomoro@148: giuliomoro@148: #endif /* IIRFILTER_H_ */