This lib is considered to be used as a sensor's calibration program. Calibration with Spline Interpolation might be useful in the case that you want some model expressing relationship such like between a value of physical quantity and your sensor's voltage, but you cannot estimate a model such as liner, square, cubic polynomial, or sine curve. This makes (Parametric) Cubic Spline Polynomial Model (Coefficients of the polynomial) from some sample plots(e.g. sets of (value, voltage)). The inverse function (x,y)->(y,x) has been implemented so as to get analog data (not stepping or leveled data).

Fork of TRP105F_Spline by Akifumi Takahashi

Revision:
7:e032ddec6ed5
Parent:
5:bfb6dbd37aa4
Child:
8:e7d451bb4fd4
--- a/CubicSpline.h	Fri May 20 14:28:42 2016 +0000
+++ b/CubicSpline.h	Tue May 24 17:37:27 2016 +0000
@@ -13,16 +13,18 @@
 #define Cubic_Spline_H
 
 #include "mbed.h"
+#include <cmath>
+#include <complex>
 
 
 //  Vector Element Type
 typedef struct {
-    double x; //  
+    double x; //
     double y; //
     double t; //    use as pramameter of x,y.
 } Vxyt;
 
-enum UseType{
+enum UseType {
     AsDEBUG,
     AsMODULE
 };
@@ -53,17 +55,39 @@
     UseType      _useType;
     unsigned int _Sample_Num;   //  the number of samples for derive spline
     Vxyt*        _Sample_Set;
-    double*      _C_x[4];    //x = Spline-fx(t) = _C_x[0] + _C_x[1]t + _C_x[2]t^2 + _C_x[3]t^3
-    double*      _C_y[4];    //y = Spline-fy(t) = _C_y[0] + _C_y[1]t + _C_y[2]t^2 + _C_y[3]t^3
-    //double*      _u_param_x;
-    //double*      _u_param_y;
-    // 
+    double*      _C_x[4];    //x = Spline-f(t) = _C_x[0]  + _C_x[1]t  + _C_x[2]t^2  + _C_x[3]t^3
+    double*      _C_y[4];    //y = Spline-f(t) = _C_y[0]  + _C_y[1]t  + _C_y[2]t^2  + _C_y[3]t^3
+    //
+    //
+    //
+    Vxyt        _LastPoint;
+    //
     //  For calibration
     //
+    //  sampling data for calibration
     void    _sampleData();
     //  generate a vector of _u_params which is used for Cubic spline model
-    void    _makeModel(double* arg_t, double* arg_ft, double* arg_C[4], unsigned int arg_num);
-    unsigned short _get(double);
+    void    _makeModel(
+        const double* arg_sampled_t,
+        const double* arg_sampled_ft,
+        /*-*/ double* arg_C[4],
+        const unsigned int arg_num = _Sample_Num
+    );
+    //
+    //  For calculation
+    //
+    //  Fuction to return the value of Cubic polyminal f(t)
+    double  _cubic_f(
+        const double  arg_t,
+        const double* arg_C[4]
+    );
+    //  Function to solve a cubic poliminal
+    //  by using Gardano-Tartaglia formula
+    void _solve_cubic_f(
+        std::complex<double>* arg_t,
+        const double* arg_C[4],
+        const double  arg_ft
+    );
     //
     //  For debug
     //