Christian Weiß / Mbed 2 deprecated ProcVisDemo_Accel

Dependencies:   MMA7660 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TP1.h Source File

TP1.h

00001 // Digitaler Tiefpass 1. Ordnung
00002 
00003 class TP1Ord
00004 {
00005 private:
00006     float alpha; // Filterkonstante
00007 public:
00008     float yn_1;
00009     float y; // momentaner Ausgangswert des Filters
00010 public:    
00011     
00012     // Konstruktor wird automatisch aufgerufen
00013     // Variable der Klasse TP1Ord angelegt wird
00014     // interne Variablen sinnvoll initialisieren
00015     TP1Ord(); 
00016     
00017     // einen Abtastschritt des Filters rechnen
00018     // es entsteht ein neues y
00019     void CalcOneStep (float aX);
00020     
00021     void SetAlpha (float aAlpha);
00022 };
00023 
00024 TP1Ord::TP1Ord()
00025 {
00026     y = 0; yn_1 = 0;
00027     SetAlpha(0.1); // sinnvolles Alpha einstellen
00028 }
00029 
00030 void TP1Ord::SetAlpha (float aAlpha)
00031 {   
00032     // 0...1 absichern
00033     if(aAlpha >= 0 && aAlpha <= 1)
00034         alpha = aAlpha; 
00035 }
00036 
00037 void TP1Ord::CalcOneStep (float aX)
00038 {
00039     y = alpha*aX + (1-alpha)*yn_1;
00040     yn_1 = y; // y einmal merken (zwischspeichern)
00041 }