# LUT - Maximum error of linear interpolation approximation

I'm currently using an LUT (Look-Up Table) stored in a microcontroller, to read the temperature from an NTC sensor. I'd like to achieve a precision which is known, it doesn't matter if it is not so high.

The first step in which I'm stuck is to know well the error introduced by evaluating an interpolation of two values in a LUT.

What I thought: If the LUT have 1°C steps, the maximum error using the intermediate value as discriminant, is 0.5°C. And (what I thought) the only final solution to this is that I can print on a display the value interpolated (i.e. 24.8°C) instead of the LUT (i.e. 25°C), but both have 0.5°C of error. The case of 24.8 +- 0.5°C it doesn't seems so meaningful. Maybe 24.5°C could be a better solution.

The second thought is that interpolating using two points separated by 1°C, are bringing an error which can be smaller than 0.5°C, since it is related to the ratio of second derivative of the curve and a factor of 1/8 times the step of the function (here 1°C) (https://en.wikipedia.org/wiki/Linear_interpolation#Linear_interpolation_as_approximation). But I'm not sure at all of what I am reading: supposing that I have the Steinhart-Hart equation, I do not have the second order derivative. Am I right? Any suggestion? Is this analysis necessary to make a correct estiamtion of the error?

• What is an LUT? Sep 25 '15 at 22:05
• Edit just made. Sep 25 '15 at 22:07
• Why not just work out the error for an insanely sampled set up points, and take the maximum? Sep 25 '15 at 22:11
• Taking the maximum is ok if I know what I am doing. The risk of your proposal is to obtain a final error that is insanely high or erroneously low. That why I need a tiny bit (just a bit) of math to be solved. Sep 25 '15 at 22:15
• My suggestion will give you a map of your actual error at many points, as finely grained as you want. Do with the data what you like, you don't need to take the maximum, but the method is guaranteed not to provide an erroneously low number. Sep 25 '15 at 22:34

The curve is smooth and monotonic, hence the maximum error is 0.5 degrees C.

The derivative of the function will give you the slope, higher order derivatives are necessary to find the maximum error. You could fit a cubic spline (matching the slopes on either side of the area of interest) to the data points and evaluate the maximum error analytically, but frankly it would be a much better approach to simply evaluate at a much finer resolution than your desired accuracy, just as @Scott suggested in his comment

Suppose you don't care about anything finer than 0.1°. You can easily evaluate over the entire range to 0.01 or 0.001 degrees C on a PC in seconds. The maximum error in those calculations will be +/- 0.005 or +/-0.0005 degrees C respectively, since the curve is smooth and monotonic at any resolution.

Doing an simple brute-force exhaustive search will provide confidence on the maximum error. Unless your range is very narrow, or your ADC very fine resolution, you'll probably run into resolution errors with a typical thermistor long before you have unacceptable linearization errors.

• I presume that sampling to obtain the table will require a measurement set-up with a tolerance far smaller than what I obtain from the NTC. The table that I'm using is provided from Vishay. But if this is not present, I can use the Steinhart equation and sampling its plot (and the DS provides also the error provided by the function, which will sum on the others). Sep 25 '15 at 22:43
• The datasheet values are probably calculated by S-H or extended S-H, not measured. You can test that the values agree. Sep 25 '15 at 22:48
• Steinhart-Hart. So you use Steinhart-Hart and verify that the values agree with the table in the datasheet first. Sep 25 '15 at 23:03
• Yes, the sensor tolerances will affect the system error. Sep 26 '15 at 20:06
• Oh, you could add a simple offset or a 25°C offset + span (gain) diddle term to the linearized temperature output without changing the SH terms, but at some point a better sensor is the right way to go. Especially since we don't have a good model of what unit-to-unit variations look like beyond the 'bowtie' chart. Probably a 'beta' variation models it, but that's inside info at the thermistor maker. Often we require interchangeability and don't want to add stuff that can screw up the reading worse than the factory calibration so we don't even try. Sep 27 '15 at 13:42

Your error depends HIGHLY upon the nature of the underlying function. Even so, your error for a 1 degree table should be SUBSTANTIALLY less than 0.5 degrees. In fact, under your conditions, I think the expected value of the error even if you just take the nearest point with zero interpolation (a zero order approximation) is 0.5 degrees.

• That is exactly what I said. For this reason I was trying to see how much less than 0.5 could be. Sep 25 '15 at 22:18
• @thexeno, it could be a great deal higher than 0.5 if the function is not well behaved-- but an NTC sensor will not be that badly behaved. Sep 25 '15 at 22:36