MiscEl: Curve fit

Back to MiscEl main page Write a message to author

This page does a curve fit on data. The resulting curve fit can be extracted either as a formula or as a table.
The formulas can be adapted to any high level computer language and be used for conversion of real world data to useable units. The tables can be used either in high level computer languages or in assembler language for fast conversion.

The curve fit works in multiple steps:

Algorithm supported

The fit can be done with different algorithms, not all algorithm are suitable for all data and sometimes a suitable algorithm might fail to fit. A failed fit can maybe be fixed by adding your own starting values.
Fit format: The higher degree fits will nearly always match the data better, BUT watch out for uncontrolled behaviour.
See Calculator for syntax and available functions when writing your own formula

Input values

The input values can be entered in different formats.
The X value must be listed in increasing values.
When the fitting is done the f(x) or y is the value that can be calculated form the x or time value.
Data format: *A space character can also sometimes be used as delimeter.
The "thermo-sensor" settings uses the page Thermo sensors to convert the supplied value to a temperature. The correct sensor must be selected on this page.
Any line starting with ; or / is ignored.
Fit startRestrict the used input data and the table output, only X values at or above this value will be used
Fit endRestrict the used input data and the table output, only X values at or below this value will be used
Fit stepsHow many steps to generate in the table
Add spline pointsExtend the input data with lots of extra points, these are calculated using the spline algorithm. This will sometimes improve a fit and prevent uncontrolled behaviour.
User fitYour own algorithm, the coefficents are named a,b,c... and input value is x
Initial guessStarting function for a fit algorithms, use the arrow to fill in the currently calculated coefficents. The checkbox can be used to lock a value, i.e. it will not be changed when doing a fit.
Save formatSave the result, either as a table or as a formula (Not all fits supports formulas), the save is always to the clipboard
UpdateForce a new fit calculation

Output values

ChiA measure of the fit quality, a low value is best
FitThe fit algorithm used
a,b,c,...The coefficents for the fit algorithm
Save format: When using a table, it is always possible to do a simple interpolation between entries, to get better resolution. The precision will depend on the type of data and the interpolation algorithm.
The most usefull tables are the ones with only the Y value, scale X to the table size and use the scaled X as index into the table.
Using ofs settings can increase the resolution in a smaller table (i.e. using int8 instead of int16).

2 Temp, thermo-sensor-inputvalue

This is not really a input data format, but a special function to generate tables for use with thermo sensors.
Four input values are required:
On first line: Min temperature and corresponding input value
On second line: Max temperature and corresponding input value

The "input value" will typical be the digital output from an ADC and the "temperature" will be the corrosponding temperature.
The operation performed will be as follow: The currently selected sensor on the Thermo sensors page will be used.
CAVEAT It is very important that the ADC measures the property that the Thermo sensors page uses as property for the sensor. I.e. if the sensors has resistance output, the ADC must measure resistance, not the voltage from a voltage divider! If your want to measure resistance, use a constant current source.


Calculator functions

The Calculator can do spline fits and evalute polynoms:

Other pages