Improving Preprocessing Of EEG Data In One Line Of Code With CAR

A Beginner’s Guide to Brain-Computer Interfaces (part 6)

--

Now we know how to collect data from an EEG device, or retrieve data from the internet, we are off to step 2 of the BCI cycle: pre-processing!

In this blog post, we will look at using Common Average Referencing (CAR) to reduce the general noise in your EEG data. Both the theory as the implementation of CAR are not too difficult. Let’s start with the theory.

CAR theory

Regarding theory, CAR can be described as an simple spatial noise filter. CAR works by calculating the mean signal value from all EEG channels for each point in time, and then this value will be subtracted from the value of each EEG channel. Here, the goal is to reduce the general noise present in all channels, in order to improve the often weak specific signal component of the brain region under each individual EEG electrode. And so, individual signals (single-unit activity) will not be removed by CAR, unless the signal is so large as to dominate the average. CAR is a computationally simple technique, and therefore amenable to both on-chip and real-time applications. It has even by used as early as the 1950s!

This is basically all you have to know to use CAR! Now, we will implement it in our own project.

If you want to go more in depth in the theory of CAR, please read this paper by Ludwig and his colleagues from 2009, where more references are given, and CAR is mathematically justified.

CAR implementation

So, how does one use CAR in their BCI project? It’s simple. Written in Python, it only consists of the following line:

data -= data.mean()

Here, it is important to note that data must be in channels x samples DataFrame format. As EEG data is often presented with the electrode channels as columns, do not forget to transpose your data before.

For my own project, I applied CAR directly after some artifact reduction. However, some other studies use CAR after frequency (spectral) filtering. To be honest, I do not know if this makes a big difference.

And that’s all there is regarding the implementation!

So, what does CAR practically do to our data? Well, this is easily visible in figure 1 below, where 2 EEG channels of a total of 8 are presented of the same s. Using CAR, the general noise over all channels has been removed, and it can be seen that the signals fluctuate less. Next to this, actually some of the EEG peaks seem to be different after applying CAR, indicating that some peaks in the original signal may have been due to general noise.. Good to know!

Figure 1: A 2-second EEG segment of the channels Fz and C3, without or with CAR.

Results

For most BCI-projects, the end results, like classification accuracy, are the most important thing to consider. Let’s see if CAR can help us here. During my current work, I have experimented with CAR for a Deep Learning (DL) pipeline, and for a Riemannian Geometry (RG) pipeline (more details about these two pipelines will follow in later posts..). Below, some 3-class motor imagery (left arm, right arm, or relax) classification accuracy results are given for 3 subjects. Without going too much into the details, it can quickly be noted that for RG, CAR does not seem to improve performance, while for DL, performance does increase!

Figure 2: Classification results with and without CAR of a 3-class motor imagery BCI pipeline using Riemannian Geometry (RG) and Deep Learning (DL).

To conclude, it should be said that applying CAR will not always lead to better results, but it has the potential to do so for some cases… And so, CAR is for sure worth the effort of typing that one line of code to see if your results improve!

Please check out the publication page, where more practical BCI tutorials like this one will be posted in the future, and give me a follow to be notified for further posts!

--

--

Tim de Boer
A Beginner’s Guide to Brain-Computer Interfaces

Master graduate AI @VU Amsterdam. Currently learning and writing about building brain-computer interfaces. Support me: https://timdb877.medium.com/membership