# Linear Interpolation Between Sensor Table Points

Learn how to estimate intermediate sensor readings with two-point linear interpolation, read a sensor lookup table, and apply the formula step by step.

Linear interpolation estimates a sensor reading that falls between two points you already have in a table. You take the two known points that sit on either side of the value you want, then draw a straight line between them to find the answer. This turns a sparse sensor lookup table into a usable conversion for any input inside its range. 

- Find the two table points that bracket the input value before doing any math.
- The linear interpolation formula scales the gap between the two values by how far the input sits across the interval.
- Interpolation only estimates values inside the table range; outside it you are extrapolating.
- A linear method assumes the sensor response between two points is close to a straight line.
- Keep the units of the table columns consistent or the result will be wrong.
 

## What linear interpolation does for sensor tables 

A sensor lookup table lists raw sensor output next to the reading it represents. The table is finite, so many real inputs land between two listed rows. Linear interpolation fills that gap by treating the segment between two points as a straight line. 

The method is a form of estimating intermediate sensor readings from data you already trust. It requires no curve fitting and no model of the sensor itself. Two bracketing points and simple arithmetic give a usable conversion value. 

The result is an estimate, not a measurement. Accuracy depends on how closely the real sensor response matches a straight line across that segment. A table with closely spaced points keeps the estimate closer to the true value. 

## Placing the input in the table 

The first step in interpolating between table values is finding the two rows that surround your input. One point must sit below the input and one above it. Those become the lower and upper anchors for the calculation. 

Sort the table by the independent column, the side you use as the input. Scanning for the bracket is then a simple comparison. If the input matches a table entry exactly, no interpolation is needed and you read the result directly. 

An input outside the full table range cannot be interpolated. Extending the line beyond the last two points is extrapolation, which carries more risk of error. Many conversion routines flag those inputs instead of guessing. 

## The two-point interpolation formula 

The linear interpolation formula weights the two anchor results by distance. Subtract the lower input from your actual input, then divide by the gap between the two input values. That fraction tells you how far across the segment you sit. 

Apply the same fraction to the difference between the two results. Add the scaled difference to the lower result to get your estimate. The formula is symmetric, so either anchor works as long as you keep the pairing consistent. 

Worked symbolically, the result equals y1 plus the fraction times y2 minus y1, where y1 and y2 are the lower and upper table outputs. Every term carries the unit of its column, so the fraction stays dimensionless. Mixing units inside one column breaks the calculation. 

## A step-by-step example 

A worked example makes the two-point interpolation method concrete. Suppose a table pairs raw counts with a temperature reading and your raw input falls between two rows. The bracket is chosen first, then the fraction, then the final value. 

Take a lower point of raw value 100 mapping to 20 degrees and an upper point of raw value 200 mapping to 30 degrees. An input of 150 sits halfway across the segment. Half of the 10-degree span gives 25 degrees as the estimate. 

An input of 120 gives a smaller fraction, one fifth across the gap. The estimated reading becomes 22 degrees. The pattern holds for any input inside the interval, and the arithmetic stays the same. 

## Choosing the lookup table spacing 

The spacing of a sensor lookup table sets how well linear interpolation tracks the real response. Dense points reduce the error because each segment covers a smaller stretch of the curve. Sparse points leave longer straight-line approximations. 

Spacing should be tighter where the sensor curve bends or changes slope quickly. Sections where the response is nearly straight need fewer rows. The table can be uneven on purpose to match the sensor behavior. 

Table precision also depends on how the original values were measured. Interpolating between noisy points propagates that noise into the estimate. Cleaning the source data before building the table improves the result more than adding rows. 

## Where linear interpolation falls short 

A linear method treats the interval as a straight line, which the sensor may not follow. Curved or steeply changing responses produce larger errors between points. The estimate can drift from the true reading without any obvious warning. 

Sharp breaks or discontinuities in the sensor response cannot be captured by two-point interpolation at all. Points placed on either side of a break give a misleading straight line across it. Tables must keep those regions well sampled or use another method. 

Some sensors need piecewise curves, polynomial fits or calibration equations for accurate conversion. Choosing the method depends on the accuracy your application needs and how the sensor behaves. Interpolation is a practical first tool, not a universal answer. 

## Keeping the estimate reliable 

Reliable interpolation starts with a table whose units and rounding are consistent from row to row. Record the raw sensor values and the reference measurements together at the same conditions. Sign and offset errors in the source data carry straight into every estimate. 

Check the result against a few known inputs to confirm the bracket logic and the formula agree. A conversion routine that returns values outside the range of its two anchors has a fault. Range checks catch this before the estimate is used. 

Document the table version and the method beside the conversion. Anyone reading a sensor value later needs to know how the number was produced. A clear record makes the estimate defensible and repeatable. 

## Questions about sensor table interpolation 

### How do I use linear interpolation with a sensor table? 

Find the two table rows that bracket your input, then apply the two-point formula to scale between their results. Linear interpolation with a sensor table works only when the input lies inside the table range. The output is an estimate based on a straight line between the two points. 

### What is the linear interpolation formula for two points? 

The formula is y1 plus the fraction times y2 minus y1, where the fraction is your input minus x1 divided by x2 minus x1. The two-point interpolation formula weights each table result by distance along the input axis. Keep x1, x2, y1 and y2 in matching units. 

### Can I interpolate between table values outside the table range? 

No, interpolating between table values outside the listed range is not interpolation at all. Extending the line past the last two points is extrapolation, which carries a higher risk of error. Most conversion routines flag an out-of-range input rather than estimating it. 

### How accurate is estimating intermediate sensor readings this way? 

Accuracy depends on how straight the sensor response is between the two anchor points and how closely the table rows are spaced. Estimating intermediate sensor readings with a straight line can drift from the true value where the curve bends. Tighter spacing in those regions reduces the error. 

### What should a sensor lookup table include? 

A sensor lookup table should include the raw sensor output and the reference reading it represents, with consistent units in each column. The table should be sorted by the input column so bracketing is straightforward. Recording the calibration conditions helps others trust the values.
