← Linear Regression

Real Data: Sensor Temperature Drift

40 measurements from an ultrasonic snow-depth sensor — all taken under dry conditions, so true depth = 0 cm throughout. The variation you see is caused entirely by temperature.

The setup
A sensor that should read zero
An ultrasonic sensor measures the distance to the ground to calculate snow depth. On days with no snow it should always read 0 cm — but it doesn't. Something is making the readings wander by as much as ±9 cm.
The clue
Temperature changes too
The sensor is mounted outdoors and its electronics warm up in sunlight. The temperature of the sensor chip itself swings from −6 °C to +34 °C across the dataset — a range of 40 °C. Could this be causing the drift?
The finding
A near-perfect linear relationship
Plotting depth against temperature reveals a strikingly straight line with R² = 0.959. Temperature explains 96% of the apparent depth variation. This is temperature drift — a well-known phenomenon in electronic sensors.
Measurements
40
True snow depth
0 cm (all dry)
Sensor temp range
−5.8 °C to +34.0 °C
Measured depth range
−9.0 cm to +4.2 cm
Regression R²
0.959
Graph 1 — Measured depth vs. event
True depth is 0 cm throughout. Why does the sensor show values from −9 to +4 cm?
Graph 2 — Sensor temperature vs. event
The sensor chip temperature swings widely — driven by sunlight, shade, and ambient air.
Graph 3 — Both signals overlaid
Notice how the two series move in opposite directions — when temperature rises, measured depth falls.
Graph 4 — Depth vs. temperature
Each point is one measurement. Toggle the regression line to reveal the linear relationship.
depth = −0.3494 · temp + 3.4292    R² = 0.959
Things to think about

Discussion questions

For every 1 °C rise in sensor temperature, the measured depth reading drops by 0.35 cm. The negative sign makes sense: warmer electronics tend to cause the sensor to report shorter distances (higher apparent depth turns negative here), a known thermal expansion effect in ultrasonic sensors.
Possibilities include: humidity affecting the speed of sound in air, slight wind disturbing the sensor beam, random electronic noise, or small changes in the actual ground surface. No model captures everything — the question is whether the unexplained part is small enough to ignore.
You could apply a temperature correction: measure the sensor temperature alongside each depth reading and subtract (−0.35 × temp + 3.43) from the raw reading. This is called compensation — using one variable to correct for a known bias in another. It's a real technique used in sensor engineering.