emgdecompy.preprocessing
Module Contents
Functions
|
Takes the raw EMG signal array, flattens it, and removes empty channels with no data. |
|
Filters input data using a Butterworth band-pass filter. |
|
Takes a one-dimensional array and extends it using past observations. |
|
Takes an array with dimensions M by K, |
Subtract mean of each row. |
|
|
Whiten the input matrix through zero component analysis. |
- emgdecompy.preprocessing.flatten_signal(raw)[source]
Takes the raw EMG signal array, flattens it, and removes empty channels with no data.
- Parameters
raw (numpy.ndarray) – Raw EMG signal array.
- Returns
Flattened EMG signal array, with empty channels removed.
- Return type
numpy.ndarray
- emgdecompy.preprocessing.butter_bandpass_filter(data, lowcut=10, highcut=900, fs=2048, order=6)[source]
Filters input data using a Butterworth band-pass filter.
- Parameters
data (numpy.ndarray) – 1D array containing data to be filtered.
lowcut (float) – Lower range of band-pass filter.
highcut (float) – Upper range of band-pass filter.
fs (float) – Sampling frequency in Hz.
order (int) – Order of filter.
- Returns
Filtered data.
- Return type
numpy.ndarray
Examples
>>> butter_bandpass_filter(data, 10, 900, 2048, order=6)
- emgdecompy.preprocessing.extend_input_by_R(x, R)[source]
Takes a one-dimensional array and extends it using past observations.
- Parameters
x (numpy.ndarray) – 1D array to be extended.
R (int) – How far to extend x.
- Returns
len(x) by R+1 extended array.
- Return type
numpy.ndarray
Examples
>>> R = 5 >>> x = np.array([1, 2, 3]) >>> extend_input_by_R(x, R) array([[1., 2., 3.], [0., 1., 2.], [0., 0., 1.], [0., 0., 0.], [0., 0., 0.], [0., 0., 0.]])
- emgdecompy.preprocessing.extend_all_channels(x_mat, R)[source]
Takes an array with dimensions M by K, where M represents number of channels and K represents observations, and “extends” it to return an array of shape M * (R+1) by K.
- Parameters
x_mat (numpy.ndarray) – 2D array to be extended.
R (int) – How far to extend x.
- Returns
M(R+1) x K extended array.
- Return type
numpy.ndarray
Examples
>>> R = 3 >>> x_mat = np.array([[1, 2, 3, 4,], [5, 6, 7, 8,]]) >>> extend_all_channels(x_mat, R) array([[1., 2., 3., 4.], [0., 1., 2., 3.], [0., 0., 1., 2.], [0., 0., 0., 1.], [5., 6., 7., 8.], [0., 5., 6., 7.], [0., 0., 5., 6.], [0., 0., 0., 5.]])
- emgdecompy.preprocessing.center_matrix(x)[source]
Subtract mean of each row. Results in the data being centered around x=0.
- Parameters
x (numpy.ndarray) – Matrix of arrays to be centered.
- Returns
Centered matrix array.
- Return type
numpy.ndarray
Examples
>>> x = np.array([[1, 2, 3], [4, 6, 8]]) >>> center_matrix(x) array([[-1., 0., 1.], [-2., 0., 2.]])
- emgdecompy.preprocessing.whiten(x)[source]
Whiten the input matrix through zero component analysis.
- Parameters
x (numpy.ndarray) – Centred 2D array to be whitened.
- Returns
Whitened array.
- Return type
numpy.ndarray
Examples
>>> x = np.array([[1, 2, 3, 4], # Feature-1 [5, 6, 7, 8]]) # Feature-2 >>> whiten(x) array([[-1.34217726e+08, -1.34217725e+08, -1.34217725e+08, -1.34217724e+08], [ 1.34217730e+08, 1.34217731e+08, 1.34217731e+08, 1.34217732e+08]])