biosppy.synthesizers.emg

biosppy.synthesizers.emg

This module provides methods to synthesize Electromyographic (EMG) signals. :copyright: (c) 2015-2026 by Instituto de Telecomunicacoes :license: BSD 3-clause, see LICENSE for more details.

Functions

synth_gaussian([duration, sampling_rate, ...])

Generates an artificial (synthetic) EMG signal of a given duration and sampling rate.

synth_uniform([duration, length, ...])

Generates an artificial (synthetic) EMG signal of a given duration and sampling rate, with muscle activity bursts modeled as an uniform distribution and background noise modeled as a zero-mean Gaussian process with adjustable standard deviation.

biosppy.synthesizers.emg.synth_gaussian(duration=10, sampling_rate=1000, length=None, SNR=30, sigma=0.1, alpha=2.5, baseline=None, burst_number=1, burst_location=None, random_state=None)[source]

Generates an artificial (synthetic) EMG signal of a given duration and sampling rate.

Follows the approach by by Ghislieri, Cerone, Knaflitz and Agostini [ModelEMG2], where muscle activity bursts are modeled as a zero-mean Gaussian process with standard deviation equal to 10**(SNR/20) mV, and the background noise is modeled as a zero-mean Gaussian process with standard deviation equal to 1 mV. All muscle activity bursts have the same duration, which is equal to 2*sigma*alpha (in seconds).

If the parameters introduced lead to superimposed burst locations, an error will be raised, and if they lead to consecutive bursts, a warning will raise. Warnings will also be raised, if the precision derived from the selected sampling rate is not compatible with each burst’s location or duration, or the duration of quiet periods.

Parameters:
  • duration (int, optional) – Desired recording length in seconds.

  • sampling_rate (int, optional) – The desired sampling rate (in Hz, i.e., samples/second).

  • length (int, optional, optional) – The desired length of the signal (in samples).

  • SNR (float, optional) – Desired signal-to-noise ratio of the signal (in dB).

  • sigma (float, optional) – Standard deviation of the truncated Gaussian process with zero mean used to simulate muscle activity.

  • alpha (float, optional) – Multiplier that multiplied with the ‘sigma’ value defines the time support of the truncated Gaussian process, which will be the duration of the bursts (burst_duration = 2*sigma*alpha, with default values, this duration is 0.5s).

  • baseline (float, optional) – Signal offset from zero. If no value is given, it is assumed that the baseline has already been removed.

  • burst_number (int, optional) – Desired number of bursts of activity (active muscle periods).

  • burst_location (list, optional) – Location of the bursts (in seconds).

  • random_state (None, int, numpy.random.RandomState or numpy.random.Generator) – Seed for the random number generator.

Returns:

  • emg (array) – Vector containing the EMG signal.

  • t (array) – Time values accoring to the provided sampling rate.

  • params (dict) – Input parameters of the function, clean EMG and noise signals, and SNR

Examples

sampling_rate = 1000
duration = 10
SNR = 30
sigma = 0.2
alpha = 1.25
bursts = 4
burst_location = [2,4,6,8]
output = synth_gaussian(duration=duration, sampling_rate=sampling_rate, SNR=SNR,
                                sigma=sigma, alpha=alpha, burst_number=bursts, burst_location=burst_location,
                                random_state=0)
emg_synth, t, params = output["emg"], output["t"], output["params"]

# Get muscle activity state
activity = params["activity"]

plt.figure()
plt.plot(t,emg_synth,label="EMG")
plt.plot(t,activity,label="Muscle activity")
plt.xlabel("Time (s)")
plt.ylabel("Amplitude (mV)")
plt.grid()
plt.title("EMG")
plt.legend()

plt.show()

References

[ModelEMG2]

Marco GHISLIERI, Giacinto Luigi CERONE, Marco KNAFLITZ & Valentina AGOSTINI “LONG SHORT-TERM MEMORY (LSTM) RECURRENT NEURAL NETWORK FOR MUSCLE ACTIVITY DETECTION” Journal of NeuroEngineering and Rehabilitation, Vol. 18, No. 1, 2021, 3–4

biosppy.synthesizers.emg.synth_uniform(duration=10, length=None, sampling_rate=1000, noise=0.01, baseline=None, burst_number=1, burst_duration=1.0, burst_location=None, amplitude_mult=None, random_state=None)[source]

Generates an artificial (synthetic) EMG signal of a given duration and sampling rate, with muscle activity bursts modeled as an uniform distribution and background noise modeled as a zero-mean Gaussian process with adjustable standard deviation.

Follows the approach by Diong, Joanna [ModelEMG1], but, additionally, this function also allows to manually choose the muscle activity burst locations, and add amplitude multipliers for each burst.

If the parameters introduced lead to superimposed burst locations, an error will be raised, and if they lead to consecutive bursts, a warning will be raised. Warnings will also be raised, if the precision derived from the selected sampling rate is not compatible with each burst’s location or duration, or the duration of quiet periods.

Parameters:
  • duration (int, optional) – Desired recording length in seconds.

  • sampling_rate (int, optional) – The desired sampling rate (in Hz, i.e., samples/second).

  • length (int, optional) – The desired length of the signal (in samples).

  • noise (float, optional) – Noise level (standard deviation of the gaussian distribution from which values are sampled).

  • baseline (float, optional) – Signal offset from zero. If no value is given, it is assumed that the baseline has already been removed.

  • burst_number (int, optional) – Desired number of bursts of activity (active muscle periods).

  • burst_duration (float or list, optional) – Duration of the bursts. Can be a float (each burst will have the same duration) or a list of durations for each burst.

  • burst_location (list, optional) – Location of the bursts (in seconds).

  • amplitude_mult (float or list, optional) – Amplitude multiplier for the bursts. Can be a float (each burst will have the same amplitude range) or a list of multipliers for each bursts.

  • random_state (None, int, numpy.random.RandomState or numpy.random.Generator, optional) – Seed for the random number generator.

Returns:

  • emg (array) – Vector containing the EMG signal.

  • t (array) – Time values accoring to the provided sampling rate.

  • params (dict) – Input parameters of the function, clean EMG and noise signals, and SNR

Examples

sampling_rate = 1000
duration = 10
noise_amplitude = 0.05
bursts = 7
burst_duration = [0.5,1,0.5,0.6,1,0.5,0.5]
burst_location = [0.1,2.5,4,5.5,7,8.5,9.4]
amplitude_mult = [1,1,0.5,1.5,1,0.75,1]
emg_synth, t, params = synth_uniform(duration=duration, sampling_rate=sampling_rate, noise=noise_amplitude,
                                    burst_number=bursts, burst_duration=burst_duration, burst_location=burst_location,
                                    amplitude_mult=amplitude_mult)

# Get muscle activity state
activity = params["activity"]

plt.plot(t,emg_synth,label="EMG")
plt.plot(t,activity,label="Muscle activity")
plt.xlabel("Time (s)")
plt.ylabel("Amplitude (mV)")
plt.grid()
plt.title("EMG")
plt.legend()

plt.show()

References

[ModelEMG1]

Joanna DIONG, “PYTHON: ANALYSING EMG SIGNALS”, https://scientificallysound.org/2016/08/11/python-analysing-emg-signals-part-1/