Decimator

class gpype.backend.timing.decimator.Decimator[source]

Bases: IONode

Decimator node for downsampling data streams.

Reduces data rate by outputting only every Nth sample based on decimation factor. Adjusts sampling rate and frame size in output context accordingly.

Everything above the new Nyquist frequency is removed first. Dropping samples without that step folds the discarded band back into the retained one, where it is indistinguishable from real signal: at 250 Hz decimated by 50, everything from 2.5 Hz to 125 Hz lands on top of the band of interest. The filter runs on the measured-signal channels only, so an in-band master index or a trigger channel survives intact.

The first sample kept is input sample decimation_factor - 1, and start_time is moved to it. A marker in the input context moves to the first kept sample at or after it. A gap covers every kept sample whose window holds a missing input sample. Without the anti-alias filter the window is the kept sample itself. With it, the window is the input samples that carry 99 % of the kept sample’s filter weight, 53 at a factor of 5.

CUTOFF_RATIO = 0.8

Cutoff as a fraction of the output Nyquist frequency. Below one so that the transition band fits below Nyquist rather than straddling it, which is where aliasing would reappear.

FILTER_ORDER = 8

Order of the anti-alias low-pass.

RESPONSE_PERIODS = 64

Output periods of impulse response measured for a gap’s window. The 99 % point sits at 10.2 to 13 of them for factors 2 to 1000, and 512 gives the same windows.

class Configuration[source]

Bases: Configuration

class Keys[source]

Bases: Keys

class OptionalKeys[source]

Bases: OptionalKeys

Optional configuration keys.

ANTI_ALIAS = 'anti_alias'

Whether to low-pass before dropping samples.

__init__(decimation_factor=1, anti_alias=True, **kwargs)[source]

Initialize decimator with decimation factor.

Parameters:
  • decimation_factor (int) – Factor by which to reduce data rate. Must be positive integer. Value of 1 means no decimation.

  • anti_alias (bool) – Remove everything above the new Nyquist frequency before dropping samples. Only turn this off if the input is already band-limited below the output Nyquist frequency.

  • **kwargs – Additional arguments for parent IONode.

setup(data, port_context_in)[source]

Setup output context with adjusted sampling rate and frame size.

Parameters:
  • data (dict[str, ndarray]) – Input data arrays.

  • port_context_in (dict[str, dict]) – Input port contexts containing frame size and sampling rate information.

Return type:

dict[str, dict]

Returns:

Output port contexts with decimated sampling rate.

Raises:

ValueError – If frame_size is not provided, or is not exactly 1.

step(data)[source]

Process one step of decimation.

The anti-alias filter runs on every incoming frame, not only on the frames that are emitted: a streaming filter carries state, and skipping the discarded samples would leave that state describing a signal that was never presented.

Parameters:

data (dict) – Input data dictionary containing data to be decimated.

Returns:

Dictionary with last sample of input data if decimation step, None otherwise.