Skip to content

Repository files navigation

Data-Driven Classification of Hand Postures for Myoelectric Control

M.Tech thesis project — Department of Mechanical Engineering, IIT Guwahati Advisor: Prof. Shyamanta M. Hazarika · Biomimetic Robotics & Artificial Intelligence Lab

Classifying 15 hand postures from 8-channel surface EMG, with an evaluation protocol that reflects how such a system would actually be deployed.


Headline result

The same features and the same models score very differently depending on how the data is split. Getting the split right turned out to be the most consequential decision in the project.

Evaluation protocol Random Forest Extra Trees
A. Random window split (KFold(shuffle=True)) 97.30% 98.18%
B. Leave-one-trial-out (GroupKFold on trial) 81.15% 83.72%
C. Leave-one-subject-out (unseen user) 32.28% 32.33%

15 classes; chance = 6.67%. Mean accuracy across 8 subjects.

Evaluation by protocol

Protocol A is not a result. It is the protocol this project originally used, and it is reported here only to quantify how much it inflates. Each subject's feature matrix holds 3,465 rows — 15 gestures × 3 trials × 77 windows — where the 77 windows are 128 ms segments taken at a 64 ms stride from a single continuous 5-second recording. Consecutive windows therefore share half their samples.

Shuffling those rows scatters near-duplicates across train and test. Measured directly: under KFold(shuffle=True), 100% of test windows come from a recording that also appears in the training fold. Under GroupKFold on trial, that figure is 0%. The 98% was largely measuring "can you recognise this recording", not "can you recognise this gesture".

Correcting the split costs 14.5 accuracy points. That gap is the main finding.

What the honest numbers say

  • 83.7% within-subject (Extra Trees, leave-one-trial-out) across 15 postures. Per-subject accuracy ranges 72.7% – 93.5%, macro F1 0.70 – 0.93. This is the number that describes a calibrated, single-user system, and it is a reasonable result for 15-class sEMG.
  • 32.3% cross-subject (leave-one-subject-out), against a 6.7% chance baseline. The model learns something transferable — roughly 5× chance — but nowhere near enough to deploy on a new wearer without calibration. Held-out subjects S6 and S7 reach ~60% while S2 and S5 sit below 21%, which points at electrode placement and forearm geometry rather than at the classifier.

This is the practical conclusion: per-user calibration is not a refinement of a myoelectric interface, it is a requirement. Commercial prostheses calibrate per wearer for exactly this reason.

Leave-one-subject-out confusion matrix

The cross-subject confusion matrix shows the failure is structured, not random. Whole-hand and distinct single-finger postures survive; adjacent-finger and combined-finger gestures collapse into each other, consistent with overlapping muscle activation and crosstalk between neighbouring electrode sites.


Dataset

Public sEMG repository published by Dr. Rami N. Khushaba.

Subjects 8
Postures 15 (individual and combined finger movements)
Trials 3 per posture per subject
Channels 8 forearm muscles
Sampling rate 4,000 Hz
Total recordings 360 trials (8 × 15 × 3)

Method

Preprocessing — amplification (gain 1000), 20–450 Hz band-pass to retain the muscle-activity band, 50 Hz notch for mains interference, mean baseline removal.

Segmentation — each trial trimmed from 20 s to its 5 s active window, then split into 128 ms windows (512 samples) at a 64 ms stride, producing 77 windows per trial and 27,720 windows overall. The 128 ms length keeps total response time under the ~300 ms ceiling required for real-time control.

Feature extraction — 16 time-domain and statistical features per channel (MAV, VAR, STD, min, max, RMS, sum of absolute differences, skewness, kurtosis, zero-crossings, energy, Hjorth activity, IQR, peak-to-peak, slope sign change, Willison amplitude), giving a 128-dimensional vector per window.

Classification — Random Forest, Extra Trees and SVM, each inside a Pipeline with StandardScaler so the scaler is fitted on training folds only. Evaluated under all three protocols above.

Dimensionality reduction — muscle synergies extracted with Non-Negative Matrix Factorisation, component count chosen by Variance-Accounted-For analysis (2 synergies, VAF > 95%). The resulting 8×2 weight matrix flattens to a 16-dimensional vector, an 8× reduction that stays physiologically interpretable. Extra Trees on this representation reached 93.3% — but on a single subject and only 45 samples, so it is a pilot result rather than a validated one.


Repository structure

File Purpose
1_StructuralAnalysis_&_Plots.ipynb Raw signal inspection, FFT, per-muscle activity plots
2_Structural_HyperParametersTuning.ipynb Preprocessing, segmentation, feature extraction
3_OrganisingFeatures_Classification.ipynb Feature assembly and original classification
4_Evaluating_Results.ipynb Confusion matrices and per-class metrics
5_NMF_Features.ipynb Muscle synergy extraction via NMF
6_Leakage_Corrected_Evaluation.py Three-protocol evaluation (A / B / C)
6_Leakage_Corrected_Evaluation.ipynb Notebook driver for the above
Harshit_MTP_Thesis.pdf Full thesis report

Reproducing the evaluation

pip install numpy pandas scikit-learn joblib matplotlib seaborn

# from the folder containing Features_SPT.joblib
python 6_Leakage_Corrected_Evaluation.py --skip-svm

Outputs evaluation_by_protocol.csv and .png, plus per-fold CSVs for each protocol. --skip-svm runs Random Forest and Extra Trees only; the RBF SVM is O(n²) and adds hours to protocol C without changing the conclusion.


Limitations and what I would do next

  • Cross-subject performance is the blocker, not within-subject accuracy. The obvious directions are domain adaptation, subject-invariant feature design, and a short per-user calibration routine that fine-tunes on a handful of trials.
  • Three trials per gesture makes leave-one-trial-out a 3-fold evaluation, so the per-subject estimates carry wide confidence intervals.
  • The NMF result needs extending to all 8 subjects under protocols B and C before it can be compared with the full feature set.
  • No real-time testing. Segment length was chosen with latency in mind, but end-to-end response time on live streaming input was never measured.

Tools

Python · NumPy · pandas · SciPy · scikit-learn · Matplotlib · Seaborn · joblib

References

Khushaba, R. N. — sEMG biosignals repository. Phinyomark, A. et al. — Feature reduction and selection for EMG signal classification. Oskoei, M. A. & Hu, H. — Myoelectric control systems: a survey. Reaz, M. B. I. et al. — Techniques of EMG signal analysis.

About

My MTech project focuses on classifying hand gestures using surface Electromyography (sEMG) signals to enable intuitive control for assistive and rehabilitation technologies. I worked with large-scale EMG datasets (80,000×8 signals per trial) and built a complete ML pipeline for accurate classification of the hand postures.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages