Electronics > Projects, Designs, and Technical Stuff
4th order polynomial coefficients for pressure at temperature readings, Help!!!
CatalinaWOW:
--- Quote from: IanB on August 21, 2020, 08:29:54 pm ---
--- Quote from: itsbiodiversity on August 21, 2020, 11:27:48 am ---Those are the coefficients NOMINAL ANIMAL. Exactly. Now I need to figure out how to calculate those myself based on any dataset using excel. I tried to download Gnuplot but had some issues installing.
--- End quote ---
As I mentioned in an earlier post, this is easily done using the Excel solver add-in (it is included with every version of Excel, but it does not show up on ribbon by default--you have to add it).
With the solver add-in you can say "vary these cells to minimize the value of that cell". It becomes quite easy to do all sorts of regressions that way.
--- End quote ---
I heartily endorse this. There are closed form solutions to many regression problems, but the math gets difficult quickly for more complex forms. This method works easily and for a very broad class of problems. You do occasionally get convergence problems, which can often be solved by changing initial state or selecting other options in the solver setup, like bounding values for some of the coefficients or changing the form of the model.
The key point is that for a variety of reasons a lowest sum of squared errors is a "best" answer. Do be aware that other definitions of best exist and may be appropriate to specific cases. Lowest maximum error for example.
Doctorandus_P:
Why not just keep it simple?
Measure some reference points, and then do linear interpolation between those points.
You may need a few more points, (10 or so is usually plenty) but it makes the software much easier to understand, write, maintain, modify, etc.
The Electrician:
--- Quote from: itsbiodiversity on August 19, 2020, 01:38:10 pm ---
The author of the instrument stated the following:
Enter Temperature Coefficients
This command provides for the entry of temperature coefficients that will compensate the sensor for ambient temperature conditions. The coefficients are determined during the factory calibration process.
tcomp <a0> <a1> <a2> <a3> <a4> (THESE ARE WHAT I AM TRYING TO IDENTIFY) :)
The operator specifies five coefficients, which are used in a fourth order polynomial that corrects temperature readings for the ambient temperature at the sensor.
The currently effective temperature compensation coefficients can be viewed using the coef command, which is described in the user’s manual.
default is 0 0 1 0 0.
Does this make sense? I feel like this is close to what you were describing. I'm attaching another spreadsheet here, and I'm also downloading the program you mentioned. Thank you so much.
--- End quote ---
'
What is the independent variable (and its powers) which the temperature compensation coefficients are multiplying?
If you use the "coef" command, what are the currently effective coefficients?
Edit:
I see that the answer to my questions can be found in reply #39 and #41
Here is how I derived a least squares solution using some matrix methods:
I solved this with an HP50G calculator and got 9 correct digits for a1, and 12 correct digits for a2.
Nominal Animal:
--- Quote from: Doctorandus_P on August 27, 2020, 12:05:50 am ---Why not just keep it simple?
--- End quote ---
Because it is the device itself that internally uses \$P(p, c) = a_0 + a_1 c + a_2 p + a_3 p c + a_4 p c^2\$ to apply pressure \$p\$ and "temperature count" \$c\$ compensation to the pressure reading it provides.
--- Quote from: The Electrician on August 27, 2020, 01:09:59 am ---I solved this with an HP50G calculator and got 9 correct digits for a1, and 12 correct digits for a2.
--- End quote ---
Except that that least squares fit (which is most commonly used) gives you maximum error an order of magnitude larger than gradient descent optimization (which yields \$a_0 = 0.007697997673805127\$, \$a_1 = -9.893590127282349\cdot 10^{-7}\$, \$a_2 = 0.9937816855224063\$, \$a_3 = 1.353571043339379 \cdot 10^{-6}\$, and \$a_4 = -6.784307221818112\cdot 10^{-11}\$).
Why do I care? Because if OP is doing recalibration before giving the devices to actual users, I want those users to have the best readings they can. Least squares regression is most commonly used to fit device parameters to calibration data, but popularity does not mean it is the best method. In this instance, I have already shown how using the exact same calibration data, you can reduce the maximum error by a factor of 10. Why so many members here think that is irrelevant or not worth the effort, boggles my mind.
The Electrician:
--- Quote from: Nominal Animal on August 27, 2020, 11:49:47 am ---
--- Quote from: The Electrician on August 27, 2020, 01:09:59 am ---I solved this with an HP50G calculator and got 9 correct digits for a1, and 12 correct digits for a2.
--- End quote ---
Except that that least squares fit (which is most commonly used) gives you maximum error an order of magnitude larger than gradient descent optimization (which yields \$a_0 = 0.007697997673805127\$, \$a_1 = -9.893590127282349\cdot 10^{-7}\$, \$a_2 = 0.9937816855224063\$, \$a_3 = 1.353571043339379 \cdot 10^{-6}\$, and \$a_4 = -6.784307221818112\cdot 10^{-11}\$).
--- End quote ---
Using these coefficients I get the same result you reported in reply #49:
"No need to believe me, though. Just use the curve fitting package you think does better or even just as well, and see if it discovers the minimum I reported a couple of messages back, that minimizes the maximum error among the calibration samples to 0.002421 pressure units. In comparison, least squares fitting only reaches a minimum error a magnitude larger (around 0.02, depending on details)."
But you pay for a smaller maximum (absolute) error with a larger residual for the GDO method, namely .009256, compared to a residual for least squares of .007665
I don't find the maximum absolute error for a least squares solution to be "around .02", but rather I get .005115, which is only about twice the GDO error, not 10 times. This problem has a condition number of about 2.646E9, which is why I used rational arithmetic to solve it rather than floating point, otherwise errors in results may be larger than expected at first glance.
This is often a choice to be made as to the "best" method; minimize absolute error, or residual.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version