Electromyography analysis module¶

electromyography.
analyzeEMG
(rawEMGSignal, samplerate, preprocessing=True, lowpass=50, highpass=20, threshold=0.01, nseg=3, phasic_seconds=4)[source]¶ This functions acts as entrypoint for the EMG Analysis.
 Input:
 rawEMGSignal = raw signal as list
 samplerate = samplerate of the signal
 lowpass = lowpass cutoff in Hz
 highpass = highpass cutoff in Hz
 threshold for the evaluation of ZC,MYOP,WAMP,SSC
 nseg = number of segments for MAVSLPk, MHW,MTW
 Output:
 results dictionary

electromyography.
butter_highpass
(cutoff, fs, order=5)[source]¶ This functions generates a higpass butter filter
Parameters:  cutoff (float) – cutoff frequency
 cutoff – cutoff frequency
 fs (float) – samplerate of the signal
 order (int) – order of the Butter Filter
Returns: butter highpass filter
Return type: list

electromyography.
butter_highpass_filter
(data, cutoff, fs, order)[source]¶ This functions apply a butter highpass filter to a signal
Parameters:  data (list) – ECG signal
 cutoff (float) – cutoff frequency
 cutoff – cutoff frequency
 fs (float) – samplerate of the signal
 order (int) – order of the Butter Filter
Returns: highpass filtered ECG signal
Return type: list

electromyography.
butter_lowpass
(cutoff, fs, order=5)[source]¶ This functions generates a lowpass butter filter
Parameters:  cutoff (float) – cutoff frequency
 cutoff – cutoff frequency
 fs (float) – samplerate of the signal
 order (int) – order of the Butter Filter
Returns: butter lowpass filter
Return type: list

electromyography.
butter_lowpass_filter
(data, cutoff, fs, order)[source]¶ This functions apply a butter lowpass filter to a signal
Parameters:  data (list) – ECG signal
 cutoff (float) – cutoff frequency
 cutoff – cutoff frequency
 fs (float) – samplerate of the signal
 order (int) – order of the Butter Filter
Returns: lowpass filtered ECG signal
Return type: list

electromyography.
getAAC
(rawEMGSignal)[source]¶ Get the Average amplitude change.:
AAC = 1/N * sum(x(i+1)  xi) for i = 1 > N1
 Input:
 raw EMG Signal as list
 Output:
 Average amplitude change of the signal
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: Average Amplitude Change of the signal Return type: float

electromyography.
getAFB
(rawEMGSignal, samplerate, windowSize=32)[source]¶ Get the amplitude at first Burst.
Reference: Du, S., & Vuskovic, M. (2004, November). Temporal vs. spectral approach to feature extraction from prehensile EMG signals. In Information Reuse and Integration, 2004. IRI 2004. Proceedings of the 2004 IEEE International Conference on (pp. 344350). IEEE.
 Input:
 rawEMGSignal as list
 samplerate of the signal in Hz (sample / s)
 windowSize = window size in ms
 Output:
 amplitude at first burst
Parameters:  rawEMGSignal (list) – the raw EMG signal
 samplerate (int) – samplerate of the signal int Hz
 windowSize – window size in ms to use for the analysis
Returns: Amplitute ad first Burst
Return type: float

electromyography.
getDASDV
(rawEMGSignal)[source]¶ Get the standard deviation value of the the wavelength.:
DASDV = sqrt( (1 / (N1)) * sum((x[i+1]  x[i])**2 ) for i = 1 > N  1
 Input:
 raw EMG Signal
 Output:
 DASDV
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: standard deviation value of the the wavelength Return type: float

electromyography.
getFR
(rawEMGPowerSpectrum, frequencies, llc=30, ulc=250, lhc=250, uhc=500)[source]¶ This functions evaluate the frequency ratio of the power spectrum.
Cutoff value can be decidec experimentally or from the MNF Feature See: Oskoei, M.A., Hu, H. (2006). GAbased feature subset selection for myoelectric classification.
 Input:
 raw EMG power spectrum as list,
 frequencies as list,
 llc = lower low cutoff
 ulc = upper low cutoff
 lhc = lower high cutoff
 uhc = upper high cutoff
 Output:
 Frequency Ratio
Parameters:  rawEMGPowerSpectrum (list) – power spectrum of the EMG signal
 frequencies (list) – frequencies of the PSD
 llc (float) – lower cutoff frequency for the low frequency components
 ulc (float) – upper cutoff frequency for the low frequency components
 lhc (float) – lower cutoff frequency for the high frequency components
 uhc (float) – upper cutoff frequency for the high frequency components
Returns: frequencies ratio of the EMG power spectrum
Return type: float

electromyography.
getHIST
(rawEMGSignal, nseg=9, threshold=50)[source]¶ Histograms is an extension version of ZC and WAMP features.
 Input:
 raw EMG Signal as list
 nseg = number of segment to analyze
 threshold = threshold to use to avoid DC fluctuations
 Output:
 get zc/wamp for each segment
Parameters:  rawEMGSignal (list) – the raw EMG signal
 nseg (int) – number of segments to analyze
 threshold (int) – value to sum / substract to the zero when evaluating the crossing.
Returns: Willison amplitude
Return type: float

electromyography.
getIEMG
(rawEMGSignal)[source]¶ This function compute the sum of absolute values of EMG signal Amplitude.:
IEMG = sum(xi) for i = 1 > N
 Input:
 raw EMG Signal as list
 Output:
 integrated EMG
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: the IEMG of the EMG Signal Return type: float

electromyography.
getLOG
(rawEMGSignal)[source]¶ LOG is a feature that provides an estimate of the muscle contraction force.:
LOG = e^((1/N) * sum(xi)) for x i = 1 > N
 Input:
 raw EMG Signal
 Output = * LOG
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: LOG feature of the EMG Signal Return type: float

electromyography.
getMAV
(rawEMGSignal)[source]¶ Thif functions compute the average of EMG signal Amplitude.:
MAV = 1/N * sum(xi) for i = 1 > N
 Input:
 raw EMG Signal as list
 Output:
 Mean Absolute Value
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: the MAV of the EMG Signal Return type: float

electromyography.
getMAV1
(rawEMGSignal)[source]¶ This functoin evaluate Average of EMG signal Amplitude, using the modified version n°.1.:
IEMG = 1/N * sum(wixi) for i = 1 > N wi = { 1 if 0.25N <= i <= 0.75N, 0.5 otherwise }
 Input:
 raw EMG Signal as list
 Output:
 Mean Absolute Value
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: the MAV (modified version n. 1) of the EMG Signal Return type: float

electromyography.
getMAV2
(rawEMGSignal)[source]¶ This functoin evaluate Average of EMG signal Amplitude, using the modified version n°.2.:
IEMG = 1/N * sum(wixi) for i = 1 > N wi = { 1 if 0.25N <= i <= 0.75N, 4i/N if i < 0.25N 4(iN)/N otherwise }
 Input:
 raw EMG Signal as list
 Output:
 Mean Absolute Value
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: the MAV (modified version n. 2) of the EMG Signal Return type: float

electromyography.
getMAVSLPk
(rawEMGSignal, nseg)[source]¶ Mean Absolute value slope is a modified versions of MAV feature.
The MAVs of adiacent segments are determinated.
MAVSLPk = MAV[k+1]  MAV[k]; k = 1,..,k+1
 Input:
 raw EMG signal as list
 nseg = number of segments to evaluate
 Output:
 list of MAVs
Parameters:  rawEMGSignal (list) – the raw EMG signal
 nseg (int) – number of segments to evaluate
Returns: Mean absolute slope value
Return type: float

electromyography.
getMDF
(rawEMGPowerSpectrum, frequencies)[source]¶ Obtain the Median Frequency of the PSD.
MDF is a frequency at which the spectrum is divided into two regions with equal amplitude, in other words, MDF is half of TTP feature
 Input:
 raw EMG Power Spectrum
 frequencies
 Output:
 Median Frequency (Hz)
Parameters:  rawEMGPowerSpectrum (list) – power spectrum of the EMG signal
 frequencies (list) – frequencies of the PSD
Returns: median frequency of the EMG power spectrum
Return type: float

electromyography.
getMNF
(rawEMGPowerSpectrum, frequencies)[source]¶ Obtain the mean frequency of the EMG signal, evaluated as the sum of product of the EMG power spectrum and the frequency divided by total sum of the spectrum intensity:
MNF = sum(fPj) / sum(Pj) for j = 1 > M M = length of the frequency bin Pj = power at freqeuncy bin j fJ = frequency of the spectrum at frequency bin j
 Input:
 rawEMGPowerSpectrum: PSD as list
 frequencies: frequencies of the PSD spectrum as list
 Output:
 Mean Frequency of the PSD
Parameters:  rawEMGPowerSpectrum (list) – power spectrum of the EMG signal
 frequencies (list) – frequencies of the PSD
Returns: mean frequency of the EMG power spectrum
Return type: float

electromyography.
getMNP
(rawEMGPowerSpectrum)[source]¶ This functions evaluate the mean power of the spectrum.:
Mean Power = sum(Pj) / M, j = 1 > M, M = len of the spectrum
 Input:
 EMG power spectrum
 Output:
 mean power
Parameters:  rawEMGPowerSpectrum (list) – power spectrum of the EMG signal
 frequencies (list) – frequencies of the PSD
Returns: mean power of the EMG power spectrum
Return type: float

electromyography.
getMYOP
(rawEMGSignal, threshold)[source]¶ The myopulse percentage rate (MYOP) is an average value of myopulse output. It is defined as one absolute value of the EMG signal exceed a predefined thershold value.
MYOP = (1/N) * sum(f(xi)) for i = 1 > N f(x) = { 1 if x >= threshold 0 otherwise }
 Input:
 rawEMGSignal = EMG signal as list
 threshold = threshold to avoid fluctuations caused by noise and low voltage fluctuations
 Output:
 Myopulse percentage rate
Parameters:  rawEMGSignal (list) – the raw EMG signal
 threshold (int) – value to sum / substract to the zero when evaluating the crossing.
Returns: Myopulse percentage rate of the signal
Return type: float

electromyography.
getPSR
(rawEMGPowerSpectrum, frequencies, n=20, fmin=10, fmax=500)[source]¶ This function computes the Power Spectrum Ratio of the signal, defined as: Ratio between the energy P0 which is nearby the maximum value of the EMG power spectrum and the energy P which is the whole energy of the EMG power spectrum
 Input:
 EMG power spectrum
 frequencies as list
 n = range around f0 to evaluate P0
 fmin = min frequency
 fmax = max frequency
Parameters:  rawEMGPowerSpectrum (list) – power spectrum of the EMG signal
 frequencies (list) – frequencies of the PSD
 n (int) – range of frequencies around f0 to evaluate
 fmin (int) – min frequency to evaluate
 fmax (int) – lmaximum frequency to evaluate
Returns: Power spectrum ratio of the EMG power spectrum
Return type: float

electromyography.
getPeakFrequency
(rawEMGPowerSpectrum, frequencies)[source]¶ Obtain the frequency at which the maximum peak occur
 Input:
 raw EMG Power Spectrum as list
 frequencies as list
 Output:
 frequency in Hz
Parameters:  rawEMGPowerSpectrum (list) – power spectrum of the EMG signal
 frequencies (list) – frequencies of the PSD
Returns: peakfrequency of the EMG Power spectrum
Return type: float

electromyography.
getRMS
(rawEMGSignal)[source]¶ Get the root mean square of a signal.:
RMS = (sqrt( (1 / N) * sum(xi**2))) for i = 1 > N
 Input:
 raw EMG Signal as list
 Output:
 Root mean square of the signal
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: Root mean square of the EMG signal Return type: float

electromyography.
getSM
(rawEMGPowerSpectrum, frequencies, order)[source]¶ Get the spectral moment of a spectrum:
SM = sum(fj*(Pj**order)), j = 1 > M
 Input:
 raw EMG Power Spectrum
 frequencies as list
 order (int)
 Output:
 SM of order = order
Parameters:  rawEMGPowerSpectrum (list) – power spectrum of the EMG signal
 frequencies (list) – frequencies of the PSD
 order (int) – order to the moment
Returns: Spectral moment of order X of the EMG power spectrum
Return type: float

electromyography.
getSSC
(rawEMGSignal, threshold)[source]¶ Number of times the slope of the EMG signal changes sign.:
SSC = sum(f( (x[i]  x[i1]) X (x[i]  x[i+1]))) for i = 2 > n1 f(x){ 1 if x >= threshold 0 otherwise }
 Input:
 raw EMG Signal
 Output:
 number of Slope Changes
Parameters:  rawEMGSignal (list) – the raw EMG signal
 threshold (int) – value to sum / substract to the zero when evaluating the crossing.
Returns: Number of slope’s sign changes
Return type: int

electromyography.
getSSI
(rawEMGSignal)[source]¶ This function compute the summation of square values of the EMG signal.:
SSI = sum(xi**2) for i = 1 > N
 Input:
 raw EMG Signal as list
 Output:
 Simple Square Integral
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: SSI of the signal Return type: float

electromyography.
getTM
(rawEMGSignal, order)[source]¶ This function compute the Temporal Moment of order X of the EMG signal.:
TM = (1 / N * sum(xi**order) for i = 1 > N
 Input:
 raw EMG Signal as list
 Output:
 TM of order = order
Parameters:  rawEMGSignal (list) – the raw EMG signal
 order (int) – order the the TM function
Returns: Temporal Moment of order X of the EMG signal
Return type: float

electromyography.
getTTP
(rawEMGPowerSpectrum)[source]¶ This functions evaluate the aggregate of the EMG power spectrum (aka Zero Spectral Moment)
 Input:
 raw EMG Power Spectrum
 Output:
 Total Power
Parameters:  rawEMGPowerSpectrum (list) – power spectrum of the EMG signal
 frequencies (list) – frequencies of the PSD
Returns: total power of the EMG power spectrum
Return type: float

electromyography.
getVAR
(rawEMGSignal)[source]¶ Summation of average square values of the deviation of a variable.:
VAR = (1 / (N  1)) * sum(xi**2) for i = 1 > N
 Input:
 raw EMG Signal as list
 Output:
 Summation of the average square values
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: the VAR of the EMG Signal Return type: float

electromyography.
getVCF
(SM0, SM1, SM2)[source]¶ This function evaluate the variance of the central freuency of the PSD.:
VCF = (1 / SM0)*sum(Pj*(fj  fc)**2),j = 1 > M, = SM2 / SM0  (SM1 /SM0) **2
 Input:
 SM0: spectral moment of order 0
 SM1: spectral moment of order 1
 SM2: spectral moment of order 0
 Output:
 Variance of Central frequency of the Power spectrum
Parameters:  SM0 (float) – Spectral moment of order 0
 SM1 (float) – Spectral moment of order 1
 SM2 (float) – Spectral moment of order 2
Returns: Variance of central frequency
Return type: float

electromyography.
getWAMP
(rawEMGSignal, threshold)[source]¶ Wilson or Willison amplitude is a measure of frequency information. It is a number of time resulting from difference between the EMG signal of two adjoining segments, that exceed a threshold.:
WAMP = sum( f(x[i]  x[i+1])) for n = 1 > n1 f(x){ 1 if x >= threshold 0 otherwise }
 Input:
 rawEMGSignal = EMG signal as list
 threshold = threshold to avoid fluctuations caused by noise and low voltage fluctuations
 Output:
 Wilson Amplitude value
Parameters:  rawEMGSignal (list) – the raw EMG signal
 threshold (int) – value to sum / substract to the zero when evaluating the crossing.
Returns: Willison amplitude
Return type: float

electromyography.
getWL
(rawEMGSignal)[source]¶ Get the waveform length of the signal, a measure of complexity of the EMG Signal.:
WL = sum(x(i+1)  xi) for i = 1 > N1
 Input:
 raw EMG Signal as list
 Output:
 wavelength of the signal
Parameters: rawEMGSignal (list) – the raw EMG signal Returns: Waveform length of the signal Return type: float

electromyography.
getZC
(rawEMGSignal, threshold)[source]¶ How many times does the signal crosses the 0 (+threshold).:
ZC = sum([sgn(x[i] X x[i+1]) intersecated x[i]  x[i+1] >= threshold]) for i = 1 > N  1 sign(x) = { 1, if x >= threshold 0, otherwise }
 Input:
 rawEMGSignal = EMG signal as list
 threshold = threshold to use in order to avoid fluctuations caused by noise and low voltage fluctuations
 Output:
 ZC index
Parameters:  rawEMGSignal (list) – the raw EMG signal
 threshold (int) – value to sum / substract to the zero when evaluating the crossing.
Returns: Number of times the signal crosses the 0 (+ threshold)
Return type: float

electromyography.
phasicFilter
(rawEMGSignal, samplerate, seconds=4)[source]¶ Apply a phasic filter to the signal, with +4 seconds from each sample
 Input:
 rawEMGSignal = emg signal as list
 samplerate = samplerate of the signal
 Output:
 phasic filtered signal
Parameters:  rawEMGSignal (list) – the raw EMG signal
 samplerate (int) – samplerate of the signal in Hz
Returns: the phasic filtered signal
Return type: list