LabKit MATLAB Workbench

reference

API ReferenceBiosignal API

labkit.biosignal.cropSignal

Return a signal clipped to a time range in seconds.

Syntax

cropped = labkit.biosignal.cropSignal(signal, timeRangeSec) cropped = labkit.biosignal.cropSignal(signal)

Description

Keeps samples whose timestamps lie between the requested start and end times, including both endpoints. For a nonempty result, time is shifted so that the first retained sample occurs at zero. The sample rate is recalculated from the median positive time step when at least two usable timestamps remain; otherwise the input sample rate is preserved.

Omitting timeRangeSec or passing [] returns signal unchanged. A valid range that contains no samples returns empty time and values vectors.

Inputs

signal
Biosignal structure with time, values, fs, and metadata fields. time and values must describe corresponding samples.
timeRangeSec
Two-element numeric vector [startSec endSec], expressed on signal.time, with startSec less than endSec. The value may be omitted or empty to skip cropping.

Outputs

cropped
Copy of signal containing only the selected samples. The original range is recorded in metadata.cropTimeRangeSec.

Errors

labkit:biosignal:InvalidSignal
signal does not contain time, values, and fs fields.
labkit:biosignal:InvalidTimeRange
timeRangeSec is not an increasing two-element vector.

Example

signal = struct('time', (0:0.5:3)', 'values', (10:16)', ...
'fs', 2, 'metadata', struct());
cropped = labkit.biosignal.cropSignal(signal, [0.75 2.25]);

Source

This page is generated from the MATLAB help text in +labkit/+biosignal/cropSignal.m.