#include "stdint.h" #include "stdio.h" #include "calc.h" uint16_t raw[CALC_POINTS] = { 11555, 11501, 11432, 11370, 11307, 11250, 11186, 11131, 11083, 11008, 10968, 10901, 10858, 10794, 10754, 10695, 10651, 10603, 10554, 10505, 10470, 10418, 10374, 10336, 10287, 10249, 10215, 10169, 10140, 10097, 10056, 10024, 9992, 9953, 9934, 9891, 9867, 9837, 9806, 9782, 9764, 9742, 9704, 9685, 9667, 9644, 9623, 9612, 9591, 9576, 9559, 9545, 9537, 9526, 9516, 9502, 9489, 9482, 9474, 9469, 9460, 9460, 9456, 9452, 9452, 9463, 9453, 9457, 9456, 9468, 9474, 9476, 9486, 9490, 9504, 9513, 9527, 9542, 9545, 9568, 9579, 9598, 9610, 9632, 9656, 9671, 9696, 9722, 9744, 9763, 9799, 9812, 9850, 9881, 9904, 9927, 9980, 9995, 10034, 10063, 10112, 10143, 10176, 10224, 10258, 10296, 10344, 10383, 10417, 10465, 10515, 10559, 10608, 10651, 10702, 10752, 10804, 10853, 10905, 10952, 11010, 11070, 11129, 11179, 11233, 11289, 11357, 11418}; NUM_TYPE buff[CALC_POINTS]; struct quadratic_coefficient_s coeff; int main(void) { uint32_t c, r; for (int i = 0; i < CALC_POINTS; i++) { buff[i] = (NUM_TYPE)raw[i]; } calc_quadratic_fit_init(CALC_POINTS); calc_quadratic_fit(buff, &coeff, CALC_POINTS); printf("y = %f * x^2 + %f * x + %f\r\n", coeff.a, coeff.b, coeff.c); for (int i = 0; i < CALC_POINTS; i++) { c = (uint32_t)(coeff.a * i * i + coeff.b * i + coeff.c); r = (uint32_t)raw[i]; printf("fit[%d] = %d, raw = %d, err = %d\r\n", i, c, r, c - r); } return 0; }