I mean, a sensor can have a characteristics like Y=X^2 (X = the input, Y=the output). That is, I can easily find X if I know Y. Why is the linearity so important?
-
1Because when it is not linear, its sensitivity and resolution varies with input variable – venny Sep 12 '14 at 08:46
-
1It was much more important when everything was analog. These days, when you can do math on your data, or interpolate to a look up table, linear sensors are a nifty convenience, not quite a necessity – Scott Seidman Sep 12 '14 at 10:45
-
If you have to do the calculation in your microcontroller you might take less clock cycle when linear. – Amit Hasan Sep 12 '14 at 15:55
4 Answers
A lot of stuff still uses relatively low-powered or cheap microcontrollers, 8-bit micros haven't gone away.
The upshot is that:
- Maths is expensive (in CPU cycles)
- Floating-point and/or signed maths is even more expensive
- Doing maths introduces errors / adds to error bounds
- Type conversion can introduce coding errors
- Having to handle more bits than your CPU is natively capable of gets very expensive in maths terms.
- Having to do any of this means having to include maths libraries (more code, more space, more RAM, more storage)
If you look at the hoops a CPU has to jump through (in machine instructions executed to achieve one mathematical operation) to do signed floating-point maths, and the resulting output precision, you might decide that just using a linear sensor is a more attractive prospect.

- 7,041
- 2
- 21
- 34
-
Most of this type of math can actually be INTEGER math. Indeed, the numbers coming in through the ADC are integers to start. There are, of course, quantifiable errors when you do this, but not as big as many think they are if done correctly. Yes, there are many parameters we can optimize around. Sensor linearity is one, clock ticks is another, and memory one more. Every problem will point to different principle concerns when the numbers are crunched. – Scott Seidman Sep 12 '14 at 14:08
-
Scott - true, but the moment you do much more than add, subtract, or bit-shift in a basic micro you are into "hard maths". I found an integer MOD operation was taking about 20+ instructions to complete, replacing with a check-and-subtract loop actually made the code run a lot faster. – John U Sep 12 '14 at 15:35
Yes, you could have a sensor that responds like that (Y=X^2) Your sensor must still reliably do that. In a typical sensor, Y=cX+d where c and d are ideally constants. Due to various factors, they usually aren't simple constants. How close c and d are to really being constants is what is referred to as linearity. In your example, you would probably have something like Y=(cX+d)^2 , which would cause all kinds of fun.
Linearity as in "linear response" isn't the problem. Linearity as in "the Y values closely fit the expected linear response" is what you want. In your example, you wouldn't be concerned with whether the a plot of Y and X is a straight line. You would want your plot to closely match the expected parabolic curve. It most likely won't perfectly match. For a sensor with a linear response, you would say that the linearity is poor. For one like your proposed sensor (Y=X^2) I don't know what you'd call it - maybe just "poor response."
Poor linearity in a typical sensor means that you have to do more work to get X if you know Y. With an ideal sensor with a linear response, you can calculate X eaisly if you know Y. With real sensor with good linearity, you can (with in reasonable limits) determine X from Y. With a real sensor with poor linearity, you have to go to greater lengths to determine X when you know Y. Maybe its response varies greatly with temperature, so you have to track temperatur as well and use it when determining X from Y. Maybe it just isn't very linear, and you have to use some funky curve to relate X and Y. In either case, your job as an engineer is much easier if the sensor closely approximates the expected straight line. Often times this works out to making a system simpler to calibrate and more reliable - but also more expensive since a better sensor usually means more expensive. Sometimes you'll want to go with a cheaper and less linear sensor, and compensate for its failings in software.

- 67,678
- 8
- 104
- 179
-
"Poor linearity in a typical sensor means that you can't tell exactly what X is if you know Y" is simply not true. So long as Y is an increasing or decreasing function of X (i.e., a horizontal line on a Y vs X graph can cross only one point on the function_, there is a one to one mapping. – Scott Seidman Sep 12 '14 at 13:15
-
You are correct if the response of the sensor is known (you have a mapping for all points.) Since the inputs are analog, however, you don't have a perfect one to one mapping. Also, some of the effects (temperature especially) can cause one input value to report different output values. Also, some parts of the curve may be so steep that you can't really resolve the input - you get the same output for a range of inputs. – JRE Sep 12 '14 at 13:20
-
You're nitpicking. A strain gage is not a linear sensor, and people use single arm strain gages every day. Same for a thermistor, and many other sensors. You can list the trouble spots to watch out for, but in many cases, they simply don't apply. I don't understand your point about analog inputs at all. Your post is largely correct, but with a clear error that is easy to fix – Scott Seidman Sep 12 '14 at 13:21
-
I think I see what you are getting at. Maybe I've phrased it poorly. What I mean is that without some kind of compensation (remapping) you can't tell exactly what X is from Y - you can't just apply some linear function to Y and get back to X. Later in the same paragraph it goes on to explain that you can compensate, but that poor linearity makes it more difficult. – JRE Sep 12 '14 at 13:33
-
You're getting there. Poor linearity "can" make compensation difficult in some extreme cases, but those cases don't come up as often as your answer seems to imply, especially if there's a microcontroller in the loop. When issues do come up, its usually because you're too resource starved to do the necessary calculations (often starved for clock ticks), not because the sensor is too nonlinear to handle with simple math. – Scott Seidman Sep 12 '14 at 13:44
Many monitoring circuits for sensors are purely analogue and therefore the complication of mapping a value measured via a square root law is really not trivial. If the measurement is digitized then using math inside the CPU is fairly trivial in comparison but, like I said, many circuits are purely analogue.

- 434,556
- 28
- 351
- 777
-
I really can't think of a modern sensor chip that does not include an ADC and a digital interface... – Vladimir Cravero Sep 12 '14 at 09:15
-
1@vladimir who mentioned "chip"? There are plenty of sensors that do not and should not use a chip such as straingauges, thermocouples RTDs, accelerometers, microphones etc.. – Andy aka Sep 12 '14 at 10:03
Linearity minimises the influence of imperfections later in the circuit. For instance, say there is a small constant level of noise introduced by a preamplifier. If you need to correct for the response of that Y2 sensor of yours, the effective noise level (SNR) is proportional to the inverse function's derivative, i.e.
∂X/∂Y = d/d X √Y = 1/2 √Y ∝ 1/X.
At low levels of X, this effective noise tends to infinity (equivalently, the SNR approaches zero). In reality, it's not quite as dramatic since the pertubations aren't infinitesimal, but the problem is real: where the output voltage is only weakly correlated to the measured value, the maximum attainable accuracy suffers.
You might now think to filter the noise somehow, but there comes another problem: frequency filtering is basically linear, and to work well it assumes the signal itself has come linear – to use the physics terminology, you'd like filtering to commute with measuring. That's not given with a nonlinear sensor, for instance if you have a high-frequency signal in your X quantity around some X0, and filter the resulting Y signal, you'll get a constant offset above the corresponding Y0 value, because the square-nonlinearity "bends the pertubation upwards".
Now if you say then let's first digitally correct the nonlinearity. Next problem: you can only take discrete samples. PCM-sampling is very well under control mathematically, but guess what: it assumes everything is linear! Nonlinearities cause aliasing artifacts.
To wrap up: yes, you can somehow correct it if sensors aren't linear. But each such correction brings new problems with it; if everything is linear in then first place you can be most confident to actually get the signal you want.

- 1,394
- 10
- 14
-
1On a related note, many kinds of unwanted parasitic effects can be modeled as either linear filters; or as time-independent non-linearities (harmonic distortion). Any combination of linear filters may be modeled as a single linear filter, parameterized with a single function that maps a real to a real, and any combination of chained sources of harmonic distortion can be modeled as a single source, also mapping a real to a real. Combining the two kinds of effects, however, yields something that is *much* harder to model. – supercat Sep 12 '14 at 17:44