Siemens Slope and Intercept Calculator Guide
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This calculator works out the slope and intercept of a best-fit straight line through your data points using the least-squares method. You enter paired x and y values, and it returns the slope (m), the y-intercept (b), and the correlation coefficient (r) so you can judge how well the line fits. It is the same calculation a Siemens PLC or HMI does internally when you use its “slope and intercept” scaling block for analog signals.
Formula
The least-squares slope and intercept are computed from these formulas:
- Slope (m) = [n·Σ(x·y) − Σx·Σy] / [n·Σ(x²) − (Σx)²]
- Intercept (b) = (Σy − m·Σx) / n
- Correlation (r) = [n·Σ(x·y) − Σx·Σy] / √{[n·Σ(x²) − (Σx)²]·[n·Σ(y²) − (Σy)²]}
Where n is the number of data pairs, Σx is the sum of all x values, Σy is the sum of all y values, Σ(x·y) is the sum of each x multiplied by its paired y, Σ(x²) is the sum of each x squared, and Σ(y²) is the sum of each y squared. All sums are taken over the same n data points.
Worked Example
Using the default values from the calculator above, the data points are (1,2), (2,4), (3,5), (4,4), and (5,5).
- Count: n = 5
- Σx = 1+2+3+4+5 = 15
- Σy = 2+4+5+4+5 = 20
- Σ(x·y) = (1×2)+(2×4)+(3×5)+(4×4)+(5×5) = 2+8+15+16+25 = 66
- Σ(x²) = 1+4+9+16+25 = 55
- Σ(y²) = 4+16+25+16+25 = 86
- Slope = [5×66 − 15×20] / [5×55 − 15²] = (330 − 300) / (275 − 225) = 30 / 50 = 0.6
- Intercept = (20 − 0.6×15) / 5 = (20 − 9) / 5 = 11 / 5 = 2.2
- Correlation = (330 − 300) / √[(50)×(5×86 − 400)] = 30 / √[50×(430−400)] = 30 / √(50×30) = 30 / √1500 ≈ 30 / 38.7298 ≈ 0.7746
The calculator shows slope = 0.6, intercept = 2.2, and r ≈ 0.7746. That matches the manual calculation.
Why Siemens Uses Slope and Intercept
Siemens PLCs (S7-1200, S7-1500, S7-300/400) and HMIs often receive analog signals like 4–20 mA or 0–10 V from sensors. The raw value inside the PLC is a 16-bit integer, typically 0 to 27648 (or −32768 to 32767 in some modules). To convert that raw integer to a meaningful engineering unit—temperature in °C, pressure in bar, flow in m³/h—you need a linear scaling formula:
Engineering Value = Raw Value × Slope + Intercept
The slope is the “gain” and the intercept is the “offset.” Siemens provides standard function blocks like SCALE (in older libraries) or the NORM_X and SCALE_X instructions (in TIA Portal) that do this internally. When you set the low and high limits of the raw range and the low and high limits of the engineering range, the PLC computes the slope and intercept for you. But if you need to verify those settings, or if you are using a custom formula in a function block, you can calculate the slope and intercept yourself from two known points.
How to Choose the Right Method
There are two common ways to get slope and intercept for Siemens scaling:
- Two-point method – If you know exactly two calibration points (e.g., 4 mA = 0 °C and 20 mA = 100 °C), you can compute slope = (y2 − y1) / (x2 − x1) and intercept = y1 − slope × x1. This is exact for a linear sensor and is what the PLC does internally.
- Least-squares regression – If you have many data points from a calibration table (e.g., a thermocouple curve), the least-squares line gives the best straight-line approximation across all points. This is what this calculator does.
For most Siemens scaling, the two-point method is sufficient because the raw-to-engineering conversion is assumed linear. Use the regression calculator when you want to fit a line to noisy measurement data or when the sensor’s response is not perfectly linear and you want the best average line.
Common Mistakes and Misconceptions
A frequent error is mixing up the x and y axes. In Siemens scaling, the raw value is always the x (input) and the engineering value is the y (output). If you swap them, you get the inverse slope and a different intercept, which will cause incorrect readings.
Another mistake is using the raw range 0–27648 but forgetting that some analog modules use bipolar ranges (−27648 to +27648). Check your module’s manual. Also, when using the two-point method, make sure both points are in the same units. If one point is in mA and the other in %, convert them first.
A common misconception is that the intercept is the value at x = 0. That is true mathematically, but in practice the raw value 0 may not be meaningful (e.g., 4 mA is the live zero). The intercept is just the y-value where the line crosses the y-axis; it is not necessarily a physical reading.
Reading the Results
The slope tells you how many engineering units change per one raw unit. For example, if slope = 0.01, then every raw count changes the engineering value by 0.01 units. The intercept is the engineering value when the raw value is zero. The correlation coefficient r ranges from −1 to +1. An r close to 1 means a strong positive linear relationship; close to −1 means a strong negative linear relationship; near 0 means no linear relationship. For a two-point fit, r will always be exactly 1 or −1 because two points always define a perfect line. For regression with more points, r indicates how well the line fits.
Limitations of the Formula
The least-squares method assumes the relationship is linear and that the x values are known without error. It also gives equal weight to all points, so outliers can skew the line. If your sensor has a nonlinear response, a straight line may not be accurate enough; you may need a polynomial or a lookup table. Also, the regression line is only valid within the range of the data you used. Extrapolating far beyond that range can produce meaningless values.
Frequently Asked Questions
What is the difference between slope/intercept and NORM_X/SCALE_X in TIA Portal?
NORM_X scales the raw value to a normalized 0.0–1.0 real number, and SCALE_X scales that normalized value to your engineering range. Together they perform the same linear conversion as slope and intercept. The slope is (engineering_high − engineering_low) / (raw_high − raw_low), and the intercept is engineering_low − slope × raw_low.
Can I use this calculator for 4–20 mA scaling?
Yes. Enter the raw values (e.g., 0 and 27648) as x and the engineering values (e.g., 0 and 100) as y. The calculator will give you the slope and intercept. Then the engineering value = raw × slope + intercept.
What if my data points are not in order?
Order does not matter for the least-squares calculation. Each x must be paired with its corresponding y, but the pairs can be listed in any sequence.
Why is my r value not exactly 1?
If you have more than two points and they do not all lie exactly on a straight line, r will be less than 1. That is normal. It means the line is an approximation, not a perfect fit.
What units should I use for x and y?
Any units work as long as you are consistent. The slope will have units of y per x. For Siemens scaling, x is usually the raw integer (no unit) and y is the engineering unit (e.g., °C, bar, psi).