Ruprecht Altenburger / Misc_Lib

Dependents:  

Files at this revision

API Documentation at this revision

Comitter:
altb
Date:
Thu Oct 04 16:25:37 2018 +0000
Parent:
0:d784b08f51ff
Child:
2:0f646bde6074
Commit message:
..

Changed in this revision

PolynomialCharacteristics.cpp Show annotated file Show diff for this revision Revisions of this file
PolynomialCharacteristics.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PolynomialCharacteristics.cpp	Thu Oct 04 16:25:37 2018 +0000
@@ -0,0 +1,27 @@
+#include "PolynomialCharacteristics.h"
+#include "math.h"
+using namespace std;
+PolynomialCharacteristics::PolynomialCharacteristics(float *P,uint8_t degree,float ll, float ul){    // standard lin characteristics
+    this->P = (float*)malloc(degree*sizeof(float));
+    for(int k=0;k<=degree;k++)
+        this->P[k] =P[k];
+    this->degree = degree;
+    this->llim = ll;
+    this->ulim = ul;
+    
+}
+
+PolynomialCharacteristics::~PolynomialCharacteristics() {}
+
+
+float PolynomialCharacteristics::evaluate(float x)
+{   
+float dum = 0.0;
+for(int k=0;k<=degree;k++)
+    dum = P[k]*pow(x,(float)k);
+if(dum > this->ulim)
+    dum = this->ulim;
+if(dum < this->llim)
+    dum = this->llim;
+return dum;
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PolynomialCharacteristics.h	Thu Oct 04 16:25:37 2018 +0000
@@ -0,0 +1,28 @@
+// Polynomial Characteristics for different purposes (map Voltage to acc etc.)
+
+
+#ifndef POLYNOMIALCHARACTERISTICS_H_
+#define POLYNOMIALCHARACTERISTICS_H_
+#include "mbed.h"
+
+class PolynomialCharacteristics{
+     public:
+            PolynomialCharacteristics(float *, uint8_t, float, float);
+            float evaluate(float);
+            float operator()(float x){
+                return evaluate(x);
+                } 
+                //...
+                virtual     ~PolynomialCharacteristics();
+                // here: the calculation function
+    
+    private:
+        // here: private functions and values...
+        float *P;
+        float degree;
+        float ulim;
+        float llim;
+};
+
+
+#endif      // LINEAR_CHARACTERISTICS_H_
\ No newline at end of file