Neural Engineering
Real-time C++ Implementation of H infinity Algorithm for Removal of Ocular Artifacts of Electroencephalography for Brain-Machine Interface Application
Alana M. Maluszczak
Undergraduate Student
University of Arizona
Rockaway Township, New Jersey, United States
Jose Contreras-Vidal
Principal Investigator
University of Houston, United States
Jose Gonzalez-Espana
PhD Student
University of Houston, United States
Strokes can cause loss of muscle function. About 70% of stroke survivors experience weakness in the arms [1]. Neural engineering has been making advances to fix this with a top-down approach by interpreting brain signals to detect muscle intentions to reactivate the affected muscles. Electroencephalography (EEG) is a technology that can quantify recorded electrical activity of the brain using electrodes on the scalp [2]. The EEG can be used in non-invasive brain-machine interfaces (BMI) to record brain activity and send the decoded information to actuators. Using this technology during elbow extension and flexion tasks can be used to replace traditional physical therapy by incorporating robotic actuators to direct the muscles properly. The Neuro-Exo is a project focused on developing a robotic arm controlled solely based on the user's thoughts by communicating through an EEG headset. The brain signals recorded are contaminated by artifacts, such as eye movements and blinking, which can be measured by electrooculogram (EOG) electrodes. The H infinity filtering technique is a robust, adaptive filtering method that continuously updates based on previous corrections [3]. The algorithm has been used to remove the EOG noise in real-time but has not yet been optimized in a way that saves time, memory, and energy consumption. Optimization in this regard is necessary to be able to improve the functionality of embedded systems designed to be compact and wearable for long periods of time. This work presents a novel way to implement the H infinity filter in pseudo real-time using C++.
C++ programming of H infinity was written to filter out EOG data in real time. MATLAB is commonly used for processing EEG data and there is an existing code written in it to filter out ocular artifacts from EEG signals. However, it is known that MATLAB is not the most efficient programming language for embedded systems applications [4]. C++ is a low-level computing language, which could lead to faster data processing. It is not designed with efficient numerical computing like MATLAB, prompting a more complicated approach. By creating a pseudo code flowchart of this MATLAB code, the filter algorithm was simplified, as seen in Figure 1. The raw data is inputted into C++ and variables were correctly assigned and initialized. The parameters p and gamma are chosen to characterize the amount of noise that the filter needs to remove, and how quickly to adapt to the artifacts, respectively. The code then steps into the filter function so that every sample will be cleaned, shown in Figure 2. For further optimization, the 4 EOG channels were reduced to 3, representing the design of the NeuroExo headset. The next step is to apply pseudo-real time filtering. The code will simulate real EEG data collection by isolating each sample and inputting it to the filtering pipeline. From there, testing will be done through the BeagleBone, a single-board computer processor, to verify that it would work both with real-time EEG data and the limited memory and storage of the board. The output of all of the methods are compared to the filtering done in MATLAB.
The run time of the MATLAB code was reduced by a factor of 4 by converting it into C++. All of the ocular artifacts removed in the MATLAB code were removed in the implementation in C++, as seen in Figure 4. Filtering using pseudo-real time is being developed and should remove the same sources of noise. It will be tested by the BeagleBone in the NeuroExo headset, filtering raw data in real time as the user wears it.
There is now a working C++ implementation of H infinity. It can be used to remove ocular noise from any set of EEG data that has EOG channels. The MATLAB code run time was 16.58 seconds, nowhere near sufficient for real time purposes. The C++ computational speed with 4 EOG channels was much faster at 4.14 seconds, and with 3 channels was 4.27 seconds. All tests were ran on 64-bit operating system, x64-based processor CPU @ 1.60GHz, 2.11 GHz Processor, 7.80 GB RAM. When proven it can filter in real-time, the code can be implemented in any device to remove sources of ocular noise with the same accuracy as the offline version.
The H infinity algorithm is a general technique, not limited to removing ocular artifacts. In the future, the code can be adjusted to remove other common sources of EEG contamination including but not limited to motion artifacts and electrocardiography (ECG) artifacts. Once fully optimized, the C++ code can be implemented on the EEG headset to clean data on patients undergoing stroke rehabilitation. The device will be able to translate the user’s intentions of movement to the robotic exoskeleton accurately due to its ability of real-time denoising.
[1] Allison, R., Shenton, L., Bamforth, K., Kilbride, C., & Richards, D. (2016). Physiotherapy research international : the journal for researchers and clinicians in physical therapy, 21(4), 210–227https://doi.org/10.1088/1741-2560/13/2/026013 [2] EEG (electroencephalogram) - Mayo Clinic. (2022, May 11). https://www.mayoclinic.org/tests-procedures/eeg/about/pac-20393875https://doi.org/10.1088/1741-2560/13/2/026013 [3] Atilla Kilicarslan et al. (2016). A robust adaptive denoising framework for real-time artifact removal in scalp EEG measurements. Journal of Neural Engineering, 13(2), 026013. https://doi.org/10.1088/1741-2560/13/2/026013 [4] Pereira, Rui & Couto, Marco & Ribeiro, Francisco & Rua, Rui & Cunha, Jácome & Fernandes, João & Saraiva, João. (2017). Energy efficiency across programming languages: how do energy, time, and memory relate?. 256-267. 10.1145/3136014.3136031.