Moving Event Counter#

You can count the occurrences of a sample value over a number of signal samples by calling the method moving_events().

A new Trace instance labeled with the performed transformation 'events' is returned.

>>> # counts the ones in the moving window samples
>>> Trace('Signal', [0, 1, 0, 1, 0, 0, 0, 1, 1, 1]).moving_events(size=3)
Trace(label='Signal:events', samples=[0, 1, 1, 2, 1, 1, 0, 1, 2, 3])
>>> # counts the zeros in the moving window samples
>>> Trace('Signal', [0, 1, 0, 1, 0, 0, 0, 1, 1, 1]).moving_events(3, value=0)
Trace(label='Signal:events', samples=[1, 1, 2, 1, 2, 2, 3, 2, 1, 0])

Note

The moving event counter uses None as the preset value to generate the windows for the first number of signal samples.

(Source code, html)