# Linearizing a 0-10V non linear sensor

I'm using this sensor AIR FLOW METER, but I see on page 11 that the 0-10 V output is not linear, how can I linearize that output?

• Software. Or a lookup table, possibly with interpolation. It entirely depends on what you are trying to do and what your ultimate output should be, or could be if you re-consider the entire system. – Chris Stratton Dec 17 '18 at 19:55
• Thanks, i'm just trying to calculate more precisely the air flow speed via software – VirtApp Dec 17 '18 at 20:34
• If you're doing it in software, then make a calibration table. If you were trained as an engineer then somewhere on the back shelves of your brain should be the procedure for doing linear interpolation. So you can make a look up table with as few entries as you can get away with, and use linear interpolation to go from the measured sensor value to the actual air flow value. – TimWescott Dec 17 '18 at 20:45
• Note to OP - The calibration table consists of pairs of numbers of sensor reading paired with actual air flow for that reading. During run time you take a sensor reading and find which pair of table entries the reading is in between. Then linear interpolate between those two points to get a corresponding air flow value. You are basically solving the straight line equation with (x1,y1) and (x2,y2) being the bounding entries in the table with x being the sensor reading and solving for y the corresponding air flow value. – Michael Karas Dec 17 '18 at 21:32
• @MichaelKaras Or the OP can use exponential interpolation between points in the table, as well. It may be more accurate to do so than to use a piece-wise linear approach. Exponential interpolation merely assumes a multiplicative relationship throughout the range. – jonk Dec 17 '18 at 21:47

Let me provide more detailed information regarding piece wise linear interpolation than I was able to supply in comments beforehand.

The calibration table consists of pairs of numbers of sensor reading paired with actual air flow for that reading. During run time you take a sensor reading and find which pair of table entries the reading is in between. Then linear interpolate between those two points to get a corresponding air flow value. You are basically solving the straight line equation with (x1,y1) and (x2,y2) being the bounding entries in the table with x being the sensor reading and solving for y the corresponding air flow value.

Here is a graphic representation: The blue line represents the nonlinear behavior of between an x value and a y value from some real world sensor. Calibrated data points represented by the circles are measured at particular values of X to capture the corresponding real accurate value for Y. If the CAL points lie in the right places along the non-linear curve then straight line segments between them can provide a close approximation of the actual curve. The job of the engineer is to learn enough about her sensor to be able to understand where to make CAL measurements. The more CAL points the closer to the curve you get and the less the error in the interpolated values. Two other jobs for the engineer are to to determine the acceptable level of error and to determine if a fixed table can be used across all products using a particular sensor or if each and every product needs to be calibrated and a separate table of CAL points loaded into each product.

Following from the OP in comments I show how you can extract data points from the typical curve in the sensor data sheet. Do please keep in mind that the accuracy of the data sheet graph, its repeatability from unit to unit, and its variance at temperatures away from 20C is up for debate. So in absence the following example gives some sample points that could be used. In an actual linear interpolation process where some data acquisition system is reading the voltage out of the sensor the V values in the coordinates become the X values as described above. The Y interpolated values would become the values along the bottom of the graph. The interpolation table could look something like this: If you measured a value of voltage say 4.5V then that would fall into the range between the second and third row of the table. Then the following values would be plugged into the above equation to derive the corresponding Y airflow rate. Do note that the above example is not intended to imply the optimum selection of the "sample points". It is up to the user to select the number of points to approximate the curve to the acceptable error band.

• The OP's datasheet has a curve that "looks" exponential in nature. Not s-shaped or otherwise spline-like. The OP admits using software in a comment (not the question, sadly.) So I think should be pretty easy to work out a curve-fit from just three points taken from the desired chart curve in order to solve for $y=A\:e^{k\cdot x}+C$. Using a math model closer to the underlying process can be a good way to go, at times. – jonk Dec 18 '18 at 3:37
• @jonk - Using a curve fit solution may be realistic if there is plenty of processing power available. It is my experience however that for some system designs linear interpolation is a lot more practical, especially on low throughput 8-bit systems, even if one has to calibrate to additional data points. For well behaved sensors where curve shape stays the same but may just see an offset it is often still more efficient to use a fixed lookup table with linear interpolation after adjusting with a single CAL offset value. The key is to study the real world data and understand your device. – Michael Karas Dec 18 '18 at 8:57
• @MichaelKaras, i can't understand how to linearize this sensor, via software, given the voltage readed from the sensor, how i can calculate the respective speed? – VirtApp Feb 24 '19 at 10:53
• @VirtApp - Did you do some calibration? If not that is the first step. This will consist of measuring the Y results for a few X values using separate reference standard equipment. – Michael Karas Feb 24 '19 at 11:28
• @MichaelKaras Unfortunately the sensor it has been installed some years ago and actually i can't do any kind of calibration. I mean, there is some other road to follow? – VirtApp Feb 24 '19 at 12:34

The easiest way (given that there is no equation given) is to extract the data from the published data sheet using software such as Webplotdigitizer then fit a curve to the data. That will get you a matrix of data.

If you have MATLAB there is a curve fit tool that let you try different equations. But for such a crude curve you could also use linear interpolation with many segments or splines. Or just do a lot of points in Webplotdigitizer and interpolate between them. You can even try using the solver in Excel if you must (it's an optional install) to minimize the absolute or least squares error. Scilab and Octave (both free) are MATLAB options but I'm not sure if they have tools that make it as easy as MATLAB.

Note that most likely the linearized value is less and less accurate as you approach a couple m/s, until it's totally meaningless. You may wish to indicate that in some way, depending on what you are doing with the linearized data. There's no point in displaying something to 3 significant digits when it might be off by 2:1.