diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/IirFilter.h	Mon Sep 21 03:11:32 2015 +0100
@@ -0,0 +1,45 @@
+/*
+ * IirFilter.h
+ *
+ *  Created on: 17 Sep 2015
+ *      Author: giulio
+ */
+
+#ifndef IIRFILTER_H_
+#define IIRFILTER_H_
+
+#define IIR_FILTER_STAGE_COEFFICIENTS (5)
+#define IIR_FILTER_STAGE_STATES (IIR_FILTER_STAGE_COEFFICIENTS - 1)
+
+class IirFilterStage{ //TODO : to save (some) memory we should only store the coefficients pointers here,
+						//so that IirFilter can share them among multiple stages if needbe)
+private:
+	double coefficients[IIR_FILTER_STAGE_COEFFICIENTS]; // these are b0,b1,b2,a1,a2
+	double states[IIR_FILTER_STAGE_STATES]; // these are xprev, xprevprev, yprev, yprevprev
+public:
+	IirFilterStage();
+	void setCoefficients(double* newCoefficients);
+	void setStates(double* newStates);
+	double process(double in);
+	void process(double* inout, int length);
+	void process(double* in, double* out, int length);
+};
+
+class IirFilter{
+private:
+	struct IirFilterStage** stages;
+	int numberOfStages;
+	void dealloc();
+public:
+	IirFilter();
+	IirFilter(int newNumberOfStages);
+	IirFilter(int newNumberOfStages, double *newCoefficients);
+	void setCoefficients(double* newCoefficients);
+	void setStates(double* newStates);
+	void setNumberOfStages(int newNumberOfStages);
+	double process(double in);
+	void process(double* inout, int length);
+	void process(double* in, double* out, int length);
+};
+
+#endif /* IIRFILTER_H_ */