ดูการคำนวนได้ใน web นี้ ผมเอามาแปะไว้นะครับ http://robotics-wr.blogspot.com/2013/03/curve-fitting-for-non-linear-alcohol.html
MQ3 ALCOHOL SENSOR CURVE FITTING
Based on MQ3 alcohol sensor graph of mg/L vs Rs/Ro I´ve got four important points
Remembering my video about linear regression that can be done with any set of linear independent functions, I must remark that the shape of the points will be helpful to select the group of linear independent functions to create a curve fitting, this method is more useful than any interpolating polynomial based method because the points are unequally spaced and this spaces in the case of 10 mg/L if far from the others due the non linearities of the sensor, if we interpolate using Lagrange or Cubic Splines we for sure will get oscilation of the polynomial that is an outrageous behaviour that is common when we interpolate points that are located far from the others, this oscillations deformate the curve this makes unuseful this methods, by intance we could get negative resistences due an oscilation for this unequal spaces between points.
Two more comments, most of the sensors have a nonlinear behaviour with curves or set of points resembling an e^-nx function thus we can fit a curve using a function like the one described on the next image.
Once we have stablished the function we create the next matrix evaluating this points on each of the linear independent functions we must multiply both matrices by the transpose matrix of A then we will get a 4x4 matrix to obtain 4 coefficients solving with Gauss elimination
I get the values for Bo to B4 and plot the function, as you can see the four points are part of the result curve. thus we can calculate more points with a certain error, remember the voltage divider linerizes the values delivered to the ADC, however, It is important to know how to create a mathematical function to fit the known points of a sensor.