SBOA537 March   2022 TMP61 , TMP61-Q1 , TMP63 , TMP63-Q1 , TMP64 , TMP64-Q1

 

  1.   Trademarks
  2. 1Capturing the Data
  3. 2Creating the Plot for the Fourth-Order Polynomial
  4. 3Creating the Scatter Plot
  5. 4Creating a Polynomial for the Collected Data
  6. 5C Code
  7. 6Creating a Polynomial for an NTC
  8. 7Summary

Creating a Polynomial for the Collected Data

Polynomial curve fitting is the process of constructing a curve or mathematical function that has the best fit to a series of data points. In mathematics, a polynomial is an expression consisting of indeterminates and coefficients, that involves only the operations of addition, subtraction, multiplication, and non-negative integer exponentiation of variables. In theory, the polynomial coefficients are always positive and the function has operations of addition, subtraction, and multiplication. The goal in programming is to fix the code and only have to change out the coefficients. A polynomial equation is modified in code to only use addition and multiplication so that the formula remains constant. So positive and negative coefficients are used to perform the addition and subtraction needed. For the TMP6 parts, a 4th-order polynomial is used to get the best curve fit for the near linear curve of the PTC thermistor.

Use the following steps to create the polynomial from the Microsoft Excel scatter plot previously created. Follow the flow in Figure 4-1 for each step of the process.

  1. Right click the plot line
  2. Select Add Trendline, then the trendline must be formatted
  3. Select the Polynomial trendline option
  4. Change the Order to "4", for 4th-order
  5. Check the box for Display Equation on chart
  6. Check the box for Display R-squared value on chart
GUID-24407386-AE52-4E2A-864A-9021B5E61E7F-low.png Figure 4-1 Polynomial Flow

Use 6 digits of precision in the coefficients to maintain the accuracy of the calculations as much as possible. Figure 4-2 shows how to change the format of the label to get the required digits for the coefficients.

  1. Right click the label for the polynomial and select Format Trendline Label
  2. Change the category to scientific
  3. Change the number of decimal places to "6"
GUID-66D1CCDF-DA10-45B2-B1B1-8A7AB9F58497-low.png Figure 4-2 Format the Trendline Label

Now you can copy the formula and the coefficients from the trendline label and paste it as text in a spreadsheet.

Equation 1. Y = - 1.374327 E + 01 x 4 + 1.393725 E + 02 x 3 - 4.405225 E + 02 x 2 + 7.588066 E + 02 x - 5.512652 E + 02
Equation 2. T ° C = A 4 × ( V 4 ) + A 3 × ( V 3 ) + A 2 × ( V 2 ) + A 1 × ( V ) + A 0

where

  • V = ADC Voltage
  • A4 = –1.374327E+01
  • A3 = 1.393725E+02
  • A2 = –4.405225E+02
  • A1 = 7.588066E+02
  • A0 = –5.512652E+02

Remember that if the formula requires the subtraction of a number, keep the (–) minus symbol with the coefficient. Now the polynomial formula can be created in code with only addition as in the main polynomial in Equation 1. Adding a negative number is the same as subtracting.

Now replace the X4 through X values with the measured ADC voltage in the polynomial formula. Use the coefficients you created in the new formula.