Neuroarm: Noninvasive EEG-based control of assistive robotic arm using machine learning

Neuroarm represents the culmination of a progressive journey in robotics and neural engineering, transforming the way we interact with machines. This project revolves around the development of a sophisticated robotic arm controlled through EEG.
Neil Bhalla
Grade 11

Problem

This project confronts a significant gap in assistive technology, specifically in prosthetic development, by proposing an innovative solution: a non-invasive, EEG-controlled robotic arm. This approach marks a radical departure from traditional prosthetics, which predominantly rely on residual muscle movements or physical manipulation, thereby limiting their use to those with certain levels of motor function. The integration of EEG technology and machine learning represents a novel venture in prosthetics, enabling control through neural activity rather than physical movement.

The relevance of this project is underscored by the increasing demand for advanced assistive devices due to an aging global population and higher survival rates from conditions leading to motor impairments. This project aims to meet these needs by leveraging recent advancements in EEG signal processing and machine learning algorithms, which have made the interpretation of brain signals more accurate and user-friendly.

This initiative is not merely about enhancing existing technology but redefining the capabilities of assistive devices. It addresses the current limitations in EEG-based prosthetics, such as accuracy and responsiveness, by employing sophisticated machine learning techniques for precise signal interpretation. The project's scope is logically grounded in current technological advancements, making its goals achievable and impactful.

By focusing on EEG-driven control systems, the project aims to overcome the barrier faced by people living with mobility impairments, offering a new era of assistive technology that is more inclusive and empowering. Inspired by the resilience of individuals like Stephen Hawking, this project represents hope for enhanced quality of life and independence for those unable to use standard prosthetic devices, embodying a future where technology transcends physical constraints.

Method

1. Construction of the Robotic Arm:

  • CAD File Selection and Evaluation: Extensively researched and selected CAD files from specialized online repositories. Each file was assessed for detailed structural design, compatibility with standard servo motors, and ease of assembly.
  • Component Assembly Process: Documented the assembly stages, emphasizing the technical specifications of each part. Provided a detailed description of the integration of mechanical parts like servos, ensuring correct torque specifications, joint alignment, and gripper functionality.
  • Microcontroller and Servo Driver Integration: Explored various microcontroller options, ultimately choosing Arduino for its user-friendly interface and robust community support. Detailed the integration process with the PCA9685 servo driver, including the configuration of control signals for precise movement calibration.
    Carousel image representing the 3D design. Either an user-provided picture or a 3D render.

2. EEG Signal Acquisition Process:

  • The EEG signal acquisition process in this project will utilize the Lab Streaming Layer (LSL) framework. LSL is a system for synchronizing streaming data for real-time applications, commonly used in neuroscience research. It's specifically designed to handle high data rates and provide low-latency access to live EEG data streams.

3. Feature Extraction Process:

Feature extraction in EEG data processing involves converting complex brainwave signals into a format suitable for analysis and interpretation. Here's an overview of different feature extraction methods along with their pros and cons:

  • Time-Domain Analysis:

    • What it is: Analyzing the signal based on its amplitude variations over time.
    • Pros: Simple to implement and understand.
    • Cons: May not capture the frequency-related complexities of EEG signals.
  • Frequency-Domain Analysis (FFT and PSD):

    • What it is: Transforming the signal to frequency domain to identify dominant frequencies and their intensities.
    • Pros: Effective in identifying signal frequency components.
    • Cons (FFT): Provides limited time-related information.
    • Cons (PSD): More computationally demanding than FFT.
  • Wavelet Transform:

    • What it is: Offers a time-frequency analysis of the EEG signal.
    • Pros: Good for non-stationary signal analysis.
    • Cons: Requires careful selection of wavelets and is computationally intensive.
  • Entropy Measures:

    • What it is: Quantifies the randomness or complexity of the EEG signal.
    • Pros: Useful in assessing the complexity of brain activity.
    • Cons: Interpretation can be complex and the results are sensitive to signal quality.
  • Autoregressive Models:

    • What it is: Models the EEG signal as a linear combination of its past values.
    • Pros: Useful in modeling EEG dynamics.
    • Cons: Model order selection is crucial and can be influenced by noise.
  • Hjorth Parameters:

    • What it is: Describes the signal in terms of activity, mobility, and complexity.
    • Pros: Simple and quick to calculate.
    • Cons: Might not capture the full dynamics of EEG signals.
  • Statistical Features:

    • What it is: Basic statistical measures like mean, variance, etc., of the EEG signal.
    • Pros: Easy to compute and understand.
    • Cons: May not fully capture the signal's characteristics relevant to brain activity.
  • Common Spatial Patterns (CSP):

    • What it is: Used primarily in motor imagery tasks to enhance signal variance for one class while suppressing it for the other.
    • Pros: Effective in differentiating between two mental states.
    • Cons: Limited to scenarios where two states are compared.
  • Band Power Ratios:

    • What it is: Calculates the power within specific EEG frequency bands and their ratios.
    • Pros: Directly relates to different types of brain activities.
    • Cons: Requires careful band selection and may not capture inter-band dynamics.
  • Selecting the appropriate feature extraction method depends on the specific requirements of the EEG application, computational resources, and the nature of the EEG signals being analyzed. Testing out all of them will be required.

4. Machine Learning Model Development and Training:

  • Introduction to Machine Learning Models:

  • Machine Learning Models are algorithms that enable a computer to learn from data and make predictions or decisions. In EEG data analysis, they play a critical role in interpreting complex brain signals.
  • Process Overview:

  • Feature Loading: The selected features from EEG data, such as PSD values and band power ratios, are loaded into different classifiers.
  • Data Splitting: The dataset is divided into training (80%) and testing (20%) sets to validate model performance.
  • Classifier Evaluation: Various classifiers are tested to find the most suitable one for EEG data interpretation.
  • Exploring Classifiers:

  • Support Vector Machine (SVM):

    • What it is: A supervised machine learning model that uses a hyperplane to categorize data.
    • Pros/Cons: Good for high-dimensional data but not ideal for very large datasets.
  • Random Forest:

    • What it is: An ensemble learning method using multiple decision trees.
    • Pros/Cons: Handles large data but can be slow in making predictions.
  • K-Nearest Neighbors (k-NN):

    • What it is: A simple algorithm that classifies data based on the closest training examples in the feature space.
    • Pros/Cons: Simple to implement but computationally expensive.
  • Logistic Regression:

    • What it is: A statistical model that predicts the probability of a binary outcome.
    • Pros/Cons: Efficient for smaller datasets but assumes a linear relationship.
  • Neural Networks:

    • What it is: Composed of interconnected nodes, mimicking the human brain, ideal for capturing complex patterns.
    • Pros/Cons: Flexible but requires large datasets and is computationally intensive.
  • Decision Trees:

    • What it is: A flowchart-like tree structure where each internal node represents a test on an attribute.
    • Pros/Cons: Easy to interpret but prone to overfitting.
  • Gradient Boosting:

    • What it is: A method that builds an additive model in a forward stage-wise fashion.
    • Pros/Cons: Provides high accuracy but is computationally demanding.
  • Naive Bayes:

    • What it is: A simple probabilistic classifier based on Bayes' theorem.
    • Pros/Cons: Fast and works well with high dimensions but assumes feature independence.
  • Deep Learning (CNNs, RNNs):

    • What it is: Advanced neural network architectures for handling complex data structures.
    • Pros/Cons: Excellent for large datasets but complex and prone to overfitting.
  • Selection and Optimization:

  • The classifiers will be evaluated based on their performance with EEG data. The focus will be on accuracy, computational efficiency, and suitability for EEG signal analysis.
  • The final model will undergo rigorous optimization for enhanced predictive accuracy.

5. Final Implementation for Real-Time EEG-Based Control:

The final implementation of the EEG-controlled robotic arm project involves several critical steps:

  1. Threshold Detection: The system continuously monitors EEG signals for specific patterns or activities. When it detects an event exceeding a predefined threshold, such as a blink or bite, it triggers the next phase.

  2. Recording EEG Data: Once the threshold is exceeded, the system records EEG data for a set duration, typically half a second. This duration ensures sufficient data is captured to accurately identify the specific action.

  3. Feature Extraction: The recorded EEG data undergoes feature extraction. These features are crucial in differentiating between different types of actions (e.g., blink, double blink, bite, double bite).

  4. Classification: The extracted features are then fed into a pre-trained machine-learning model. The model classifies the data into one of the predefined categories (blink, double blink, bite, or double bite) based on the patterns identified in the EEG data.

  5. Action Execution: Once the event is classified as a number from 0-3, that number is sent to an Arduino.

  6. Robotic Arm Control: The Arduino then controls a servo based on which number it received.

This process allows individuals with mobility impairments to control the robotic arm using their brain signals, offering a new level of interaction and independence.

Analysis

Analysis of Feature Extraction Methods:

  1. Max Amplitude Features:

    • Utility: Exceptionally useful for differentiating between blinks and bites. Bites typically generate a higher peak in the EEG signal compared to blinks.
    • Application: The maximum amplitude of an EEG signal indicates the most significant electrical activity during a specific time frame. By comparing these peaks, the system can distinguish between subtle blinks and more pronounced bite actions.
  2. Peak Count Features:

    • Utility: Crucial for differentiating between single and double blinks or bites. A double action would exhibit a higher peak count within a given time frame.
    • Application: This method counts the number of times the signal crosses a certain amplitude threshold. A higher count within a short duration suggests repetitive actions like double blinks or bites.
  3. Band Power Ratios:

    • Utility: Essential in understanding the distribution of brain activity in different frequency bands, which varies with different types of neural activities.
    • Application: By analyzing the power within specific EEG frequency bands and their ratios, the system can correlate these patterns with different mental states or actions.
  4. Power Spectral Density (PSD) Features:

    • Utility: Highly effective in analyzing the frequency content of EEG signals, which is key in differentiating various mental states or actions.
    • Application: PSD features provide a comprehensive view of the signal's power distribution across frequencies, allowing for a detailed analysis of the brain's response during different actions.

These feature extraction methods were chosen due to their combined ability to provide a detailed and nuanced understanding of EEG signals. Each method contributes uniquely to the model, enhancing its ability to accurately classify brain activities associated with specific actions. The selection of these methods was based on extensive testing and analysis, ensuring their effectiveness in the context of EEG-based robotic arm control.

 

Analysis of Machine Learning Algorithms:

  1. Support Vector Machine (SVM):

    • Accuracy: 0.8750
    • Precision: 0.9375
    • Recall: 0.8750
    • F1 Score: 0.8869
    • Analysis: SVM demonstrated high accuracy, precision, and recall, indicating its effectiveness in classifying EEG-based actions. The high F1 score suggests a balanced performance between precision and recall.
  2. Random Forest:

    • Accuracy: 0.8750
    • Precision: 0.9375
    • Recall: 0.8750
    • F1 Score: 0.8869
    • Analysis: Random Forest matched SVM in performance metrics, indicating its robustness. However, considering the complexity and computational demands, SVM was preferred for its efficiency.
  3. K-Nearest Neighbors (KNN):

    • Accuracy: 0.6250
    • Precision: 0.7083
    • Recall: 0.6250
    • F1 Score: 0.5958
    • Analysis: KNN showed moderate accuracy and precision. Its lower F1 score compared to SVM and Random Forest indicated less effectiveness in this application.
  4. Logistic Regression:

    • Accuracy: 0.8750
    • Precision: 0.9375
    • Recall: 0.8750
    • F1 Score: 0.8869
    • Analysis: Logistic Regression's performance was on par with SVM and Random Forest, but its assumption of a linear relationship between variables made it less suitable for complex EEG data patterns.
  5. Decision Tree:

    • Accuracy: 0.6250
    • Precision: 0.6042
    • Recall: 0.6250
    • F1 Score: 0.5744
    • Analysis: The Decision Tree's lower performance metrics indicated its limitations in handling the complexities of EEG data.
  6. Naive Bayes:

    • Accuracy: 0.8750
    • Precision: 0.9375
    • Recall: 0.8750
    • F1 Score: 0.8869
    • Analysis: While Naive Bayes showed high accuracy, its assumption of feature independence is often not valid in EEG data, leading to the preference for SVM.
  7. Neural Network:

    • Accuracy: 0.8750
    • Precision: 0.9375
    • Recall: 0.8750
    • F1 Score: 0.8869
    • Analysis: Neural Networks showed promising results; however, their complexity and need for extensive data for training made them less practical for this project.
  8. Gradient Boosting:

    • Accuracy: 0.2500
    • Precision: 0.5417
    • Recall: 0.2500
    • F1 Score: 0.2625
    • Analysis: Gradient Boosting's significantly lower performance metrics indicate that it was not suitable for this particular EEG data analysis task.

In conclusion, based on the comprehensive analysis of various machine learning models, the SVM was chosen as the most suitable algorithm for this project due to its high accuracy, precision, recall, and F1 score, along with its computational efficiency and effectiveness in handling the intricacies of EEG signal classification.

Why does the SVM perform so well?

High Dimensionality and Feature Space Transformation

  1. Vector Spaces and Dimensionality: EEG data is represented in a high-dimensional vector space, typically resulting from multiple electrodes and time series data. Formally, if n is the number of electrodes and m is the number of time points, the feature space could be represented as R^(n x m).

  2. Curse of Dimensionality and Generalization Error: High-dimensional spaces can lead to overfitting, as described by the Hughes phenomenon or the curse of dimensionality. SVM combats this by maximizing the margin, which effectively minimizes the VC dimension of the classifier, thus reducing the generalization error.

Kernel Trick and Non-linear Mappings

  1. Hilbert Spaces and Kernel Functions: EEG data often exhibits non-linear relationships. SVM uses kernel functions to map the original finite-dimensional space into a higher-dimensional (potentially infinite-dimensional) Hilbert space. Common kernels like the Radial Basis Function (RBF) kernel allow the capturing of non-linear patterns in the data.

  2. Mercer's Theorem and Convolution Operations: The validity of these kernels is guaranteed by Mercer's Theorem, which ensures that the kernel function corresponds to an inner product in some expanded feature space. This transformation is key in handling complex, non-linear patterns typical in EEG signals.

Robustness to Noise and Regularization

  1. Regularization and Lagrange Multipliers: SVM includes a regularization parameter C that controls the trade-off between the margin size and misclassification rate. Mathematically, this is represented in the SVM’s objective function, which minimizes (1/2) ||w||^2 + C sum_{i=1}^{n} xi_i, where xi_i are slack variables representing the degree of misclassification.

  2. Structural Risk Minimization (SRM): SVM's approach embodies the principle of SRM, balancing the empirical risk and the complexity of the model (as measured by the margin or the norm of the weight vector). This is particularly relevant in EEG analysis where the signal-to-noise ratio can be low.

Sparsity and Computational Efficiency

  1. Support Vectors and Sparse Solutions: In the dual form of the SVM, the solution depends only on a subset of data points, the support vectors. This sparsity is a result of most Lagrange multipliers alpha_i being zero in the solution of the dual problem, enhancing computational efficiency, crucial for high-dimensional EEG data.

  2. Quadratic Programming and Convex Optimization: SVM solves a quadratic programming problem, which is a convex optimization problem guaranteeing a global optimum. This stability and consistency are vital in EEG signal classification, where the interpretation of results is critical.

Conclusion

The mathematical foundations of SVM — including handling high-dimensional spaces, the kernel trick, robustness to noise through regularization, sparsity of solutions, and convex optimization — align well with the challenges presented by EEG data. These characteristics facilitate the effective capture of complex patterns, generalization to new data, and robust performance in noisy environments, making SVM a superior choice for EEG feature classification.

Conclusion

The success of this EEG-controlled robotic arm project paves the way for revolutionary applications in prosthetics, offering new hope and capabilities for individuals with mobility impairments. The precision and responsiveness achieved in this project hint at a future where brain-computer interfaces could transform everyday technologies. Imagine a world where the need for physical keyboards is obsolete, replaced by the intuitive power of our thoughts to navigate and interact with digital spaces. This project stands as a testament to such potential, blending the realms of neuroscience, robotics, and AI to unlock previously unimagined possibilities.

Citations

Python Libraries Used:

  1. NumPy: Harris, C.R., Millman, K.J., van der Walt, S.J., et al. (2020). Array programming with NumPy. Nature 585, 357-362.
  2. Scikit-learn: Pedregosa, F., Varoquaux, G., Gramfort, A., et al. (2011). Scikit-learn: Machine Learning in Python. JMLR 12, pp. 2825-2830.
  3. Joblib: Joblib: running Python functions as pipeline jobs.
  4. SciPy (for signal processing): Virtanen, P., Gommers, R., Oliphant, T.E., et al. (2020). SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python. Nature Methods 17, 261-272.
  5. pySerial (for Arduino communication): Stinner, C. pySerial: Python Serial Port Extension.
  6. Lab Streaming Layer (LSL): Kothe, C. Lab streaming layer (LSL).
  7. MuseLSL: Alexandre Barachant, Dano Morrison, Hubert Banville, Jason Kowaleski, Uri Shaked, Sylvain Chevallier, & Juan Jesús Torre Tresols. (2019, May 25). muse-lsl (Version v2.0.2). Zenodo. http://doi.org/10.5281/zenodo.3228861

 

Acknowledgement

The completion of this project would not have been possible without the encouragement of Mr. Ajat Hukkoo. I would also like to thank my pre-engineering teacher, Mr. Michael MacDonald for fostering my love of machine learning. Lastly, I would like to thank my older sister, Rhea, for editing this report.