-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference: Sensors
Hannes Suhr edited this page Mar 9, 2026
·
24 revisions
The SensorThreshold library provides data containers with state-dependent threshold rules.
Data container with state channels and condition-dependent thresholds.
s = Sensor('pressure');
s = Sensor('pressure', 'Name', 'Chamber Pressure', 'ID', 101);
s = Sensor('pressure', 'MatFile', 'data.mat', 'KeyName', 'p_chamber');| 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) |
| 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 |
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
% 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();Time-varying discrete state (e.g., machine mode: idle=0, run=1, boost=2).
sc = StateChannel('machine');
sc.X = [0 20 40 60]; % time points
sc.Y = [0 1 2 1]; % state values| Property | Type | Description |
|---|---|---|
| Key | string | Unique state channel identifier |
| X | 1xM double | Time points (monotonically increasing) |
| Y | 1xM double | State values |
Condition-value threshold pair.
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| 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) |
matches = rule.matchesState(stateStruct);Predefined sensor catalog for quick access.
SensorRegistry.list(); % Print all available sensors
s = SensorRegistry.get('pressure'); % Retrieve by key
sensors = SensorRegistry.getMultiple({'pressure', 'temperature'}); % Multiple at onceThe resolve() method uses an efficient segment-based approach:
- Find state-change timestamps from all channels
- Evaluate conditions once per segment (typically 5-50 segments)
- Batch rules sharing the same condition
- 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.
FastSense Wiki
API Reference
Guides
Use Cases
Internals
Resources