AccelTest_Baseb

Dependencies:   MMA7660 Serial_HL mbed

TP1Ord_18.h

Committer:
martwerl
Date:
2018-11-15
Revision:
1:0c47899d1aba

File content as of revision 1:0c47899d1aba:



// Digitaler Tiefpass 1er Ordnung

class TP1Ord {
	private:
		float alpha; // Filter-Constante
	public:
		float yn_1;
		float y; // momentaner Ausgangswert des Filters
	public:
		// Konstruktor wird automatisch aufgerufen wenn eine
		// Variable der Klasse TP1Ord angelegt wird.
		// interne Variablen sinnvoll initialisieren
		TP1Ord(); 
	
	  // einen Abtastschritt des Filters rechnen
		// es entsteht ein neues y
		void CalcOneStep(float aX);
	
		void SetAlpha(float aAlpha);
};

TP1Ord::TP1Ord()
{
	y=0; yn_1=0;
	SetAlpha(0.1); // sinnvalles Alpha einstellen
}

void TP1Ord::CalcOneStep(float aX)
{
	y = alpha*aX + (1-alpha)*yn_1;
	yn_1 = y; // y einmal merken ( zwischenspeichern )
}

void TP1Ord::SetAlpha(float aAlpha)
{ // 0..1 absichern
	if( aAlpha>=0 && aAlpha<=1 )
		alpha = aAlpha;
}