ezmsg.sigproc.util.startup#

Data-primed filter start-up: build the filter state from the first samples of a stream.

Module Attributes

SETTLE_TOL

Fraction of a pole's initial contribution left when its settling length has passed.

Functions

hold_for_startup(held, message, axis, n)[source]#

Collect messages until they hold n samples on axis.

Appends message to held. Returns None while fewer than n samples are held; then empties held and returns everything as one message carrying the first held message’s axes and the latest message’s attrs, segment and config_id.

Parameters:
Return type:

AxisArray | None

prime_with_reflection(run, message, axis, n_pad)[source]#

Prime a stateful processor from the start of message and discard what it emits.

Builds up to n_pad samples of synthetic pre-history by odd reflection of the first samples about the first one, 2 * x[0] - x[n_pad:0:-1] (the padding scipy.signal.filtfilt() uses), stamps them with the times just before message and passes them to run, whose output is dropped. n_pad is cut to what message holds (one fewer than its length); with nothing to reflect, run is not called.

Parameters:
  • run (Callable[[AxisArray], Any]) – The processor, or any callable that advances its state on an AxisArray.

  • message (AxisArray) – The first real message. It needs a LinearAxis on axis.

  • axis (str) – The stream dimension.

  • n_pad (int) – Pad length in samples.

Return type:

None

release_held(held, axis)[source]#

Empty a non-empty held and return its messages as one, as hold_for_startup() releases them.

A processor’s flush calls this to emit a start-up buffer that never filled.

Parameters:
Return type:

AxisArray

settle_samples(poles, order, tol=0.001)[source]#

Samples until a filter’s state is (nearly) independent of its initial conditions.

order for a filter with all poles at the origin (an FIR: its state is exactly the last order inputs), otherwise ceil(log(tol) / log(max|pole|)), the length over which the slowest pole decays to tol. inf for a pole on or outside the unit circle.

Parameters:
Return type:

float

startup_n_pad(n, message, axis, max_dur)[source]#

Cap a pad length n (samples) at max_dur seconds of message’s stream (None: no cap).

Parameters:
Return type:

int

Classes

class StartupMode(*values)[source]#

Bases: OptionsEnum

What a filter assumes about the signal before the first sample it sees.

ZERO = 'Zero pre-history'#
CONSTANT = "Constant pre-history at the first sample's value"#
FIRST_CHUNK = 'Prime the state from a reflection of the first message'#
BUFFERED = 'Hold output until enough samples arrive to prime the state, then release them'#