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:
4:8db89b731133
Parent:
3:75f50dbedf1b
Child:
5:bfb6dbd37aa4
--- a/CubicSpline.h	Thu May 12 14:41:15 2016 +0000
+++ b/CubicSpline.h	Fri May 20 14:25:39 2016 +0000
@@ -17,58 +17,58 @@
 
 //  Vector Element Type
 typedef struct {
-    unsigned short x; //  
-    unsigned short y; //  distance
-} Vector2d;
+    double x; //  
+    double y; //
+    double t; //    use as pramameter of x,y.
+} Vxyt;
 
 enum UseType{
     AsDEBUG,
     AsMODULE
 };
 
-class Spline_2dCubic
+class CubicSpline2d
 {
 public:
     //  Constraction
-    Spline_2dCubic();
-    Spline_2dCubic(unsigned int);
-    Spline_2dCubic(unsigned int arg_NumSample, UseType arg_dit);
+    CubicSpline2d();
+    CubicSpline2d(unsigned int);
+    CubicSpline2d(unsigned int, UseType);
     //  Destraction
-    ~Spline_2dCubic();
+    ~CubicSpline2d();
     //  Functions
-    unsigned short getX();
-    unsigned short getY();
+    double  getX();
+    double  getY();
     void    calibrateSensor();
     void    saveSetting();
     void    saveSetting(const char *filename);
     void    loadSetting();
     void    loadSetting(const char *filename);
     void    printOutData();
-    void    printThresholds();
 
 private:
     //
     //  Variables
     //
-    unsigned int _Sample_Num;    // the number of samples for derive spline
-    Vector2d*    _Sample_Set;
     UseType      _useType;
-    double*      _u_param;
-    //
+    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;
+    // 
     //  For calibration
     //
     void    _sampleData();
-    void    _makeSpline();  //  Cubic spline
-    unsigned short _getSplineYof(double);
-    //
-    //  For get distance
-    //
-    int     _getNearest(int, int, unsigned short);
+    void    _makeModel();       //  generate a vector of _u_params which is used for Cubic spline model
+    enum 
+    unsigned short _get(double);
     //
     //  For debug
     //
     void    _printOutData(unsigned short    *arg, int num, char* name);
-    void    _printOutData(VDset             *arg, int num, char* name);
+    void    _printOutData(Vxyt              *arg, int num, char* name);
     void    _printOutData(double            *arg, int num, char* name);
 };
 #endif
\ No newline at end of file