TestBench.tools

2-Point Calibration Calculator

Derive slope and offset from two measured reference points.

Reference points

Slope (gain)
12.5
Offset
-50
Equation
y = 12.5000·x − 50.0000
y at x = 12
100
x at y = 12
4.96

This tool fits the straight line through two reference measurements and hands you the two constants every linear calibration needs: slope (gain) and offset (zero). Enter the raw reading and the true value at two points, and the equation — plus a live apply/invert field — updates instantly.

How it works

A linear channel obeys y = slope·x + offset. Two known points (x₁, y₁) and (x₂, y₂) determine it exactly: slope = (y₂ − y₁)/(x₂ − x₁), then offset = y₁ − slope·x₁. This is the math behind every zero-and-span procedure: the “zero” adjustment moves the offset, the “span” adjustment moves the slope. The same two constants invert cleanly (x = (y − offset)/slope), which is what you need when driving an output to hit a target value.

Accuracy hinges on the reference points: read them with a better instrument than the channel you are calibrating, and spread them wide — slope uncertainty grows as the points move closer together.

Worked example

point 1: x=4 (mA) → y=0 (°C) · point 2: x=20 → y=200
slope = (200−0)/(20−4) = 12.5 · offset = 0 − 12.5·4 = −50
y = 12.5·x − 50 → at x=12: y = 100

Parameters

ParameterValueNotes
Modely = slope·x + offsetlinear only
Slope(y₂−y₁)/(x₂−x₁)gain / span
Offsety₁ − slope·x₁zero
Inversex = (y−offset)/slope
Constraintx₁ ≠ x₂

C implementation

C
/* Two-point calibration: y = slope*x + offset */
typedef struct { float slope, offset; } cal2_t;

cal2_t cal2_fit(float x1, float y1, float x2, float y2)
{
    cal2_t c;
    c.slope  = (y2 - y1) / (x2 - x1);
    c.offset = y1 - c.slope * x1;
    return c;              /* (4,0)-(20,200): slope 12.5, offset -50 */
}

float cal2_apply(cal2_t c, float x) { return c.slope * x + c.offset; }

FAQ

When is a two-point calibration enough?

Whenever the sensor or channel is linear over your working range — which covers most industrial transducers, amplified bridges and analog input chains. Two points pin down a straight line exactly; a third point is only needed to check linearity or when the device is known to curve.

Which two points should I use?

As far apart as practical, ideally near the ends of the range you care about. Slope error scales with 1/(x₂−x₁), so points close together amplify any reading noise into a large gain error.

What do slope and offset mean physically?

Slope is the gain — output units per input unit (12.5 °C/mA in the worked example). Offset is the reading the line predicts at input zero; a nonzero offset is what people informally call the 'zero error'.

How do I use the result in my PLC or firmware?

Store the two constants and compute y = slope·x + offset per sample (one multiply, one add). The reverse direction x = (y − offset)/slope converts a desired output back to the raw input — the tool computes both live.

Is my data uploaded?

No. The fit runs locally in your browser.

Related tools