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