Using Brain-Computer Interfaces & EEG Signals to Classify Emotions | by Bonny Nichol | Jan, 2021


What are we able to be informed from brainwaves?

Image Credit:

An electroencephalogram (EEG) is a recording of the mind task measured by electrodes. EEG alerts had been first recorded in 1924 by Hans Berger², an implausible discovery that has lead to a space of analysis this is nonetheless being closely researched these days with numerous unknowns. The choice of EEG alerts is non-invasive and the electrodes are positioned at the scalp with gel or paste. The maximum commonplace use of EEG alerts for clinical causes come with Epilepsy analysis and sleep research. They are extensively utilized to uncover mind accidents, mind irritation, and strokes.

The dataset used to be created by Queen Mary University of London and will also be accessed at The dataset is open for public use and calls for signing a unlock shape.

The dataset is composed of:

32 Participants
40 Channels (The first 32 channels are EEG)
40 One-minute movies
Labels: Valence, Arousal, Dominance, Liking, Familiarity, Order
EEG Channel Names- ‘Fp1’, ‘AF3’, ‘F3’, ‘F7’, ‘FC5’, ‘FC1’, ‘C3’, ‘T7’, ‘CP5’, ‘CP1’, ‘P3’, ‘P7’, ‘PO3’, ‘O1’, ‘Oz’, ‘Pz’,’Fp2′, ‘AF4’, ‘Fz’, ‘F4’, ‘F8’, ‘FC6’, ‘FC2’, ‘Cz’, ‘C4’, ‘T8’, ‘CP6’, ‘CP2’, ‘P4’, ‘P8’, ‘PO4’, ‘O2’

Although EEG alerts are mechanically used for clinical observe, this analysis is inquisitive about if and the way EEG alerts may well be used for extra subjective approaches, equivalent to human feelings and sentiment. By aligning the player’s surveys concerning the tune movies (subjective) in addition to the EEG information (goal) we will be able to start to perceive whether it is conceivable to expect feelings from EEG alerts.

The python library predominantly used on this analysis is MNE-Python¹, an open-source python package deal that analyses human neurophysiological information together with MEG, EEG, and different alerts.

Electrodes, that are small steel disks, are positioned strategically at the scalp in accordance to the 10/20 rule of placement. The placement of those electrodes are measured in accordance to fastened places at the matter’s head. Below we will be able to see the sensor places used for the Biosemi gadget used on this dataset’s experiment.

Sensor Locations on Head for Biosemi32 System (Image by Author)

The Biosemi gadget on this experiment is a 32-channel gadget this is utilized in analysis settings and now not for clinical utilization.
The even numbers refer to the precise aspect of the pinnacle and the unusual numbers refer to the left aspect. The naming conventions of the sensors will depend on the site of the sensor:

Raw, Unprocessed EEG Signals (Image by Author)

F — Frontal lobe
T — Temporal lobe
C — Central lobe
P — Parietal lobe
O — Occipital lobe

The objective of preprocessing alerts is to reinforce the signal-to-noise ratio in addition to detecting experimental results. This is completed with band-pass filtering (this passes frequencies inside a definite vary whilst rejecting frequences out of doors of that vary). Also all over preprocessing, useless channels are dropped and artifacts are got rid of.

Marking Bad Channels

It is necessary to mark dangerous channels, this is channels which are malfunctioning, unused, or now not appearing any sign, so as to exclude them from the research of the alerts. We can see within the first plot beneath that there’s a minimum of one dangerous channel. The error message tells us that the channel is GSR2. We will mark this as a nasty channel and redo the plot to see if we will be able to see the opposite channels higher. We additionally know from the unique dataset description that channels “Erg1” and “Erg2” also are now not used channels so we can mark them as dangerous as smartly. We can see within the 3rd plot beneath that the unused channels aren’t integrated anymore.

(Image by Author)

We additionally know there are different non-EEG channels (as an example, galvanic pores and skin reaction) within the dataset so we can exclude the ones as smartly since we gained’t be the usage of them within the fashions. Now that we have got known all the unused and non-EEG channels, we will be able to set the montage. This will give a location to the sensors and refer them to the gadget the information used to be accrued with (Biosemi32). In the overall plot above, we will be able to see best the EEG channels that experience colour associating the alerts with their sensor places.

Power Spectral Density Plot (Image by Author)

Filtering information via desired passband

Most helpful data within the brainwave will exist beneath 30hz. We can see on this energy spectral density plot that the frequency drops off someplace between 30-40hz in any case so we can cutoff at 30hz for the needs of our analysis.

Detecting Artifacts and Removing with ICA

It is necessary to visualize and apply the artifacts within the information sooner than deciding which way to make a selection for repairing the artifacts. There are 3 kinds of artifacts that disturb EEG information. These come with environmental (energy strains, doorways slamming, elevator noises, cellphones, air con, and many others), instrumentation (deficient scalp connection, electromagnetic interference), and organic artifacts (heartbeats, blinking, swallowing).

(Image by Author)

First we can take away the SSP (Signal Space Projection) projectors from the information. This is a matrix multiplication that reduces the rank of the information by projecting it to a decrease dimensional subspace.

It is necessary to locate the artifacts (ocular and heartbeats) so as to decide if they’re vital sufficient to want to be repaired and to additionally decide which instrument to use to restore them. We can be the usage of the Independent Component Analysis (ICA) which makes an attempt to decompose a multivariate sign into impartial non-Gaussian alerts.

Eye blink artifacts manifested around the other channels (Image by Author)

Once the alerts are processed, we’re in a position to determine the occasions throughout the alerts. Events are marked by a stimulus channel. For this dataset, the stimulus channel used to be known as “Status”. The Status channel has 7 tournament markers. These mark occasions equivalent to the beginning of the experiment, when the tune begins, when there’s a fixation display, the tip of the experiment,and many others. These tournament markers can slice the EEG sign to create epochs, that are particular time home windows which are extracted from the continual EEG sign. The first symbol beneath presentations all the tournament markers on this one pattern of knowledge. The 2d symbol is a small window of time with tournament markers overlaid on most sensible of the sign.

Plotted occasions in a single pattern of knowledge (Image by Author)
Plotted occasions overlaid with EEG information (Image by Author)

Rejected Epochs

While we’re looking for occasions, we’re in a position to carry out otherwise of rejecting information that indicates a watch blink (which as we have in mind is an artifact). The graph beneath may be very attention-grabbing as a result of we will be able to see that the sensors within the frontal lobes had the most important proportion of rejected information. This aligns with commonplace sense that the frontal lobes are closest to the eyes the place the blinks happen and due to this fact create the most powerful artifact.

Percentage of Rejected Epochs (Image by Author)

Several classifying fashions had been examined at the dataset together with KNN, Decision Tree Classifier, Random Forest Classifier, and Bagged Trees. A GridsearchCV used to be additionally carried out to hypertune the parameters.

Target label: Participant familiarity with video (Image by Author)

Unfortunately there are some disadvantages to EEG alerts. EEG alerts have deficient spatial answer (about 10cm2 from the scalp) leading to intense interpretation to perceive what spaces of the mind are activated by a specific reaction. As we will be able to additionally see from this analysis, EEG alerts also are tricky to procedure. Therefore, transferring ahead, a technique to reinforce the result of this analysis is additional processing and trying out of the alerts. In addition, we will be able to see in our gadget finding out fashions that we best experimented with “Familiarity” however may do a regression downside to deal with valence, arousal, and dominance.

Additionally, the KNN fashion carried out the most efficient to begin with of all the fashions however not one of the fashions carried out extremely smartly due to the small dimension of the dataset (1 player pattern). Because there are 32 contributors within the find out about, it might be attention-grabbing to interpret all the EEG alerts into a bigger gadget finding out fashion.


  1. A. Gramfort, M. Luessi, E. Larson, D. Engemann, D. Strohmeier, C. Brodbeck, R. Goj, M. Jas, T. Brooks, L. Parkkonen, M. Hämäläinen, MEG and EEG data analysis with MNE-Python,Frontiers in Neuroscience, Volume 7, 2013, ISSN 1662–453X, [DOI]
  2. Haas, L F (2003). “Hans Berger (1873–1941), Richard Caton (1842–1926), and electroencephalography”. Journal of Neurology, Neurosurgery & Psychiatry. 74(1): 9. doi:10.1136/jnnp.74.1.9. PMC 1738204. PMID 12486257.
  3. Ok.R. Scherer, “What are feelings? And how can they be measured”, Social Science Information,vol. 44, no. 4, pp. 695–729, 2005.
  4. S. Koelstra, C. Muehl, M. Soleymani, J.-S. Lee, A. Yazdani, T. Ebrahimi, T. Pun, A. Nijholt, I. Patras, “DEAP: A Database for Emotion Analysis the usage of Physiological Signals”, IEEE Transactions on Affective Computing, Special Issue on Naturalistic Affect Resources for System Building and Evaluation, in press


Please enter your comment!
Please enter your name here