annotate include/IirFilter.h @ 148:6cd38e261027 ClockSync

Simple IirFilter class
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 21 Sep 2015 03:11:32 +0100
parents
children
rev   line source
giuliomoro@148 1 /*
giuliomoro@148 2 * IirFilter.h
giuliomoro@148 3 *
giuliomoro@148 4 * Created on: 17 Sep 2015
giuliomoro@148 5 * Author: giulio
giuliomoro@148 6 */
giuliomoro@148 7
giuliomoro@148 8 #ifndef IIRFILTER_H_
giuliomoro@148 9 #define IIRFILTER_H_
giuliomoro@148 10
giuliomoro@148 11 #define IIR_FILTER_STAGE_COEFFICIENTS (5)
giuliomoro@148 12 #define IIR_FILTER_STAGE_STATES (IIR_FILTER_STAGE_COEFFICIENTS - 1)
giuliomoro@148 13
giuliomoro@148 14 class IirFilterStage{ //TODO : to save (some) memory we should only store the coefficients pointers here,
giuliomoro@148 15 //so that IirFilter can share them among multiple stages if needbe)
giuliomoro@148 16 private:
giuliomoro@148 17 double coefficients[IIR_FILTER_STAGE_COEFFICIENTS]; // these are b0,b1,b2,a1,a2
giuliomoro@148 18 double states[IIR_FILTER_STAGE_STATES]; // these are xprev, xprevprev, yprev, yprevprev
giuliomoro@148 19 public:
giuliomoro@148 20 IirFilterStage();
giuliomoro@148 21 void setCoefficients(double* newCoefficients);
giuliomoro@148 22 void setStates(double* newStates);
giuliomoro@148 23 double process(double in);
giuliomoro@148 24 void process(double* inout, int length);
giuliomoro@148 25 void process(double* in, double* out, int length);
giuliomoro@148 26 };
giuliomoro@148 27
giuliomoro@148 28 class IirFilter{
giuliomoro@148 29 private:
giuliomoro@148 30 struct IirFilterStage** stages;
giuliomoro@148 31 int numberOfStages;
giuliomoro@148 32 void dealloc();
giuliomoro@148 33 public:
giuliomoro@148 34 IirFilter();
giuliomoro@148 35 IirFilter(int newNumberOfStages);
giuliomoro@148 36 IirFilter(int newNumberOfStages, double *newCoefficients);
giuliomoro@148 37 void setCoefficients(double* newCoefficients);
giuliomoro@148 38 void setStates(double* newStates);
giuliomoro@148 39 void setNumberOfStages(int newNumberOfStages);
giuliomoro@148 40 double process(double in);
giuliomoro@148 41 void process(double* inout, int length);
giuliomoro@148 42 void process(double* in, double* out, int length);
giuliomoro@148 43 };
giuliomoro@148 44
giuliomoro@148 45 #endif /* IIRFILTER_H_ */