Skip to content

API Reference: Sensors

Hannes Suhr edited this page Mar 9, 2026 · 24 revisions

API Reference: Sensors

The SensorThreshold library provides data containers with state-dependent threshold rules.

Sensor

Data container with state channels and condition-dependent thresholds.

Constructor

s = Sensor('pressure');
s = Sensor('pressure', 'Name', 'Chamber Pressure', 'ID', 101);
s = Sensor('pressure', 'MatFile', 'data.mat', 'KeyName', 'p_chamber');

Properties

Property Type Description
Key string Unique identifier
Name string Human-readable display name
ID number Numeric sensor ID
Source string Path to original data file
MatFile string Path to .mat file
KeyName string Field name in .mat file (defaults to Key)
X 1xN double Time stamps (datenum)
Y 1xN double Sensor values
StateChannels cell array StateChannel objects
ThresholdRules cell array ThresholdRule objects
ResolvedThresholds struct array Precomputed threshold lines (after resolve)
ResolvedViolations struct array Precomputed violation points (after resolve)
ResolvedStateBands struct Precomputed state region bands (after resolve)

Methods

Method Description
s.load() Load data from external source
s.addStateChannel(sc) Attach a StateChannel
s.addThresholdRule(condition, value, ...) Add a condition-dependent threshold
s.resolve() Precompute thresholds, violations, and bands
s.getThresholdsAt(t) Evaluate active rules at a specific time

addThresholdRule Parameters

s.addThresholdRule(condition, value, 'Direction', 'upper', 'Label', 'HH');
  • condition — struct with state keys/values (e.g., struct('machine', 1))
  • value — threshold value (scalar)
  • Direction — 'upper' (y > th) or 'lower' (y < th)
  • Label — display label
  • Color — RGB triplet override

Complete Example

% Create sensor with data
s = Sensor('pressure', 'Name', 'Chamber Pressure');
s.X = linspace(0, 100, 1e6);
s.Y = randn(1, 1e6) * 10 + 50;

% Attach state channel (machine mode)
sc = StateChannel('machine');
sc.X = [0 30 60 80];
sc.Y = [0 1 2 1];     % idle=0, run=1, boost=2
s.addStateChannel(sc);

% Condition-dependent thresholds
s.addThresholdRule(struct('machine', 1), 70, 'Direction', 'upper', 'Label', 'Run HI');
s.addThresholdRule(struct('machine', 2), 55, 'Direction', 'upper', 'Label', 'Boost HI');
s.addThresholdRule(struct(), 80, 'Direction', 'upper', 'Label', 'Absolute HI');

% Resolve and plot
s.resolve();
fp = FastPlot('Theme', 'dark');
fp.addSensor(s);
fp.render();

StateChannel

Time-varying discrete state (e.g., machine mode: idle=0, run=1, boost=2).

Constructor

sc = StateChannel('machine');
sc.X = [0 20 40 60];     % time points
sc.Y = [0 1 2 1];        % state values

Properties

Property Type Description
Key string Unique state channel identifier
X 1xM double Time points (monotonically increasing)
Y 1xM double State values

ThresholdRule

Condition-value threshold pair.

Constructor

rule = ThresholdRule(struct('machine', 1), 50);
rule = ThresholdRule(struct('machine', 1, 'phase', 3), 30, 'Direction', 'lower', 'Label', 'Low');
rule = ThresholdRule(struct(), 50);  % empty condition = always active

Properties

Property Type Description
Condition struct State keys/values that activate this rule
Value number Threshold value
Direction string 'upper' or 'lower'
Label string Display label
Color RGB triplet Color override (empty = use theme)

Methods

matches = rule.matchesState(stateStruct);

SensorRegistry

Predefined sensor catalog for quick access.

Static Methods

SensorRegistry.list();                                       % Print all available sensors
s = SensorRegistry.get('pressure');                          % Retrieve by key
sensors = SensorRegistry.getMultiple({'pressure', 'temperature'});  % Multiple at once

Resolution Algorithm

The resolve() method uses an efficient segment-based approach:

  1. Find state-change timestamps from all channels
  2. Evaluate conditions once per segment (typically 5-50 segments)
  3. Batch rules sharing the same condition
  4. SIMD-accelerated violation detection per segment

Complexity: O(S x R) where S = number of state segments and R = number of rules. For 10M data points with 20 segments and 5 rules, this evaluates 100 condition checks instead of 50M per-point evaluations.

Clone this wiki locally