In our videos on pressure sensors, we discussed how the non-linear output of a sensor could be characterized as part of the accuracy of a sensor. Now, we will discuss how you linearize a sensor output signal. Linearization can be used in sensors software as an approximation technique for a highly non-linear sensor output. This is commonly done in thermocouples and certain flow sensors. The simplest way to approximate a linear signal is to take the tangent to the non-linear function at a certain point as shown in the left side of this slide. You assume that the curve follows a linear output along the tangent line. For small deviations from the tangent point, you get limited error. For example, the table lookup data for thermocouple voltages requires linear approximation between the single digit degrees Celsius points. The farther you get from the tangent point, the less accurate this method will be. If you want to linearize a large portions of a non-linear curve, try piece-wise linearization as shown on the right side. You take a large series of tangent lines at different points of the non-linear curve and piece them together. The resulting curve is the sum of a large number of straight lines. This method is easy to implement, processing time is fast, and you get accurate results. On the downside, your code size will get large because you have to store a large number of coefficients to perform the calculation. RTDs are characterized by a nearly linear output. For better accuracy, you characterize the RTD output with the third-order equation. Alternately, you can feed the output of the sensor through an analog circuit specifically designed to provide a linear curve that closely matches the actual analog output curve. A resistive network combined with a single op-amp is enough to linearize the output of a two wire RTD. In this circuit, a voltage-controlled current source is formed from the op-amp output through R5 into the RTD. This is a simple resistive network, and the output voltage is directly proportional to the resistance of the RTD and thus to the temperature. The circuit gets more complicated for the three wire and four wire RTDs so another option is to try software compensation for the output. A linearized output signal eliminates the need for a table lookup software commonly used with thermocouples. The end point fit method of linearization is simple, you approximate the nonlinear curve with a straight line fit through the two end points of that curve. The problem with this method is that the error at the midpoint of the line is large. So the statisticians of the world looked around for a mathematical method that could minimize the worst-case error at every point in the curve. Linear Regression otherwise known as the Least Squares method is a statistical means of determining the best fit of a straight line through a series of points. The calculation is a little tedious so be prepared to use a spreadsheet. The formula for calculating the slope of the line is given by N equals summation from i equals one to n of x_i minus x bar times y_i minus y bar divided by the summation of i equals one to n of x_i minus x bar quantity squared, where y equals mx plus b which is the formula for a line, y bar is the average value of y values, x bar is the average value of the x values, y_i equals one y data point, x_i equals one x data point, and n equals the total number of data points. Once you calculate the slope of the line, you calculate the y-intercept b of the line from the formula b equals y bar minus mx bar. With linear regression, the linearity error at the midpoint will generally not be the same as the linearity error at the endpoints. However, the maximum error at any point will be smaller than the midpoint era for the endpoint method. This slide compares the midpoint error using the two methods. The Least Squares fit line passes through different parts of the non-linear curve, but not the endpoints. The deviation at the midpoint using the Least Squares method is shown as half that using the endpoint method, exaggerated visually to make a point. Now, let's illustrate how you would do a Least Squares calculation in Excel to calculate the slope and midpoint errors for the output of a type K thermocouple. This is a plot of type k thermocouple voltage over its full range of temperatures. The curve has its highest non-linearity at the negative Celsius temperatures. We will take a slice of the data specifically between minus 200 C and minus 150 C, linearize it and calculate the error incurred using the two types of linear approximations discussed. There is only enough room on this slide to show you the detailed data points between minus 200 C and minus 180 C. If I showed you the full range of minus 200 C and minus 150 C, the numbers would be so small that you would not be able to read them. We showed the temperature in the leftmost column and the type K thermocouple voltage in the second column from the left. We calculate the numerator of our equation for the slope using the Least Squares method in this third column from the left. We calculate the denominator in the fourth column from the left. The average x value, x bar, is a minus 175 degrees C for the range of minus 200 C to minus 150 degrees C. The average a y value, y bar, is minus 5.436 millivolts for the range of minus 200 degrees C to minus 150 degrees C. The first data point at i equals one is calculated at t equals minus 200 degrees C. We calculate successive higher values of voltage up through i equals 51 at minus 150 degrees C. We sum all values in the third column from the left and divide by the sum of all values in the fourth column from the left. This gives us the slope m equals 0.01960 millivolts per degrees C. We find the y-intercept of the curve b from the formula b equals y bar minus m x bar. Then we calculate the assumed values of thermoelectric voltage at all points between minus 200 degrees C to minus 150 degrees C using our newly created straight line for the Least Squares method. These data points are shown in the second column from the right. None of them are equal to the actual thermocouple voltage. These points are solely a linear approximation of the non-linear thermocouple curve. For the endpoints method, we get the slope from the thermocouple data points at minus 200 degrees C and minus 150 degrees C. The slope is calculated by taking the difference between actual thermocouple voltages at minus 200 degrees C and minus 150 degrees C and dividing by 50 degrees C. We estimate the other points on the line by adding an incremental y value to each point. For example, the thermocouple voltage at minus 200 degrees C is minus 5.891 millivolts. The slope of the line calculated using the endpoints method is minus 01956 millivolts per degrees C. For a change of one degree C, we add 0.01956 millivolts to minus 5.891 millivolts and we get minus 5.871 millivolts at minus 199 degrees C. You use this method 49 more times and we find that the millivoltage calculated at minus 150 degrees C is exactly per the table published on www.nist.gov. These data points are shown in the far right corner. Only the end points are equal to the actual thermocouple voltage. The points in between or another linear approximation of the non-linear thermocouple curve. The difference in the slopes calculated using the Least Squares and endpoints method is tiny. Only 4 times 10 to the negative fifth millivolts per degree C. However these methods also create different y-intercepts. When you combine the differences, you get surprisingly different lines fit through the data points as shown on the next slide. In this graph, the orange colored dots represent the raw thermocouple data points from the www.nist.gov website. The red line is a line drawn between the end points at minus 200 degrees and minus 150 degrees C. It overestimates the voltage at all other points. The blue line is created by the least squares method. By design, it is located above some of the raw data points and below others. The two lines have different slopes and different y-intercepts as shown on the right. The Least Squares line in blue does a better job of approximating the raw data points than the end points line in red. We can quantify by how much at the minus 175 degrees C data point the midpoint of the range from minus 200 degrees C to minus a 150 degrees C. The voltage estimated by the end points line is different from the raw thermocouple voltage by 0.052 millivolts. The voltage estimated by the Least Squares line is different from the raw thermocouple voltage but by only 0.018 millivolts. Let's recap. Now, you have learned how to linearize a non-linear curve, a common technique in sensor circuit design. The next video, we will review how suppliers compensate their sensors for use at extreme ambient temperatures.