features¶
Time-domain features.
- Notation:
- \(x_i\) : value of a signal at time index \(i\)
- \(N\) : length of the signal
-
axopy.features.time.
integrated_emg
(x, axis=-1, keepdims=False)[source]¶ Sum over the rectified signal.
\[\text{IEMG} = \sum_{i=1}^{N} | x_{i} |\]Parameters: - x (ndarray) – Input data. Use the
axis
argument to specify the “time axis”. - axis (int, optional) – The axis to compute the feature along. By default, it is computed along rows, so the input is assumed to be shape (n_channels, n_samples).
- keepdims (bool, optional) – Whether or not to keep the dimensionality of the input. That is, if the input is 2D, the output will be 2D even if a dimension collapses to size 1.
Returns: y – IEMG of each channel.
Return type: ndarray, shape (n_channels,)
- x (ndarray) – Input data. Use the
-
axopy.features.time.
logvar
(x, axis=-1, keepdims=False)[source]¶ Log of the variance of the signal.
\[\text{log-var} = \log \left( \frac{1}{N} \sum_{i=1}^{N} \left(x_i - \mu \right)^2 \right)\]For electrophysiological signals that are mean-zero, this is the log of the mean square value, making it similar to
root_mean_square()
but scaling differently (slower) with \(x\).For EMG data recorded from forearm muscles, log-var has been found to relate to wrist angle fairly linearly [1]_.
Note: base-10 logarithm is used, though the base is not specified in [1]_.
Parameters: - x (ndarray) – Input data. Use the
axis
argument to specify the “time axis”. - axis (int, optional) – The axis to compute the feature along. By default, it is computed along rows, so the input is assumed to be shape (n_channels, n_samples).
- keepdims (bool, optional) – Whether or not to keep the dimensionality of the input. That is, if the input is 2D, the output will be 2D even if a dimension collapses to size 1.
Returns: y – log-var of each channel.
Return type: ndarray, shape (n_channels,)
References
[1] J. M. Hahne, F. Bießmann, N. Jiang, H. Rehbaum, D. Farina, F. C. Meinecke, K.-R. Müller, and L. C. Parra, “Linear and Nonlinear Regression Techniques for Simultaneous and Proportional Myoelectric Control,” IEEE Transactions on Neural Systems and Rehabilitation Engineering, vol. 22, no. 2, pp. 269–279, 2014. - x (ndarray) – Input data. Use the
-
axopy.features.time.
mean_absolute_value
(x, weights='mav', axis=-1, keepdims=False)[source]¶ Computes the mean absolute value (MAV) of each signal.
Mean absolute value is a popular feature for obtaining amplitude information from EMG, especially in gesture classification contexts [1]_.
There is an optional windowing function applied to the rectified signal, described as MAV1 and MAV2 in some references. A custom window can also be used. The general definition is given as:
\[\text{MAV} = \frac{1}{N} \sum_{i=1}^{N} w_i |x_i|\]Normal MAV does not use a windowing function, equivalent to setting all \(w_i = 1\).
MAV1 refers to a rectangular window which de-emphasizes the beginning and ending of an input window. The first quarter of the input samples receive a weight of 0.5, the middle half of the input samples receive a weight of 1, and the final quarter recieves a weight of 0.5:
\[\begin{split}w_i = \begin{cases} 1, & \frac{N}{4} \leq i \leq \frac{3N}{4} \\ 0.5, & \text{otherwise} \end{cases}\end{split}\]MAV2 uses a similar window structure to MAV1 (i.e. broken into first quarter, middle half, and final quarter), but the window is trapezoidal in shape, ramping from 0 to 1 over the first quarter and from 1 to 0 over the last quarter:
\[\begin{split}w_i = \begin{cases} 1, & \frac{N}{4} \leq i \leq \frac{3N}{4} \\ \frac{4i}{N}, & i < \frac{N}{4} \\ \frac{4(i - N)}{N}, & i > \frac{3N}{4} \end{cases}\end{split}\]Parameters: - x (ndarray) – Input data. Use the
axis
argument to specify the “time axis”. - weights (str or ndarray, optional) –
Weights to use. Possible values:
- ’mav’ : all samples in the signal are weighted equally (default).
- ’mav1’ : rectangular window with the middle half of the signal receiving unit weight and the first and last quarters of the signal receiving half weight.
- ’mav2’ : similar to ‘mav1’, but weights on the first and last quarters increase and decrease between 0 and 1 respectively, forming a trapezoidal window.
- [ndarray] : user-supplied weights to apply. Must be a 1D array
with the same length as the signals received in the
compute
method.
- axis (int, optional) – The axis to compute the feature along. By default, it is computed along rows, so the input is assumed to be shape (n_channels, n_samples).
- keepdims (bool, optional) – Whether or not to keep the dimensionality of the input. That is, if the input is 2D, the output will be 2D even if a dimension collapses to size 1.
Returns: y – MAV of each channel.
Return type: ndarray, shape (n_channels,)
See also
axopy.features.util.inverted_t_window()
- Generates the window for MAV1
axopy.features.util.trapezoidal_window()
- Generates the window for MAV2
References
[1] B. Hudgins, P. Parker, and R. N. Scott, “A New Strategy for Multifunction Myoelectric Control,” IEEE Transactions on Biomedical Engineering, vol. 40, no. 1, pp. 82-94, 1993. [2] A. Phinyomark, P. Phukpattaranont, and C. Limsakul, “Feature Reduction and Selection for EMG Signal Classification,” Expert Systems with Applications, vol. 39, no. 8, pp. 7420-7431, 2012. - x (ndarray) – Input data. Use the
-
axopy.features.time.
root_mean_square
(x, axis=-1, keepdims=False)[source]¶ Computes the root mean square of each signal.
RMS is a commonly used feature for extracting amplitude information from physiological signals.
\[\text{RMS} = \sqrt{\frac{1}{N} \sum_{i=1}^N x_i^2}\]Parameters: - x (ndarray) – Input data. Use the
axis
argument to specify the “time axis”. - axis (int, optional) – The axis to compute the feature along. By default, it is computed along rows, so the input is assumed to be shape (n_channels, n_samples).
- keepdims (bool, optional) – Whether or not to keep the dimensionality of the input. That is, if the input is 2D, the output will be 2D even if a dimension collapses to size 1.
Returns: y – RMS of each channel.
Return type: ndarray, shape (n_channels,)
- x (ndarray) – Input data. Use the
-
axopy.features.time.
slope_sign_changes
(x, threshold=0, axis=-1, keepdims=False)[source]¶ Computes the number of slope sign changes (SSC) of each signal.
A slope sign change occurs when the middle value of a group of three adjacent values in the signal is either greater than or less than both of the other two.
Parameters: - x (ndarray) – Input data. Use the
axis
argument to specify the “time axis”. - threshold (float, optional) – A threshold for discriminating true slope sign changes from those caused by low-level noise fluctuating about a specific value. By default, no threshold is used, so every slope sign change in the signal is counted.
- axis (int, optional) – The axis to compute the feature along. By default, it is computed along rows, so the input is assumed to be shape (n_channels, n_samples).
- keepdims (bool, optional) – Whether or not to keep the dimensionality of the input. That is, if the input is 2D, the output will be 2D even if a dimension collapses to size 1.
Returns: y – SSC of each channel.
Return type: ndarray, shape (n_channels,)
References
[1] B. Hudgins, P. Parker, and R. N. Scott, “A New Strategy for Multifunction Myoelectric Control,” IEEE Transactions on Biomedical Engineering, vol. 40, no. 1, pp. 82-94, 1993. - x (ndarray) – Input data. Use the
-
axopy.features.time.
waveform_length
(x, axis=-1, keepdims=False)[source]¶ Computes the waveform length (WL) of each signal.
Waveform length is the sum of the absolute value of the deltas between adjacent values (in time) of the signal:
\[\text{WL} = \sum_{i=1}^{N-1} | x_{i+1} - x_i |\]Parameters: - x (ndarray) – Input data. Use the
axis
argument to specify the “time axis”. - axis (int, optional) – The axis to compute the feature along. By default, it is computed along rows, so the input is assumed to be shape (n_channels, n_samples).
- keepdims (bool, optional) – Whether or not to keep the dimensionality of the input. That is, if the input is 2D, the output will be 2D even if a dimension collapses to size 1.
Returns: y – WL of each channel.
Return type: ndarray, shape (n_channels,)
References
[1] B. Hudgins, P. Parker, and R. N. Scott, “A New Strategy for Multifunction Myoelectric Control,” IEEE Transactions on Biomedical Engineering, vol. 40, no. 1, pp. 82-94, 1993. - x (ndarray) – Input data. Use the
-
axopy.features.time.
zero_crossings
(x, threshold=0, axis=-1, keepdims=False)[source]¶ Computes the number of zero crossings (ZC) of each signal.
A zero crossing occurs when two adjacent values (in time) of the signal have opposite sign. A threshold is used to mitigate the effect of noise around zero. It is used as a measure of frequency information.
Parameters: - x (ndarray) – Input data. Use the
axis
argument to specify the “time axis”. - threshold (float, optional) – A threshold for discriminating true zero crossings from those caused by low-level noise situated about zero. By default, no threshold is used, so every sign change in the signal is counted.
- axis (int, optional) – The axis to compute the feature along. By default, it is computed along rows, so the input is assumed to be shape (n_channels, n_samples).
- keepdims (bool, optional) – Whether or not to keep the dimensionality of the input. That is, if the input is 2D, the output will be 2D even if a dimension collapses to size 1.
Returns: y – ZC of each channel.
Return type: ndarray, shape (n_channels,)
References
[1] B. Hudgins, P. Parker, and R. N. Scott, “A New Strategy for Multifunction Myoelectric Control,” IEEE Transactions on Biomedical Engineering, vol. 40, no. 1, pp. 82-94, 1993. - x (ndarray) – Input data. Use the