A sensor can keep producing values while no longer describing the process accurately.
That is a harder problem than a sensor that has failed completely. A disconnected transmitter may trigger a clear diagnostic. A drifting, noisy or frozen signal can remain inside the range that the control system expects, while quietly making alarms, trends and operator decisions less reliable.
For control and automation engineers, the challenge is not just detecting bad values. It is deciding what “bad” means for each signal, preserving the evidence behind that decision, and making sure the application responds deliberately.
This article outlines a practical approach to monitoring sensor data quality alongside the measurement itself.
A plausible value is not necessarily a valid value
Imagine a temperature input that normally changes gradually. If it stays at exactly the same value for hours while the process is changing, the number may be plausible but the signal may be frozen.
Other problems have different signatures:
- Out-of-range values: The reading exceeds the configured measurement range.
- Stale values: The input has not updated within the expected interval.
- Excessive noise: The signal varies far more than its normal operating pattern.
- Unexpected rate of change: The value moves faster than the process or instrument should allow.
- Bad channel status: The input module or communication layer marks the measurement as unreliable.
These conditions should not all be collapsed into a single “sensor bad” flag. Each has a different cause and may require a different response.
Keep the measurement and its quality separate
A useful software representation keeps the value, timestamp and quality status together:
from dataclasses import dataclass from enum import Enum, auto class Quality(Enum): GOOD = auto() STALE = auto() OUT_OF_RANGE = auto() FROZEN = auto() BAD_CHANNEL = auto() @dataclass(frozen=True) class Reading: value: float | None timestamp_s: float quality: Quality This makes an important distinction explicit: the system may have received a value, but that does not mean it should treat the value as trustworthy.
In a PLC or industrial monitoring application, the exact representation will depend on the platform and project standards. The general principle applies across implementations: preserve quality information instead of replacing it with a default number.
Add simple, explainable checks first
A basic range check can catch readings outside configured limits:
def check_range(value: float, low: float, high: float) -> Quality: if not low <= value <= high: return Quality.OUT_OF_RANGE return Quality.GOOD A stale-data check uses the time since the last update:
def check_freshness(now_s: float, last_update_s: float, max_age_s: float) -> Quality: if now_s - last_update_s > max_age_s: return Quality.STALE return Quality.GOOD These examples use configurable limits; they are not universal thresholds. The acceptable range and update interval need to come from the instrument, process and application requirements.
Simple checks are valuable because they are deterministic and easy to review. More advanced techniques can be added later, but the first goal is to make basic failure modes visible.
Detect a frozen signal carefully
A constant value can indicate a failed input, but it can also be legitimate. A tank level may remain steady when there is no flow. A temperature controller may hold a process near its setpoint.
So a frozen-signal detector should not alert merely because consecutive readings match. It should consider context, duration and the signal’s expected behaviour.
One simple detector tracks how long a value has remained unchanged:
def is_unchanged(previous: float, current: float, tolerance: float = 0.001) -> bool: return abs(current - previous) <= tolerance The detector can count consecutive unchanged samples and raise a quality flag only after a configured duration. In a real system, the tolerance should account for signal resolution and normal measurement noise.
If process conditions explain the steady reading, the detector may need a condition such as “only evaluate while the equipment is running” or “only evaluate when another related signal is changing.” That context should be explicit, documented and tested rather than hidden in a magic threshold.
Preserve raw and processed values
Filtering can make noisy measurements easier to use, but it can also conceal a developing fault. Keep the original reading available alongside any filtered value:
raw value -> what the input reported filtered value -> value used for a defined application purpose quality status -> whether the reading passed validation Avoid overwriting the raw measurement with a smoothed result. If an engineer later investigates a deviation, the original signal helps distinguish an instrumentation issue from a processing artefact.
Filtering also introduces delay. The choice of filter and its parameters should be considered against the process dynamics and the consequences of responding late.
Define what downstream logic should do
Finding a quality issue is only half the design. The application also needs an explicit policy for what happens next.
Depending on the application, a bad or stale reading might:
- Raise an operator-visible diagnostic.
- Suppress a calculation that requires valid data.
- Mark a trend or report as incomplete.
- Move a sequence into a defined fault or hold state.
- Use a documented fallback, if one is appropriate.
There is no universally safe response. Treating every bad value as zero, retaining the last value indefinitely, or silently continuing with stale data can all create misleading behaviour. The response must be chosen for the specific process and reviewed by the relevant engineering team.
Test failure cases as well as normal readings
Unit tests can verify that quality checks behave as intended:
def test_stale_reading_is_flagged(): result = check_freshness( now_s=120.0, last_update_s=100.0, max_age_s=10.0, ) assert result is Quality.STALE def test_recent_reading_is_accepted(): result = check_freshness( now_s=105.0, last_update_s=100.0, max_age_s=10.0, ) assert result is Quality.GOOD Tests should include boundary values, missing updates, invalid ranges and transitions between good and bad quality. For a frozen-signal detector, test both a genuinely static process and a simulated stuck input. The point is to check that the rule does not confuse normal process behaviour with instrumentation failure.
These tests verify software behaviour only. They do not replace hardware testing, loop checks, risk assessment or commissioning.
Make quality visible in logs and trends
If a reading is flagged, record enough context to investigate it later:
- Signal or channel identifier
- Timestamp and measured value
- Quality status and reason
- Relevant operating mode
- Whether downstream logic used, ignored or substituted the value
A trend that shows only the processed measurement can hide the reason for a decision. Showing quality transitions alongside the signal makes the system easier to troubleshoot and helps engineers tune checks based on evidence rather than guesswork.
Conclusion
Sensor validation is not just about checking whether a value falls between two limits. It is about deciding whether the value is current, plausible and suitable for the purpose that will use it.
Keep quality separate from value. Start with simple, explainable checks. Preserve raw measurements. Define downstream behaviour deliberately, and test the conditions that can make a plausible signal misleading.
That gives operators and engineers more than a number on a screen: it gives them context they can use to decide how much confidence to place in it.