LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate the equation from dataset using "Fitting VI's" (polynomial or nonlinear Fit) ?

Solved!
Go to solution

The funny thing and is the main reason I'm not satisfied with this equations is that If I substitute a value above 50 (degrees), the

calculated resistance its not even close to the real one (from thermistor table). So I'll try the equations you generate and see what happens.

 

Even thought I'm still figuring out how to use the NONLINEAR VI.... For example I have the next Steinhart-Hart equation:

1/T = A+B*Ln(R) + C*Ln(R)^3

 

I've calculated parameters A, B, C:

A=1.126249 e-3

B=2.345631 e-4

C=0.862140 e-7

Nonlinear VI.png

I have my X and Y and initial parameters ready. But how do I use this function... Haven't figure it out where to specify the model I'm a bit confused at the moment...

0 Kudos
Message 11 of 25
(2,387 Views)
Solution
Accepted by JLuna

The curve looks much nicer if you take the log of the Y data (and transform back later). Now a 3rd order polynomial is plenty (Just a slight "banana") and you don't get these negative values towards the end.

 

 

Download All
Message 12 of 25
(2,386 Views)

The nonlinear equation is basically a third order polynomial using the log(y) and setting the quadratic term to zero. There is no need to complicate things and use levenberg marquardt.

 


@JLuna wrote:

 

I have my X and Y and initial parameters ready. But how do I use this function... Haven't figure it out where to specify the model I'm a bit confused at the moment...


 There are two flavors of the nonlinear curve fit, one using VI model (preferred) and one using a formula. There are plenty of examples that ship with LabVIEW, just look at them!

0 Kudos
Message 13 of 25
(2,380 Views)

I just want to know which gives me the most accurate equation...

 

Many thanks btw 😄

0 Kudos
Message 14 of 25
(2,375 Views)

@JLuna wrote:

I just want to know which gives me the most accurate equation...\

 


How accurate are the table values? They have an error too!

 

Both methods will be similar. the third order polynomial to log(y) is easier to use. The Steinhart-Hart equation inverts the formula buts omits the quadratic term and you need to first rewrite it to solve for R(t).

 

You simply need to test it. For example if you do my log polynomial and change the order to 5, the maximum difference is below 100 while the values are hundreds of thousands! This is well below your 2% specification (0.04%). Even the third order as suggested earlier gives a max deviation below 0.4%, good enough!

 

Here's an example for the 5th order (use the right y axis for the scale of the difference between data and fit)

 

 

 

 

And here's the difference in percent of the reading:

 

 

Download All
Message 15 of 25
(2,369 Views)

I'm analizing the VI you shared, with log and power of 10 functions. Can you explain why did you choose to do that: first go for

LOG10 then after using the Polynomial Fit, you introduced data to the POWER10 function.

 

1 Question came up to mind. You have the POWER10 function affecting ONLY the output "Best polynomial Fit" and you did this

to be able to see the entire graph correctly... right? Because without it, the Polynomial Fit throws small values due to the previous

Log10 function. So the thing that confuses me is:

 

Why is the POWER10 not affecting the Coefficient values output...??

0 Kudos
Message 16 of 25
(2,355 Views)
Solution
Accepted by JLuna

We are fitting the log of the data to a polynomial, thus we need to reverse that to get it into the original mapping. The log is safe because we (hopefully!) never have a negative resistance.

 

The polynomial coefficients will be correct for the log of the data, so you also need to do 10^x after polynomial evaluation when calculating interpolated data.

Message 17 of 25
(2,351 Views)

Good day altenback,

 

I'm still a bit confused or more like  I haven't quite understand 100% (more like a 80%...) how did it ocurred to you that using a log10 (the power of 10 comes obvious, to get back to the original mapping) would work like a charm. The next is what I understand from this LOG10 method:

 

- Because the resistance values are so big (almost taking values of 800kohms) if we try to fit this values into a Polynomial equation, when we get to smaller values (for example: 2kohms) the polynomial fit tends to give us possibly negative values. So

the purpose of the LOG10 method is to work only with positive and small values, so this way the Polynomial FIT analysis tends to give out more accurate POLYNOMIAL COEFFICIENTS... This polynomial coefficients are the "small answer" due to the LOG10; in order to get the real values we have to POWERTO10 the previous values...

 

So I'm a right, did I get the big picture? I just want to fully understand your explanation. To know when and where apply logarithms, succesfully, pretty awesome way to go \m/.

 

Thanks for your support I really appreciated @altenbach,

 

Regards,

 

0 Kudos
Message 18 of 25
(2,329 Views)

Yes, the original Y data covers about three orders of magnitude. If you change the mapping of the y axis to logarithmic, it immediately looks much more tame, basically a line with a slight curvature. Obvously, this is much easier to describe with a low oder polynomial. (If it were a pure single exponential, it would be a straight line in the log mapping).

 

A polynomial is typically a descriptive tool and the coefficients often don't have a direct scientific meaning. So if taking the log makes the curve more suitable for polynomial fitting there is no reason not to use it. Note that you can use the natural log (base e) or log10 (or any other base), it does not matter as long as you undo it the corresponding way later.

 

Note that you probably want to convert from resistance to temperature (and not the other way around), so just swap the x and y inputs and take the log of the resistance.

 

Attached is a simple draft for one of your datasets.. when you run it(and whenever the order is changed), it calculates the polynomial of the desired order, then you can select any resistance and read the corresponding interpolated (or extrapolated) temperature. Modify as needed.

(also note that if you don't take the log, the polynomial fit will probably fail.)

 

0 Kudos
Message 19 of 25
(2,304 Views)

Of course with a bit more effort you can implement a nonlinear fit to the Steinhart-Hart equation. Now you get much better than 0.02 degrees difference with only three parameters. (The disadvantage is that you need to create a model VI and have reasonable parameter guesses for the fit.)

 

Download All
0 Kudos
Message 20 of 25
(2,298 Views)