ezmsg.simbiophys.line_noise#

Additive mains (line) noise with slow frequency drift.

Adds a sinusoidal 50/60 Hz interference component to every channel of a signal, emulating power-line pickup on a recording. The peak frequency wanders slowly (a bounded random walk) to mimic drift of the recording device’s clock relative to the mains. When freq is None the stage is a pass-through.

The drifting sinusoid is generated by phase accumulation (see ezmsg.simbiophys.oscillator.advance_drifting_sine()) so it stays continuous across chunks and as the frequency changes.

Classes

class LineNoiseSettings(freq=None, amp=1.0, drift_rate=0.002, drift_bound=1.5, seed=None)[source]#

Bases: Settings

Parameters:
freq: float | None = None#

Mains frequency in Hz (typically 50.0 or 60.0). None disables the stage (pass-through).

amp: float = 1.0#

Amplitude of the added sinusoid (same units as the input signal), shared across all channels.

drift_rate: float = 0.002#

Frequency drift rate in Hz per second (RMS wander over 1 s), emulating recording-clock drift. Set to 0 for a perfectly fixed frequency.

drift_bound: float = 1.5#

The line frequency is clamped to freq +/- drift_bound Hz.

seed: int | None = None#

Random seed for the frequency-drift walk. If None, uses system entropy.

__init__(freq=None, amp=1.0, drift_rate=0.002, drift_bound=1.5, seed=None)#
Parameters:
Return type:

None

class LineNoiseState[source]#

Bases: object

ang_freq: ndarray[tuple[Any, ...], dtype[float64]] | None = None#

Base angular frequency 2*pi*freq, shape (1, 1).

amp: ndarray[tuple[Any, ...], dtype[float64]] | None = None#

Amplitude, shape (1, 1).

phase: ndarray[tuple[Any, ...], dtype[float64]] | None = None#

Accumulated phase carried across chunks, shape (1, 1).

freq_off: ndarray[tuple[Any, ...], dtype[float64]] | None = None#

Current frequency offset (Hz) carried across chunks, shape (1, 1).

step_std: float = 0.0#

Per-sample random-walk std for the drift.

rng: Generator | None = None#

Random number generator for the drift walk.

dt: float = 0.0#

Sample period (seconds).

class LineNoiseTransformer(*args, **kwargs)[source]#

Bases: BaseStatefulTransformer[LineNoiseSettings, AxisArray, AxisArray, LineNoiseState]

Add a slowly frequency-drifting mains sinusoid to every channel.

The same single-frequency component is added to all channels (mains pickup is a common source). Timing (sample rate) is taken from the input; the number of channels may vary. When freq is None the input passes through unchanged.

class LineNoiseUnit(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[LineNoiseSettings, AxisArray, AxisArray, LineNoiseTransformer]

Unit wrapper for LineNoiseTransformer.

Parameters:

settings (Settings | None)

SETTINGS#

alias of LineNoiseSettings