Some mathematical analysis

...And another cute little calculator.

formatting link
Working code included!

Tim

-- Seven Transistor Labs, LLC Electrical Engineering Consultation and Contract Design Website:

formatting link

Reply to
Tim Williams
Loading thread data ...

Lately we just throw polynomials at things like this. Fortunately, we use ARMS in embedded things so we don't worry about resources, memory and compute power, much any more.

Thermistors sure are cheap, a few cents maybe.

--

John Larkin         Highland Technology, Inc 

lunatic fringe electronics
Reply to
John Larkin

For 20c to 60c a thermistor is pretty linear, work well for me at least.

Cheers

Reply to
Martin Riddle

oops, should have been 0c to 60c

Cheers

Reply to
Martin Riddle

formatting link

is the traditional choice for a thermistor fitting function. It's good to about a thousandth of degree over a respectable range, if you calibrating measurements were accurate and numerous enough in the first place.

It has three parameter, so you need at least three well-spaced measurements to set them up. More can give you a bit more confidence, if you know enough to do a non-linear multiparameter least squares fit to the data.

The programs I used - and the one I wrote for my particular job (which wasn't calibrating thermistors) also spat out confidence limits on the parameters.

formatting link

--
Bill Sloman, Sydney
Reply to
bill.sloman

There's a marvellous program called LAB Fit which will do this, usually IME with better results than polynomials. It seems to try all sorts of formulae to find the best fit, you enter the data, specify the number of parameters, press the button and it churns out a whole load of results, ranked by 'goodness'.

Here's one I made previously using the manufacturer's numbers from the datasheet...

T('C) = (-66120 + N)/(-248 + 0.00372 * N) - 0.002782 * N

Cheers

--
Syd
Reply to
Syd Rumpo

It was a bit harder on the engineers when the first digital thermistor thermometers came out ca. 20 years ago- they used an algorithm run on a 4-bit micro with a ~14 bit resistance to digital (RC based with a reference resistor) ADC (the latter required because of the resolution problem with thermistors over a wide temperature range).

For the acccuracy of temperature measurement around room temperature,

--sp

--
Best regards,  
Spehro Pefhany 
Amazon link for AoE 3rd Edition:            http://tinyurl.com/ntrpwu8
Reply to
Spehro Pefhany

That's an interesting program, I'll check it out.

Polynomials tend to be ill-conditioned numerically, especially when you naively use a high-order polynomial to produce an almost-linear function. It can require double precision math to get 12 bit results, even with ~12th order polynomials. I remember the problems an early prototype instrument I designed had (now 25 years ago!) with 'noise' which turned out to be numerical in nature.

The best method if you don't want to think about and have plenty of resources it is to use cubic splines, which are like the old piecewise linear approximations except using low-order (cubic) polynomials with the derivatives matched at the transition points so the curve is differentiable (smooth). Of course you need to store many more coefficients, but that's usually not an issue with today's processing power. Similarly, double-precision floating-point math is available in hardware on relatively inexpensive processors these days. Put the two together, and even a 24-bit+ ADC will not be compromised.

--sp

--
Best regards,  
Spehro Pefhany 
Amazon link for AoE 3rd Edition:            http://tinyurl.com/ntrpwu8
Reply to
Spehro Pefhany

I remember struggling to meet time and code space budgets on simple

8-bit micros with no multiply opcode, much less floats. I don't miss that a bit.

Recently I needed a time-vs-voltage circuit, which might have been a capacitor, a current source, and a comparator. It was easier to dump the current source and charge the cap through a resistor, and use a polynomial to math out the main exponential and some secondary errors, like esd diode varicap effects.

--

John Larkin         Highland Technology, Inc 

lunatic fringe electronics
Reply to
John Larkin

For nearly-linear functions the trick is to use the Horner decomposition starting from the highest power and scaling the intermediate results under way.

--

-TV
Reply to
Tauno Voipio

Take a closer look at the last code passage. :)

Tim

--
Seven Transistor Labs, LLC 
Electrical Engineering Consultation and Contract Design 
Website: http://seventransistorlabs.com
Reply to
Tim Williams

Yeah, that was the first fancy one I plotted -- it's often touted that the cubic term is negligible, but the results prove that leaving it out is as bad as calling it linear in the first place!

It does give the least number of free parameters, seemingly. Such a pain to calculate on an integer platform, though!

Handy. As you can see from the spreadsheet, I just used the manual approach of calculating the squared error, solving for least with the built-in tool.

Tim

--
Seven Transistor Labs, LLC 
Electrical Engineering Consultation and Contract Design 
Website: http://seventransistorlabs.com
Reply to
Tim Williams

Yeah, I've seen that before. Should use it some time, but I don't do this often enough to have bothered yet...

I also find my knowledge of math functions to be more useful for related properties, that are harder to constrain without knowledge of. Physical validity[1], continuity and smoothness (derivatives) (important for optimizing parameters, and executing in SPICE if needed), and more than anything else really: which functions are easiest to compute on a given platform.

[1] A sum-of-reciprocals function can be seen as the voltage divider equation's reciprocal content, plus a reciprocal approximating log(x) near x=1. So, it's a physically valid equation, as long as you don't look /too/ closely. A polynomial can simply be anything, so physical validity (or its absence) is trivial to determine! ;-) The log-reciprocal function (Steinhart-Hart equation) worked very nicely (I suppose giving the best physical representation).

Ah yup, that looks very similar to my "sum of reciprocals" formula (give or take constants). Pretty accurate for not many parameters.

Rational polynomials (i.e., of the type P_i(x) / Q_j(x), where i and j are the order of the numerator P and denominator Q polynomials) give far better fits than plain polynomials do, with fewer coefficients. Especially for functions that are smoothly varying with relatively extreme excursions (think frequency response transfer functions!).

Division is hard on a computer, though. It seems strange when a log operation is really only a few times slower; you should think a transcendental function would be a huge amount worse!

Tim

--
Seven Transistor Labs, LLC 
Electrical Engineering Consultation and Contract Design 
Website: http://seventransistorlabs.com
Reply to
Tim Williams

Hah! What kind of engineer writes a solution and doesn't check it? :^)

As can be seen in my spreadsheet (and the error plots), I've been constantly checking these curves for fitness, and the finished result of the power series contains quantization noise that's a bit smaller than the curve-fitting error.

Though 25 years ago, you may not've had as much luxury for calculating and plotting. Well, let's see, Excel was around then, but probably most people used Lotus 1-2-3?

Would've been a lot slower though. :)

Yeah, I speculated on this, but didn't try anything. I should've; it may well be better than the power series. It should only take a couple segments to get an excellent fit. The data-per-segment is a bit over double a PWL fit, but the fitness is maybe fourfold better. Downside: you're down in the noise here, as far as how many times the curve needs to be divided -- so high-performance Big-Oh's don't do you very much.

Tim

--
Seven Transistor Labs, LLC 
Electrical Engineering Consultation and Contract Design 
Website: http://seventransistorlabs.com
Reply to
Tim Williams

Sure, did that, or it would never have worked at all with fixed point, but you still end up subtracting almost-equal numbers that have a large effect on the result so the resolution goes to pot. It's a bit like the Gibbs phenomenon with square wave approximation.

There is no excuse ever for not using Horner to evaluate a poly.

--sp

--
Best regards,  
Spehro Pefhany 
Amazon link for AoE 3rd Edition:            http://tinyurl.com/ntrpwu8
Reply to
Spehro Pefhany

I had a 386, and not enough horsepower/software to actually simulate. It was all run on the target 6305 emulator, very slowly.

--sp

--
Best regards,  
Spehro Pefhany 
Amazon link for AoE 3rd Edition:            http://tinyurl.com/ntrpwu8
Reply to
Spehro Pefhany

to

ng

e

It's the square term which is typically negligible and generally left out.

f

the

to

Sure. Which is why look-up tables are so popular. Steenhart-Hart has been a round for a while - since 1968, according to Wikipedia - and does seem to b e the function to beat.

ach

l.

It might pay you to learn a bit about the built-in tool.

The multi-parameter least squares non-linear curve-fitting tools tend to bu ild up a picture of the shape of the valley around the minimum while moving towards it, and this can be exploited (after you have got there) to predic t how a small amount of noise in the data could shift each parameter away f rom the minimum while the other parameter adjust to stay as close as possib le to the bottom of the valley. It's not particularly complicated.

--
Bill Sloman, Sydney
Reply to
bill.sloman

Nah, real men use Clenshaw's rule with Chebyshev expansions. Polynomials written out as sums of powers are horribly ill-conditioned at even moderate orders, because the powers-of-x basis is very very nearly linearly dependent, whereas Chebyshevs are orthonormal--they're sines and cosines with a warped X axis.

OTOH Horner is a lot better than a*x**3+b*x**2+c*x+d, which you see a lot.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

Would have been Mathcad 2.0 in my case. Still use it occasionally, but for most things I use Mathcad 2001i Pro, which I got for $20 on eBay awhile back. Runs well under Wine, no spyware, no subscription fee.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

That last one is what I would do. Phil can you tell us again a good book/ reference for this type of stuff.

And when using a Chebyshev do you define the range such that -1 < x < +1 ?

formatting link

George H.

Reply to
George Herold

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.