Design of an EEG Acquisition System for Embedded Edge Computing

A R T I C L E I N F O A B S T R A C T Article history: Received: 17 April, 2020 Accepted: 17 June, 2020 Online: 12 July, 2020 The human brain is one of the most complex machines on the planet. Being the only method to get real-time data with high temporal resolution from the brain makes EEG a highly sought upon signal in the neurological and psychiatric domain. However, recent developments in this field have made EEG more than just a tool for medical professionals. The decreasing size and increasing complexity of EEG acquisition systems have brought it out of the lab and into the field where it is used for varied applications like neurofeedback, person recognition and other recreational activities. Amalgamation of the EEG signal with new developing standards of Industry 4.0 to control basic IOT devices using edge computing techniques marks the next step in the design and development our low-cost yet robust Brain Computer Interface (BCI); which is just one of the many applications that a versatile and well-built EEG acquisition system can be used for.


Introduction
What makes the human brain so complex is not just the 100 billion neurons that it is constituted of but also the 100 trillion plus synapses or the unique ways in which those neurons connect and communicate with each other. Even with more than 7.5 billion people on the planet, no two brains are alike. Therefore, designing a unified device that can capture the diverse Electroencephalogram (EEG) signals emanating from different brains is a challenging task. EEG signals can be processed to extract the characteristic patterns of the brain to study its spatio-temporal characteristics.
Though other methods of measuring brain activity like Magnetic Resonance Imaging (MRI) and Functional Magnetic Resonance Imaging (fMRI) have more spatial resolution yet, they lack temporal resolution and are often more costly to setup and operate. EEG on the other hand offers better temporal resolution and is a cost-effective solution which can directly measure brain activity. EEG can approximate spatial activity with the use of greater number of electrodes placed on the scalp, providing better resolution and thus, making it a scalable choice.
A low cost yet robust design of an EEG acquisition system was presented at the IEEE International Symposium on Smart Electronic Systems (iSES) (Formerly iNiS), 2019 [1]. Though the design was primarily focused on reduction of cost of manufacturing so that the system becomes affordable, yet there were many limitations of the design. We studied the base design and propose a refined design which will overcome the followings drawbacks of the initial design: a) Overcome the limitations of low sampling rate b) To perform filtering and feature extraction from acquired EEG signal on the board itself c) To reduce and eliminate the noise during the EEG signal acquisition process by reducing wires in the system d) Better processing mechanism to extract and interpret the EEG data acquired, in real-time The whole system has now been fabricated on a Printed Circuit Board (PCB) and the primary mode of communication between the acquisition system and the host computer is now wireless to minimize artefacts introduced due to wire movements and other Electromagnetic Interference (EMI) / Electromagnetic Compatibility (EMC) interference. The detailed design update is enumerated in the system design section.
The next section discusses current research trend in the field of BCI (Brain Computer Interface) and HMI (Human Machine Interface) using EEG, followed by the Problem Definition. Next, we briefly look at the testing results from our initial design and highlight its shortcomings. We then move on to introduce the updated block diagram and directly compare the initial and the updated components. This serves the double purpose of introducing the initial design while highlighting the updates in the improved model. We next discuss the results obtained during testing of the improved EEG acquisition system and finally, we illustrate one of the many applications of our system -which is to automatically control IoT devices such as the television, lights, wheel chair and fan depending upon the state of the subject e.g. active, semi active, asleep in real time.

Background
Since the first experiments of electroencephalography on humans in 1929, the electroencephalogram (EEG) of the human brain has been used mainly to evaluate neurological disorders in the clinical environment and to investigate brain functions in the laboratory. An idea that brain activity could be used as a communication channel between the subject and an IoT device has gradually emerged [2][3][4][5][6]. The possibility of recognizing a single message or command, considering the complexity, distortion, and variability of brain signals appeared to be extremely remote. Yet EEG demonstrates direct correlations with user intentions, thereby enabling a direct brain-computer communication channel.
Brain-Computer Interface (BCI) technology, as it is known, is a communication channel that enables users to control devices and applications without the use of muscles. The development of cognitive neuroscience field has been instigated by recent advances in brain imaging technologies such as electroencephalography, magneto encephalography and functional magnetic resonance imaging. The first BCI prototype was created by Dr. Vidal in 1973. This system was intended to be used as a promising communication channel for persons with severe disabilities, such as paralysis, Amyotrophic Lateral Sclerosis (ALS), stroke or cerebral paralysis.
Since then BCI research has been successfully used not only for helping the disabled, but also as being an additional data input channel for healthy people. It can be exploited as an extra channel in game control, augmented reality applications, household device control, fatigue and stress monitoring and other applications. BCI design represents a new frontier in science and technology that requires multidisciplinary skills from fields such as neuroscience, engineering, computer science, psychology and clinical rehabilitation.

Review of EEG for BCI Applications
Controlling real-world objects with nothing more than our mind is no longer science fiction. Jaime, et al [7] have proved the same by demonstrating the fact that the steering of a tractor by use of surface EOG and EEG signals is just as accurate as manual guidance or GPS guidance with a minimal variation in response time.
Furthermore, Yuan, et al [8] have conclusively established the feasibility of using a consumer-level EEG headset to realize an online steady-state visual-evoked potential (SSVEP)-based BCI during human walking using a 14 channel commercially available EEG headset to implement a four-target online SSVEP decoding system which has in-turn helped bridge the gap between laboratory BCI demonstrations and real-life application of consumer-level EEG headsets.
Starting with some simple applications, Gerardo Rosas-Cholula, et al [9] have successfully controlled a mouse pointer using a commercially available EEG headset. They have implemented Empirical Mode Decomposition (EMD) to reduce noise and simulated mouse clicks with the help of blinks. Next we come across articles [10][11][12][13][14] that focus on controlling robotic arms or wheelchairs for amputees and paraplegics using different computational techniques for identification and classification of various signals in the EEG like Event-related Potential (ERP), P300, Mu rhythm, etc. and demonstrate the accuracy and ease with which these EEG based BCIs can control simple devices.
Taking this use of EEG one step forward multiple articles [15][16][17][18][19][20][21] discuss integrating EEG with the Internet of Things (IOT) to control different devices in a smart home using protocols like Message Queue Telemetry Transport (MQTT) and Extensible Messaging and Presence Protocol (XMPP). These interfaces can further be used to improve healthcare and the general living standard of differently-abled people and in-turn make everyone's life easier. However, there is much work still to be done in this domain considering the new threats that continuously emerge in the realm of cyber security.
Researchers have worked upon and built multiple EEG acquisition systems [22][23][24][25][26][27][28] but have not used these systems to demonstrate an application. Others have demonstrated the use of EEG for various applications be it in terms of person recognition [29][30][31][32] or in the field of healthcare [33][34][35][36][37][38] or the ones mentioned above, but they have either used commercially available EEG acquisition systems or pre-existing datasets. With our research we aim to bridge this gap by not only building a robust yet low-cost EEG acquisition system but also using the same system to control IoT devices in real-time, and in doing so we not only design the hardware to acquire EEG data but also develop the software for data representation and signal processing which showcase the edge computing capabilities of our device.

Problem Definition (Limitations of Existing Designs of EEG Acquisition Systems)
The research trends towards problems addressed in the EEG and BCI/HMI domain [1] show us that only 3 out of 30 publications focus on data acquisition and 5 out of 30 discuss EEG signal processing. However, this can paint a slightly misleading picture. To fully understand the need to design and develop a lowcost yet robust EEG acquisition system capable of edge processing we need to look at the research trends towards adaptation of technology where only 2 out of 21 publications [1] use custombuilt EEG acquisition systems, while others rely on expensive alternatives available in the market or pre-existing datasets [1].
The above gaps in research are the major motivation behind this research, but the problems encountered while designing a robust yet low-cost EEG acquisition system are two-fold: Domain specific problems are: - • To ensure that the pickup, amplification and transmission of EEG signal is done while introducing minimum noise in the signal.
• To ensure that the sampling rate of the acquisition system is at lest 2.5 times the highest frequency of input EEG signal, but at the same time not too high so as to avoid the problem of oversampling.
• To ensure that the resolution of the system is enough to register minute changes in the peak-to-peak amplitude and the frequency of the EEG signal.
Problems specific to the design of our acquisition system are: • To build a Graphical User Interface (GUI) that accurately represents the EEG signal picked up by the acquisition system in real-time.
• To perform real-time processing and feature extraction from EEG signal in order to build a device capable of edge processing.

System Design
After careful examination of EEG signals and other medical grade systems available in the market, we have arrived at the following design-constraints to design our EEG acquisition system.

Design constraints:
• EEG voltage range: 10 V to 100 V • Useable EEG frequency range: 0.3 Hz to 60 Hz • Max variation of input signal per unit time: 50V • Sampling Rate: 256 to 1k SPS The subsequent sections talk about the step by step design of each component in the acquisition system. Beginning with an introduction to the initial system design, its results and drawbacks.

Initial Block Diagram, Testing and Observations
For the initial design [1] as shown in Figure 1, gold plated, cup shaped electrodes (placed on the scalp using the international 10-20 system) were connected to the instrumentation amplifiers (INA333) which were then directly connected to the analog input pins of Arduino Mega. We only used 3 input channels; two for data and one for reference. Arduino IDE however, is neither capable of plotting data from multiple channels nor is it capable of performing complex algorithms on the acquired data. Therefore, to overcome the abovementioned drawbacks, we interfaced Arduino with MATLAB, which is used to plot real time frequency domain and time domain spectrum of the incoming EEG signal with further possibility of manipulating data and representing it in different formats. Figure 2 shows the acquired EEG data from a single channel connected to analog port A0 of the Arduino at a baud rate of 9600. Subplot 1 shows the real time RAW EEG signal amplified 101 times whereas subplot 2 shows the real time Frequency plot (FFT).
A brief description of output from the initial design of our EEG acquisition system is as follows: Once the data acquisition is complete, MATLAB then computes the power spectral density of the acquired EEG signal as observed in Figure 3. Major peaks seen around 5, 10, 25 and 32 Hz correspond to Alpha, Beta and Theta waves which contribute majorly to awake EEG patterns.  Figure 4 shows the comparison of saccade, fix and blink data. Subplot 1 shows the data from our system, while Subplot 2 shows the data from the medical grade system. Similar for Subplot 3 and 4. It is evident from the above figure that our proposed system captures the correct data as all peaks match between both signals. The drawback here is the low sampling rate because of which the reconstructed signal does not have as much detail as is required for complex analysisthis can be seen when comparing Subplot 3 and 4. The maximum rate at which the data is captured by our initial system is about 5 to 20 Hz [1].

Drawbacks of the Initial System
Due to the low sampling rates which are in-turn caused by the hardware limitations of the 10-bit ADC on Arduino Mega2560, we were only able to capture data at a maximum rate of 20 Hz. But the Practical Nyquist Sampling Theorem states that to properly capture and reconstruct incoming signal, the sampling frequency of the acquisition system must be at-least 2.5 times the maximum frequency component of the incoming signal, therefore to capture brain waves with a maximum useable frequency component of 60 Hz, the acquisition system must have a sampling rate of 150 Hz or higher. To overcome this issue of lower sampling rate, we propose the use of an ADC (ADS1299) introduced after the instrumentation amplifier and before the microcontroller as shown in the block diagram of our initial design ( Figure 1).
The microcontroller Arduino Mega does not have the inherent capability to transmit data wirelessly meaning more noise is introduced in the signal due to the movement of the wires. This is overcome by replacing Arduino with NodeMCU that has an inbuilt wireless transmitter.
Moreover, the use of MATLAB for signal processing and representation poses its own set of limitations including the need for a MATLAB license to use our system, hence the same is replaced by a GUI built using open-source code in Python.

Improved Block Diagram
The initial components of the system like the Electrodes (goldplated, cup shaped, copper, non-invasive), Electrode Placement (international 10-20 system), Electrode Cap and the Instrumentation Amplifier (INA333) remain the same and are carried over from the initial design ( Figure 1).  Figure 5 shows the block diagram of the updated hardware with an Analog to Digital Converter introduced in the system after the instrumentation amplifier to handle the conversion of analog data to digital domain at a much faster rate. The ADS1299 connects to the NodeMCU using SPI, which then transmits the data wirelessly to the host computer that runs a Python GUI for data processing, filtration and signal representation.

Analog to Digital Converter (ADC)
The ADC chosen for our application is the TI analog front-end chip ADS1299, which is specifically designed to capture biopotential signals like EEG, ECG, EOG, EMG, among others. The chip has a 24-bit Sigma-Delta based architecture, with a maximum data rate of 16 kSPS. It boasts of a -110 dB CMRR and a Signal to Noise Ratio of 121 dB. It is a low power, low noise, high precision chip. It can further be multiplexed to use more channels and is available in 4, 6 and 8 channel alternatives.
The chip communicates with the microcontroller using SPI (Serial Programming Interface) which can be used to configure the chip to read data in Continuous mode or Single Shot mode and also to read the output data from the inbuilt registers.

Microcontroller
Arduino Mega from the initial design has now been replaced with ESP 8266 NodeMCU as the choice of microcontroller for our system. The NodeMCU has a L106 32-bit RISC microprocessor running at 80 MHz. It supports 32 KB instruction RAM and 80 KB user-data RAM. It comes with integrated IEEE 802.11 b/g/n Wi-Fi connectivity and matching network WEP or WPA/WPA2 authentication. It has 16 GPIO pins and also supports SPI communicationall of which is ideal for our application. The NodeMCU does not only have more GPIO pins, better clock speed of the processor and more flash and SRAM than the Arduino, but also operates at a lower 3.3 V which translates to less power consumption for battery powered wireless use of our EEG acquisition system.

Initial Observations with ADS1299
To set up and test the SPI connection between ADS1299 and NodeMCU, ADS is soldered on an adaptor ( Figure 6) and the connections are made on a bread-board ( Figure 7). It must be noted that for this initial testing, ADS is connected to Arduino. Once the connections are verified, the final PCB is interfaced with NodeMCU.   After running multiple tests Arduino Mega is able to read the correct Device ID (Figure 8). The device ID reads 1111 1100 where the last four bits correspond to the 4 channel ADS1299 chip. This means that the SPI communication was successful, but due to the inherent noise of the system which is set-up on a bread-board, the output is not consistent. Therefore, the next logical step is to design a PCB to acquire the signals. This is carried out in the next subsection.

Design for PCB Fabrication
The PCB is designed using an open-source software called PCB Artist. The schematic for the design is shown in Figure 10. The design comprises of a power supply unit which steps down the incoming 220V AC to 5V and 3.3V DC. Both the 5V and 3.3V lines have been taken out as well to provide power to the microcontroller NodeMCU and for other purposes. Internally, the ADC has multiple pins that require 5V and 3.3V to power up the Analog and Digital circuits in the chip respectively.
For the input electrodes, each channel is first passed through the non-inverting pin of the instrumentation amplifier INA333 for first stage amplification. The signal is then passed through an RC high-pass filter to remove DC offsets and fed to the ADC via referential montage with one reference electrode and an internal bias. The example Schematic using the ADS1299 in an EEG Data Acquisition Application in Referential Montage from its datasheet is shown in Figure 9. The advantage of using the referential montage is that all electrodes are referenced to a single reference electrode instead of being referenced to each-other as is the case with sequential montage. The final fabricated, two-layer PCB is shown in Figure 11 and

Output from PCB
Once the PCB is fabricated, it is connected to the microcontroller using SPI interface. The ADS1299 is then configured to transmit continuous data with 24-bit resolution at 250 SPS. The register values corresponding to the above configuration are shown in Figure 13 with the correct device ID. Even though the chip is capable of acquiring data at speeds up to 16 kSPS, we have not used these higher sampling rates to avoid the problem of oversampling.  Figure 14 shows the filtered data acquired from the EEG sensors connected to the input channels of ADS1299. The RAW data is in Hexadecimal format. This is converted to Decimal format and then scaled down to convert into Volts. Since we have used a 4 channel ADS1299 chip, the data format as observed in the output is <start bit> <channel 1> <channel 2> <channel 3> <channel 4>. The last 4 bits in each row are of no use to us because those channels don't exist on an ADS1299-4PAG chip.

Design
The code for the GUI is burnt on the NodeMCU using the Arduino IDE after installing relevant drivers. First off, this code checks the device ID coming from the attached ADS1299 chip and if it is correct, modifies the register values to acquire data. In our case the ADS is set to acquire data at 250 SPS in continuous mode. It then creates the GUI window as shown in Figure 15. This GUI window has options to toggle the 50 Hz filter, Low Pass filter and the band pass filter all of which are deployed in the python code using digital filtering. No hardware filters are deployed because they clip waveforms; due to the cutoff from opamp power supply and induce more noise and drift in the system.

Output
A simple test to capture EEG data is run on the subject for 60 seconds. The real-time time domain plot and the frequency plot are observed in Figure 16.
The GUI has a continuous rolling time domain plot with a 4 second window (customizable) and frequency domain plot that accumulates frequency responses over the course of time that the experiment is run.
As observed in Figure 16, our acquisition system performs filtering in real-time on the PCB itself with the use of hardware high-pass filter implemented using the RC filter and low-pass & notch filter implemented in software in the code burned on to the microcontroller. Furthermore, the splitting of acquired EEG signal into its component waves based on their frequency ranges and feature classification & identification in different frequency ranges is also implemented on the microcontroller. The major peaks observed in the frequency domain plot of Figure 16 are in the range of 7 to 30 Hz which comprise mainly of Alpha (7-12 Hz) and Beta (12-30 Hz) waves that constitute a major portion of awake EEG.

Use of EEG for IOT application
Now that we have successfully designed and built a plug and play device for EEG acquisition and a GUI for data representation it is time to use it for an IOT application to highlight its edge computing capabilities.
We know in hospitals; the staff has to keep an eye on patients that cannot move to ensure that they are comfortable. The lights are off when they sleep and the fan is turned on as and when needed. Keeping this equipment running all the time does not only cause discomfort to the patient but also a higher electricity bill and waste of energy.
To tackle this issue, we use our EEG acquisition system to monitor the Alpha and Beta waves of the patient. We know that in awake EEG the Alpha waves' peak-to-peak amplitude is low when our eyes are open and high when our eyes are closed. This variation can be used to turn off lights in a room when the patient closes his/her eyes to sleep. Similar interactions are observed in the Beta waves when an individual moves or even thinks of moving their limbs to perform a certain function or action. These variations in frequency and peak-to-peak amplitude can be monitored and with the right threshold can be used to turn on or off a fan.

Block Diagram
In Figure 17 our acquisition system is now represented as a black-box which wirelessly transmits data to the host computer where the GUI displays EEG waves in both time and frequency domain in real-time. Once the data is received by the GUI, it is transmitted to MATLAB using serial communication. MATLAB checks the peak-to-peak amplitude of the incoming signal and matches it against a set threshold in real-time. Once the threshold is met; in case of Alpha waves the peak-to-peak amplitude crosses the threshold, the program sends a command to Arduino Mega which in-turn transmits it wirelessly using an IR module to actuate or control the final control element which in this case are the lights.

Algorithm Work-flow
As shown in Figure 18 the incoming EEG data from the Python GUI is serially transmitted to MATLAB where an algorithm continuously scans this data and based upon the initial value of the light (on or off) compares it with the upper (light on) or lower (light off) threshold. When the EEG peak-to-peak amplitude crosses the respective threshold, the Arduino sends a command wirelessly to the actuator to change the state of the light.
A similar algorithm is applied to control the fan, however in that case, changes in a combination of frequency and amplitude; in the Beta range of frequency (12)(13)(14)(15)(16)(17)(18)(19)(20)(21)(22)(23)(24)(25)(26)(27)(28)(29)(30), meeting the threshold result in the change of state of the fan. Based on further analysis of the EEG signal in various frequency ranges, multiple such IOT devices can be controlled. However, for such an application the processing module will have to apply AI, machine learning and deep learning algorithms to improve efficiency and the user will also have to be trained enough to concentrate in certain ways in order to control different objects. Figure 19 shows the output plotted from channels F1 and F2. The x-axis is time and y-axis is amplitude in milli-volts. The experiment in this case lasted for 20 seconds, where the subject's eyes were open for the first 10 seconds and then closed for the next 10 seconds. As observed in the figure, the EEG peak-to-peak variation is less when the subject's eyes were open except for a few spikes which correspond to blinks. The variation in peak-to-peak voltage increases dramatically half way through the experiment when the subject's eyes were closed. This corresponds to the increase in Alpha Wave activity in Awake EEG when our eyes are closed.

Results and Discussion
At the 12 second mark in the experiment when the subject's eyes were closed, the lights turned off after detection of increase in Alpha wave activity at the 10 second mark. The 2 second delay is introduced to reduce the chance of false positives.
The above experiment, quite simply demonstrates the accuracy of the data coming from our EEG acquisition system and its ability to control an IOT device (the lights) precisely in real-time. It is generally observed that the filtering of noise from the EEG signal is done post its collection. Same goes for the removal of artifacts from the EEG signal. Also, the analysis of the signal such as selection of features, classification and training of the classifier is carried out after the data is acquired and stored in a secondary device making the entire flow of denoising, analysis and classification of EEG a delayed process. Figure 19: Plotted output from serial data communicated to MATLAB However, our recommended design can be used to remove the noise in the EEG acquisition system and detect the features from the signal at the time of the acquisition in the device itself. Therefore, moving the denoising of the signal and classification in the EEG acquisition system to a real time system (Edge computing). Table 1 shows a comparison of our EEG acquisition system with other commercially available systems. The cost of our EEG acquisition system is much less compared to other commercially available EEG acquisition systems because of the fact that we have stripped down the design to a bare minimum and have only retained the most essential components that make it work efficiently and effortlessly. It must be noted that the cost mentioned for our system is applicable when single parts were ordered, the cost will further come down by about 15-20% when ordering parts and fabricating PCBs in bulk.
For our particular application we have used the ADS1299 -4PAG chip that has 4 input EEG channels and one reference channel. For other applications that require more input channels, more ADS1299 chips can be daisy-chained to achieve a 16, 32 or even a 64 channel EEG acquisition system.  Figure 20 shows how two ADS1299 chips can be daisychained to achieve up-to 64 input channels. Furthermore, Table 2 shows a broad specification comparison of our EEG acquisition system with others available in the market. The performance metrics considered are sampling rate, bandwidth, number of EEG acquisition channels, mode of transmission between the acquisition system and the host computer, placement of reference electrodes and the medium of conduction used between the electrode and the scalp. It is worth mentioning that all devices considered, use non-invasive electrodes for data acquisition. A direct comparison of data is also shown in Figure 4.
As evident in table 2, our EEG acquisition system is not only the most cost effective, but also happens to be superior when comparing hardware specifications with those of other commercially available products. The use of Wi-Fi for wireless transmission gives our system the maximum range of communication. Our system also gives the user the ability to choose the number of channels (by daisy-chaining ADS1299, ADS1299-4PAG and ADS1299-6PAG chips), bandwidth (by manipulating the cut-off frequency of high-pass and low-pass filters) and sampling rate (by changing the register value on ADS1299 to be as high as 16kSPS). None of these are offered by any other product in the market right now. (configurable) 100 4,6,8 (can be daisychained up to 64) Wi-Fi Earlobe Gel

Conclusion
From the above design and application, the followings can be concluded: • The proposed system captures accurate EEG signal despite the commercially available off the shelf electronic components used in designing the overall system -making it a low-cost yet robust instrument for capturing EEG data. • In order to improve the robustness of the signal captured the ADC with the instrumentation amplifier is soldered on the same board with the microcontroller, resulting in a single smaller unit, making the overall device more portable. • To increase the number of EEG signal channels to be captured through the proposed system more ADS1299 chips must be daisy-chained, this will further make the system modular and robust, where more input channels can be added on demand based on the needs of the user.
Further research can be carried out to compare the power consumption v/s performance of various components like the instrumentation amplifier, ADC and microcontroller to design a truly power efficient, battery powered EEG acquisition system capable of collecting data over long periods of time. The reason for moving from an AC powered device to a battery powered one is to get rid of the noise at 50 Hz and its harmonics.
On the software front, the python code can be improved to display more than one EEG channel at a time. Further computational capabilities and the ability to connect with more than one device at a time can be added to completely eliminate the use of MATLAB and finally, the software must also have the ability to export recorded data in popular EEG formats like European Data Format (EDF), CSV, etc. for further analysis and storage.