SurfaceEMG#

class SurfaceEMG(
muscle_model,
electrode_arrays,
sampling_frequency__Hz=2048.0,
sampling_points_in_t_and_z_domains=256,
sampling_points_in_theta_domain=180,
MUs_to_simulate=None,
)[source]#

Bases: object

Surface Electromyography (sEMG) Simulation.

This class provides a simulation framework for generating surface electromyography signals from the muscle. It implements the multi-layered cylindrical volume conductor model from Farina et al. 2004 [1].

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

  • electrode_arrays (list[SurfaceElectrodeArray]) – List of electrode arrays to use for simulation (see myogen.simulator.SurfaceElectrodeArray).

  • sampling_frequency__Hz (float, default 2048.0) – Sampling frequency in Hz. Default is set to 2048 Hz as used by the Quattrocento (OT Bioelettronica, Turin, Italy) system.

  • sampling_points_in_t_and_z_domains (int, default 256) – Spatial and temporal discretization resolution for numerical integration. Controls the accuracy of the volume conductor calculations but significantly impacts computational cost (scales quadratically). Higher values provide better numerical accuracy at the expense of simulation time. Default is set to 256 samples.

  • sampling_points_in_theta_domain (int, default 180) – Angular discretization for cylindrical coordinate system in degrees. Higher values provide better spatial resolution for circumferential electrode placement studies. Default is set to 180 points, which provides 2° angular resolution. This is suitable for most EMG studies.

  • 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#

Motor Unit Action Potential (MUAP) templates for each electrode array. Available after simulate_muaps().

Type:

list[SURFACE_MUAP_SHAPE__TENSOR]

surface_emg__tensors#

Surface EMG signals for each electrode array. Available after simulate_surface_emg().

Type:

list[SURFACE_EMG__TENSOR]

noisy_surface_emg__tensors#

Noisy surface EMG signals for each electrode array. Available after add_noise().

Type:

list[SURFACE_EMG__TENSOR]

motor_neuron_pool#

Motor neuron pool used for EMG generation. Available after simulate_surface_emg().

Type:

MotorNeuronPool

References

Methods

__init__

add_noise

Add noise to all electrode arrays.

simulate_muaps

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

simulate_surface_emg

Generate surface EMG signals for all electrode arrays using the provided motor neuron pool.

Attributes

motor_neuron_pool

Motor neuron pool used for EMG generation.

muaps

Motor Unit Action Potential (MUAP) templates for each electrode array.

noisy_surface_emg__tensors

Noisy surface EMG signals for each electrode array.

surface_emg__tensors

Surface EMG signals for each electrode array.

simulate_muaps()[source]#

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

This method generates Motor Unit Action Potential (MUAP) templates that represent the electrical signature of each motor unit as recorded by the surface electrodes. The simulation uses the multi-layered cylindrical volume conductor model.

Returns:

List of generated MUAP templates for each electrode array. Results are stored in the muaps property after execution.

Return type:

list[SURFACE_MUAP_SHAPE__TENSOR]

Notes

This method must be called before simulate_surface_emg(). The generated MUAP templates are used as basis functions for EMG signal synthesis.

simulate_surface_emg(motor_neuron_pool)[source]#

Generate surface EMG signals for all electrode arrays using the provided motor neuron pool.

This method convolves the pre-computed MUAP templates with the motor neuron spike trains to synthesize realistic surface EMG signals. The process includes temporal resampling to match the motor neuron pool timestep and supports both CPU and GPU acceleration.

Parameters:

motor_neuron_pool (MotorNeuronPool) – Motor neuron pool with spike trains computed (see myogen.simulator.MotorNeuronPool).

Returns:

Surface EMG signals for each electrode array. Results are stored in the surface_emg__tensors property after execution.

Return type:

list[SURFACE_EMG__TENSOR]

Raises:

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

add_noise(snr_db, noise_type='gaussian')[source]#

Add noise to all electrode arrays.

This method adds realistic noise to the simulated surface EMG signals based on a specified signal-to-noise ratio. The noise characteristics can be customized to match different recording conditions.

Parameters:
  • snr_db (float) – Signal-to-noise ratio in dB. Higher values result in cleaner signals. Typical physiological EMG has SNR ranging from 10-40 dB.

  • noise_type (str, default "gaussian") – Type of noise to add. Currently supports “gaussian” for white noise.

Returns:

Noisy EMG signals for each electrode array. Results are stored in the noisy_surface_emg__tensors property after execution.

Return type:

list[SURFACE_EMG__TENSOR]

Raises:

ValueError – If surface EMG has not been simulated. Call simulate_surface_emg() first.

property muaps: list[~typing.Annotated[~numpy.ndarray[tuple[int, ...], ~numpy.dtype[~numpy.floating]], beartype.vale.Is[lambda x: x.ndim == 4]]]#

Motor Unit Action Potential (MUAP) templates for each electrode array.

Returns:

List of MUAP templates for each electrode array.

Return type:

list[SURFACE_MUAP_SHAPE__TENSOR]

Raises:

ValueError – If MUAP templates have not been computed yet.

property surface_emg__tensors: list[~typing.Annotated[~numpy.ndarray[tuple[int, ...], ~numpy.dtype[~numpy.floating]], beartype.vale.Is[lambda x: x.ndim == 4]]]#

Surface EMG signals for each electrode array.

Returns:

Surface EMG signals for each electrode array.

Return type:

list[SURFACE_EMG__TENSOR]

Raises:

ValueError – If surface EMG has not been computed yet.

property noisy_surface_emg__tensors: list[~typing.Annotated[~numpy.ndarray[tuple[int, ...], ~numpy.dtype[~numpy.floating]], beartype.vale.Is[lambda x: x.ndim == 4]]]#

Noisy surface EMG signals for each electrode array.

Returns:

Noisy surface EMG signals for each electrode array.

Return type:

list[SURFACE_EMG__TENSOR]

Raises:

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

property motor_neuron_pool: MotorNeuronPool#

Motor neuron pool used for EMG generation.

Returns:

The motor neuron pool used in the simulation.

Return type:

MotorNeuronPool

Raises:

ValueError – If motor neuron pool has not been set yet.