Skip to main content

Test Package for NINAPRO

Project description

License: MIT

DESCRIPTION

A sample python package deployment utility for NINAPRO dataset. This library aims at easing the preprocessing, amd training of the EMG signals from the NinaPro database.

QUICK START

Dependencies

This pipeline requires the dependencies which can be installed by running pip install -r requirements.txt

Functions

  • get_data(path, file)

Download the data from the NinaPro official website and save the data in a folder. The get_data() requires the folder path and the file name as the input arguments. For example:

data = get_data('DB2_s1/DB2_s1','S1_E1_A1.mat')

 

  • normalise(data, train_reps)

normalise() scales the data using the normalise() which uses the StandardScaler() from scikit-learn to normalize the data. It fits on training reps only and then transforms the whole data (excluding stimulus and repetition ofcourse).

data = normalise(data, train_reps)

train_reps are the reps required in training set and test_reps are reps required in the test/validation set. According to the recent research, this permutation of numbers proved to give better results.

train_reps = [1,3,4,6] test_reps = [2,5]

 

  • filter_data(data, f, butterworth_order=4, btype='bandpass')

Sometimes, it is required that the signal is filtered with low noise or high noise frequencies. filter_data uses Butterworth filter to filter the data. It requires the cutoff frequency, the butterworth order, and the type of filter (btype is one of lowpass, highpass, bandpass). The bandpass filter requires the f value to be a tuple or a list containing lower cutoff frequency and higher cutoff frequency.

emg_low = filter_data(data=data, f=20, butterworth_order=4, btype='lowpass')

emg_band = filter_data(data=data, f=(20,40), butterworth_order=4, btype='bandpass')

emg_high = filter_data(data=data, f=20, butterworth_order=4, btype='high')

 

  • notch_filter(data, f0, Q, fs=2000)

A Notch Filter is a bandstop filter with a very narrow stopband and two passbands, it actually highly attenuates/eliminates a particular frequency component from the input signal while leaving the amplitude of the other frequencies more or less unchanged.

f0 is the notch_frequency, Q is the quality factor and fs is the sampling frequency.

emg_notch = notch_filter(data=emg_band,f0=60,Q=30,fs=2000)

 

  • windowing(data, reps, gestures, win_len, win_stride)

windowing() is used to augment the data. The function requires the following arguments : data, reps, gestures, win_len, win_stride.

data = Pandas dataframe just like returned by any of the above functions.

reps = Repetitions that you want to use for windowing.

gestures = The gesture movements that you wish to classify.

win_len = (Length of window in milli-second) x 2. For example, for a window of 300ms, use 600 as the win_len since the sampling frequency of signal is 2000Hz.

win_stride = (Length of stride in milli-second) x 2. For example, for a stride of 10ms, use 20 as the win_stride since the sampling frequency of signal is 2000Hz.

X_train, y_train, r_train = windowing(emg_notch, train_reps, gestures, win_len, win_stride)

X_test, y_test, r_test = windowing(emg_notch, test_reps, gestures, win_len, win_stride)

 

  • get_categorical(y)

For multiclass classification, we need the labels to be represented in one-hot representation. get_categorical() helps in converting the integer labels to one-hot representation.

y_train = get_categorical(y_train)

y_test = get_categorical(y_test)

 

  • feature_extractor(features, shape, data)

Hand crafting features could be time-consuming and expensive. We extract important features:

Time Domain (rms,hist,entropy,kurtosis,zero_cross,min,max,mean,median)

Frequency Domain (fft,psd)

The extractor function will take care of extracting features for each channel of input data and append it columnwise. The output dataframe would include all required features of all channels.

features = [rms,min,max,median] Change this list according to features required.

feature_matrix = feature_extractor(features,(X_train.shape[0],-1),X_train)

test_feature_matrix = feature_extractor(features,(X_test.shape[0],-1),X_test)

 

  • pca(data, comp)

PCA is a dimensionality-reduction method that is often used to reduce the dimensionality of large data sets, by transforming a large set of variables into a smaller one that still contains most of the information in the large set. The function returns the reduced feature matrix with the mentioned number of components(columns).

reduced_feature_matrix = pca(feature_matrix,30). This returns 30 columns in the final matrix.

reduced_test_feature_matrix = pca(test_feature_matrix,30)

 

  • rectify(data)

This function rectifies the signals and converts all the negative values to positive values by simply using the absolute value.

emg_rectified = rectify(emg_notch)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nina_funcs-1.0.2.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

nina_funcs-1.0.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file nina_funcs-1.0.2.tar.gz.

File metadata

  • Download URL: nina_funcs-1.0.2.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for nina_funcs-1.0.2.tar.gz
Algorithm Hash digest
SHA256 93f8fc7b62da44e970bc45967074044edee4e959032a20b4358376878f1a8bcc
MD5 5d84ab9ff16f6050ec15fc416ce8cbd0
BLAKE2b-256 0ee48f1e55717384e278a25337e5431f5b044d603aa28eabd54995b4634e9a42

See more details on using hashes here.

File details

Details for the file nina_funcs-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: nina_funcs-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for nina_funcs-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a607f26e5ee02526cfc99ca9376a2a8a41cd9ee86a023e19aee0463bb997fc42
MD5 249d7392e13c79a5a4f0b58dcb21e323
BLAKE2b-256 a1cd5267e4f55187ec0fa32558ac5a7752d24a9107ce1a27a426325762bb7fb4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page