view include/IirFilter.h @ 152:8f98b32d0e23 ClockSync

Last commit on this branch for a while. Overall not very succesful
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 05 Oct 2015 13:06:14 +0100
parents 6cd38e261027
children
line wrap: on
line source
/*
 * 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_ */