IntramuscularEMG#

class IntramuscularEMG(
muscle_model: Muscle,
electrode_array: IntramuscularElectrodeArray,
sampling_frequency__Hz: Quantity__Hz = 10240.0 * pq.Hz,
spatial_resolution__mm: Quantity__mm = 0.01 * pq.mm,
endplate_center__percent: float = 50,
nmj_jitter__s: Quantity__s = 35e-6 * pq.s,
branch_cvs__m_per_s: tuple[Quantity__m_per_s, Quantity__m_per_s] = (5.0 * pq.m / pq.s, 2.0 * pq.m / pq.s),
MUs_to_simulate: list[int] | None = None,
)[source]#

Bases: object

Intramuscular Electromyography (iEMG) Simulation.

This class provides a comprehensive simulation framework for generating intramuscular EMG signals detected by needle electrodes.

Parameters:
  • muscle_model (Muscle) – Pre-computed muscle model (see myogen.simulator.Muscle).

  • electrode_array (IntramuscularElectrodeArray) – Intramuscular electrode array configuration to use for simulation (see myogen.simulator.IntramuscularElectrodeArray).

  • sampling_frequency__Hz (Quantity__Hz, default=10240.0 * pq.Hz) – Sampling frequency in Hz for EMG simulation. Default is set to 10240 Hz as used by the Quattrocento (OT Bioelettronica, Turin, Italy) system.

  • spatial_resolution__mm (Quantity__mm, default=0.01 * pq.mm) – Spatial resolution for fiber action potential calculation in mm. Default is set to 0.01 mm.

  • endplate_center__percent (float, default=50) – Percentage of muscle length where the endplate is located. By default, the endplate is located at the center of the muscle (50% of the muscle length).

  • nmj_jitter__s (Quantity__s, default=35e-6 * pq.s) – Standard deviation of neuromuscular junction jitter in seconds. Default is set to 35e-6 s as determined by Konstantin et al. 2020 [1].

  • branch_cvs__m_per_s (tuple[Quantity__m_per_s, Quantity__m_per_s], default=(5.0 * pq.m / pq.s, 2.0 * pq.m / pq.s)) –

    Conduction velocities for the two-layer model of the neuromuscular junction in m/s. Default is set to (5.0, 2.0) m/s as determined by Konstantin et al. 2020 [1].

    Note

    The two-layer model is a simplification of the actual arborization pattern, but it is a good approximation for the purposes of this simulation. Follows the implementation of Konstantin et al. 2020 [1].

  • MUs_to_simulate (list[int], optional) – Indices of motor units to simulate. If None, all motor units are simulated. Default is None. For computational efficiency, consider simulating subsets for initial analysis. Indices correspond to the recruitment order (0 is recruited first).

muaps__Block#

Intramuscular MUAP shapes for the electrode array as a neo.Block. Available after simulate_muaps().

Type:

INTRAMUSCULAR_MUAP__Block

intramuscular_emg__Block#

Intramuscular EMG signals for the electrode array as a neo.Block. Available after simulate_intramuscular_emg().

Type:

INTRAMUSCULAR_EMG__Block

noisy_intramuscular_emg__Block#

Noisy intramuscular EMG signals for the electrode array as a neo.Block. Available after add_noise().

Type:

INTRAMUSCULAR_EMG__Block

spike_train__Block#

Spike train block used for EMG generation. Available after simulate_intramuscular_emg().

Type:

SPIKE_TRAIN__Block

References

Methods

__init__

add_noise

Add noise to the electrode array.

simulate_intramuscular_emg

Generate intramuscular EMG signals using the provided spike train block.

simulate_muaps

Simulate MUAPs for all electrode arrays using the provided muscle model.

Attributes

intramuscular_emg__Block

Intramuscular EMG signals for the electrode array.

muaps__Block

Intramuscular MUAP shapes for the electrode array.

noisy_intramuscular_emg__Block

Noisy intramuscular EMG signals for the electrode array.

spike_train__Block

Spike train block used for EMG generation.

simulate_muaps(
n_jobs: int = -2,
verbose: bool = True,
) INTRAMUSCULAR_EMG__Block[source]#

Simulate MUAPs for all electrode arrays using the provided muscle model.

This method generates intramuscular Motor Unit Action Potential (MUAP) templates by simulating individual motor units with realistic neuromuscular junction distributions and fiber action potential propagation.

Parameters:
  • n_jobs (int, optional) – Number of parallel workers for motor unit processing. Default is -2. - n_jobs=-1: Use all CPU cores - n_jobs=-2: Use all cores except one (recommended, keeps system responsive) - n_jobs=-3: Use all cores except two - n_jobs=1: No parallelization - n_jobs=N: Use exactly N cores

  • verbose (bool, default=True) – If True, display progress bars. Set to False to disable.

Returns:

Intramuscular MUAP shapes for all motor units stored in a neo.Block. Results are stored in the muaps__Block property after execution.

Return type:

INTRAMUSCULAR_MUAP__Block

Notes

This method must be called before simulate_intramuscular_emg(). The process includes: (1) motor unit initialization, (2) neuromuscular junction simulation, and (3) MUAP calculation with spatial filtering.

simulate_intramuscular_emg(
spike_train__Block: SPIKE_TRAIN__Block,
verbose: bool = True,
) INTRAMUSCULAR_EMG__Block[source]#

Generate intramuscular EMG signals using the provided spike train block.

This method convolves the pre-computed MUAP templates with spike trains to synthesize realistic intramuscular EMG signals. The process includes temporal resampling and supports both CPU and GPU acceleration for efficient computation.

Parameters:
  • spike_train__Block (SPIKE_TRAIN__Block) – Block containing spike trains organized as segments (pools) with spiketrains.

  • verbose (bool, default=True) – If True, display progress bars. Set to False to disable.

Returns:

Intramuscular EMG signals for the electrode array stored in a neo.Block. Results are stored in the intramuscular_emg__Block property after execution.

Return type:

INTRAMUSCULAR_EMG__Block

Raises:

ValueError – If MUAP templates have not been generated. Call simulate_muaps() first.

add_noise(
snr__dB: float,
noise_type: str = 'gaussian',
*,
spectral_slope: float = -0.5,
excess_kurtosis: float = 3.0,
powerline_hz: float = 50.0,
powerline_amplitude: float = 0.1,
powerline_harmonic_ratios: list[float] | None = None,
powerline_frequency_drift_hz: float = 0.3,
powerline_amplitude_modulation_depth: float = 0.15,
peak_hz: float = 1000.0,
analog_hpf_hz: float = 10.0,
baseline_drift_rms_uv: float = 0.0,
baseline_drift_alpha: float = 1.75,
baseline_drift_low_hz: float | None = None,
baseline_drift_high_hz: float = 1.0,
) INTRAMUSCULAR_EMG__Block[source]#

Add noise to the electrode array.

Two noise models are available:

  • "gaussian" – white Gaussian noise (legacy default). Each electrode channel gets independent normal noise scaled to hit the requested per-channel SNR.

  • "realistic" – spectrally colored noise calibrated against real bipolar fine-wire iEMG recordings (TEP / Synergy studies). 1/f-like base, mid-band spectral emphasis from electrode–amplifier bandwidth, heavy tails from cross-talk artifacts, and additive 50/60 Hz powerline interference with harmonics. See myogen.utils.emg_noise for the math.

Per-channel SNR is preserved across both modes: each electrode’s noise RMS is computed from that channel’s own signal RMS so electrodes with different amplitudes get appropriately scaled noise.

Parameters:
  • snr__dB (float) – Signal-to-noise ratio in dB. Higher values result in cleaner signals. Typical intramuscular EMG has SNR ranging from 15–50 dB. Applied independently to each electrode channel.

  • noise_type ({"gaussian", "realistic"}, default="gaussian") – Noise model to use. "realistic" activates the colored noise pipeline; the remaining keyword-only parameters then apply.

  • spectral_slope (float, default=-0.5) – PSD slope in log–log space for the colored-noise base. 0 = white, -1 = pink. Real iEMG: -0.4 to -0.8. Ignored when noise_type="gaussian".

  • excess_kurtosis (float, default=3.0) – Target excess kurtosis (0 = Gaussian). Controlled isometric iEMG: 1–6. Dynamic tasks: higher. Ignored when noise_type="gaussian".

  • powerline_hz (float, default=50.0) – Powerline interference frequency. Use 60.0 for North America, 0.0 to disable. Ignored when noise_type="gaussian".

  • powerline_amplitude (float, default=0.1) – Powerline fundamental amplitude as a fraction of noise RMS. Set to 0 (or powerline_hz=0) to disable. Ignored when noise_type="gaussian".

  • powerline_harmonic_ratios (list of float, optional) – Per-harmonic amplitude ratios relative to the fundamental. None uses the default [1.0, 0.5, 0.3, 0.15, 0.08] (fundamental + 4 harmonics). Ignored when noise_type="gaussian".

  • powerline_frequency_drift_hz (float, default=0.3) – Standard deviation (Hz) of the slow random walk of the mains instantaneous frequency. Broadens each line peak from a delta into a ~2-5 Hz FWHM bump (typical of real recordings). Set to 0 for a pure-tone powerline. Ignored when noise_type="gaussian".

  • powerline_amplitude_modulation_depth (float, default=0.15) – Fractional AM depth (±15% by default) applied to each powerline harmonic — adds narrow sidebands within ±2 Hz of every line. Set to 0 to disable. Ignored when noise_type="gaussian".

  • peak_hz (float, default=1000.0) – Center frequency of the mid-band spectral emphasis from electrode–amplifier bandwidth interaction. Ignored when noise_type="gaussian".

  • baseline_drift_rms_uv (float, default=0.0) – Target RMS (post-HPF) of a band-limited 1/f^α baseline drift representing electrode/interface noise (Huigen 2002, Gondran 1996). Same units as the EMG block. Set to 0 (the default) to disable, preserving legacy behaviour. The spectral form is paper-constrained; the amplitude defaults are not validated for intramuscular EMG — calibrate against real recordings via myogen.utils.calibrate_baseline_drift_profile(). Broadband movement artifacts (0–20 Hz, De Luca 2010) are a separate phenomenon out of scope here. Ignored when noise_type="gaussian".

  • baseline_drift_alpha (float, default=1.75) – Drift PSD slope α (PSD ∝ 1/f^α). Midpoint of the [1.5, 2.0] electrode-noise regime. Must be > 0. Ignored when noise_type="gaussian".

  • baseline_drift_low_hz (float or None, default=None) – Lower edge of the drift band, in Hz. None resolves to the lowest nonzero FFT bin available for the simulation length. Ignored when noise_type="gaussian".

  • baseline_drift_high_hz (float, default=1.0) – Upper edge of the drift band, in Hz. Default keeps the knob scoped to sub-1 Hz baseline wander. Ignored when noise_type="gaussian".

  • analog_hpf_hz (float)

Returns:

Noisy intramuscular EMG signals for the electrode array as a neo.Block. Results are also stored on noisy_intramuscular_emg__Block.

Return type:

INTRAMUSCULAR_EMG__Block

Raises:

ValueError – If intramuscular EMG has not been simulated (call simulate_intramuscular_emg() first) or noise_type is unrecognized.

property muaps__Block: segments))]]#

Intramuscular MUAP shapes for the electrode array.

Returns:

Intramuscular MUAP templates for the electrode array as a neo.Block.

Return type:

INTRAMUSCULAR_MUAP__Block

Raises:

ValueError – If MUAP templates have not been computed yet.

property intramuscular_emg__Block: segments))]]#

Intramuscular EMG signals for the electrode array.

Returns:

Intramuscular EMG signals for the electrode array as a neo.Block.

Return type:

INTRAMUSCULAR_EMG__Block

Raises:

ValueError – If intramuscular EMG has not been computed yet.

property noisy_intramuscular_emg__Block: segments))]]#

Noisy intramuscular EMG signals for the electrode array.

Returns:

Noisy intramuscular EMG signals for the electrode array as a neo.Block.

Return type:

INTRAMUSCULAR_EMG__Block

Raises:

ValueError – If noisy intramuscular EMG has not been computed yet.

property spike_train__Block: segments))]]#

Spike train block used for EMG generation.

Returns:

The spike train block used in the simulation.

Return type:

SPIKE_TRAIN__Block

Raises:

ValueError – If spike train block has not been set yet.