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
CubicSpline.h
- Committer:
- aktk
- Date:
- 2016-05-20
- Revision:
- 5:bfb6dbd37aa4
- Parent:
- 4:8db89b731133
- Child:
- 7:e032ddec6ed5
File content as of revision 5:bfb6dbd37aa4:
/** * Spline_Cubic.h,.cpp * * Author: aktk, aktk.j.uec@gmail.com * Tokyo, Japan. * * LOG: * ver.0 2016/02.12 - 2016/02/16 * TRP105F_Spline.h,.cpp(Ver.2.1) * ver.1 2016/05.12 */ #ifndef Cubic_Spline_H #define Cubic_Spline_H #include "mbed.h" // Vector Element Type typedef struct { double x; // double y; // double t; // use as pramameter of x,y. } Vxyt; enum UseType{ AsDEBUG, AsMODULE }; class CubicSpline2d { public: // Constraction CubicSpline2d(); CubicSpline2d(unsigned int); CubicSpline2d(unsigned int, UseType); // Destraction ~CubicSpline2d(); // Functions double getX(); double getY(); void calibrateSensor(); void saveSetting(); void saveSetting(const char *filename); void loadSetting(); void loadSetting(const char *filename); void printOutData(); private: // // Variables // 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; // // 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); // // For debug // void _printOutData(unsigned short *arg, int num, char* name); void _printOutData(Vxyt *arg, int num, char* name); void _printOutData(double *arg, int num, char* name); }; #endif