Skip to content

API Reference: Event Detection

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

API Reference: Event Detection

The EventDetection library groups threshold violations into discrete events with statistics and provides a viewer UI.

EventDetector

Core detector that groups consecutive threshold violations into events.

Constructor

det = EventDetector();
det = EventDetector('MinDuration', 0.5, 'MaxCallsPerEvent', 3);

Properties

Property Type Default Description
MinDuration number 0 Debounce: events shorter than this (seconds) are discarded
OnEventStart function handle [] Callback invoked as f(event) when event starts
MaxCallsPerEvent number 1 Max callback invocations per event

Methods

events = det.detect(t, values, thresholdValue, direction, label, sensorName);

Returns an array of Event objects.


Event

Value class holding event metadata and statistics.

Properties (all read-only)

Property Type Description
StartTime number First violation timestamp
EndTime number Last violation timestamp
Duration number EndTime - StartTime
SensorName string Sensor/channel name
ThresholdLabel string e.g., "warning high"
ThresholdValue number Threshold that was violated
Direction string "high" or "low"
PeakValue number Worst violation (furthest from threshold)
NumPoints number Data points in event window
MinValue number Minimum value over event window
MaxValue number Maximum value over event window
MeanValue number Mean value over event window
RmsValue number RMS value over event window
StdValue number Standard deviation over event window

EventConfig

Configuration container for the event detection system.

Properties

Property Type Description
Sensors cell array Sensor objects to analyze
SensorData struct array Fields: name, t, y (for click-to-plot)
MinDuration number Debounce filter
MaxCallsPerEvent number Callback limit
OnEventStart function handle Callback
ThresholdColors containers.Map Maps threshold labels to RGB colors
AutoOpenViewer logical Auto-open EventViewer after detection

Methods

Method Description
det = cfg.buildDetector() Create configured EventDetector
events = cfg.runDetection() Detect across all sensors
cfg.addSensor(sensor, t, y) Register sensor with data
cfg.setColor(label, [r g b]) Set color for threshold label

EventViewer

Figure UI with Gantt-style timeline and event table with click-to-plot.

Constructor

viewer = EventViewer(events);
viewer = EventViewer(events, sensorData);
viewer = EventViewer(events, sensorData, thresholdColors);

Methods

viewer.update(newEvents);  % Refresh with new events (live mode)

UI Features

  • Top panel: Gantt-style timeline — one row per sensor, colored bars per event
  • Bottom panel: Table with columns: Start, End, Duration, Sensor, Threshold, Direction, Peak, NumPts, Min, Max, Mean, RMS, Std
  • Dropdown filters: Filter by sensor name or threshold label
  • Click-to-plot: Click a table row to open a FastPlot zoomed to that event's time range

Convenience Functions

detectEventsFromSensor

events = detectEventsFromSensor(sensor);
events = detectEventsFromSensor(sensor, detector);

Bridges the SensorThreshold and EventDetection libraries. Resolves thresholds, detects violations, returns Event array.

printEventSummary

printEventSummary(events);

Prints a formatted event table to the console.

eventLogger

det = EventDetector('OnEventStart', eventLogger());

Returns a callback function for live console logging of events as they are detected.


Complete Example

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

sc = StateChannel('machine');
sc.X = [0 30 60 80];
sc.Y = [0 1 2 1];
s.addStateChannel(sc);

s.addThresholdRule(struct('machine', 1), 70, 'Direction', 'upper', 'Label', 'Run HI');
s.resolve();

% Detect events
det = EventDetector('MinDuration', 0.5);
events = detectEventsFromSensor(s, det);

% Console output
printEventSummary(events);

% Open viewer with click-to-plot
sensorData = struct('name', 'pressure', 't', s.X, 'y', s.Y);
viewer = EventViewer(events, sensorData);

Clone this wiki locally