MATLAB: Analyse EEG signal with FieldTrip

So we want to analyse brainwaves that we obtain from the EEG with MATLAB, how can we do this?

There is a toolbox for MATLAB called FieldTrip that is designed for MEG and EEG. It has been developed at the Centre for Cognitive Neuroimaging of the Donders Institute for Brain, Cognition and Behaviour in Nijmegen. The software includes algorithms for simple and advanced analysis of MEG and EEG data, such as time-frequency analysis, source reconstruction using dipoles, distributed sources and beamformers and non-parametric statistical testing. It supports the data formats of all major MEG systems and of the most popular EEG systems, new formats can be added easily. FieldTrip contains high-level functions that you can use to construct your own analysis protocols in MATLAB. Furthermore, it easily allows developers to incorporate low-level algorithms for new analysis methods.

Our goal is to develop systems which completely paralysed people (such as late-stage suffers of Amyotropic Lateral Sclerosis, ALS) could use to communicate. We are focussing on the brain, this means we can’t use muscles, peripheral nerves and machine artefacts. The problem is that these sources generate much stronger signals than the brain, thus we must remove them to be sure our BCI has a B in it.

To do this these possible artefacts need to be recorded, detected, rejected from the corrupted data and removed whilst leaving the data intact. That are a bunch of things that need to be done to get a clean signal and some of these steps can be very hard, especially detecting the artefacts en removing them.

Because datasets are usually very large it would be easy to have automatic artefact rejection, but this is very hard. The human eye is very good at noticing patterns, but to program this in software is difficult. Some artefacts that can be seen in data are eye movement (a), eye blink (b) and muscle tension (c). It could also be that a channel is bad or the baseline is drifted in time.

EEG data is very high dimensional (e.g. 64 electrodes * 3000 samples * 600 trials), this makes it hard to see what’s going on, therefore FieldTrip gives us some easy visualisation options. There are different ways to view BCI data in FieldTrip, but the most common are the multi channel view and the topoplot (d). FieldTrip can average over channels or samples, to make a more interesting averaged plot. Still to detect the artefacts we need to see all samples manually to make the data clean, with this amount of data it will be a never ending job.

Fortunately some of these artefacts have a particular shape, this shape can be used as a template to detect other artefacts that are alike. We can automate this and it is called Template Matching Detection. We can make our own template by detecting some artefacts by eye and average these shapes to one shape, this new shape can be used as a template. You can also separately record these artefacts, like record a blinking eye a couple of times. This saves time of searching for the artefacts in the data. There are more ways to detect the artefacts and even more advanced ones than described here.

After detection there are two things that can be done with this “infected” data, either throw the data away or attempt to clean the artefacts from the data. In a nutshell it will look like a simple subtraction, subtract the clean (recorded) eye blink from the data and the other data will remain intact.

There can be software written for this artefact detection and removal, but it will always be good to do some routine manual checks. After this artefact removal the data is clean enough to move on to the next step: classification and eventually play Brains on Fire!

Thanks to Jason Farquhar for some information on this one!

After detection there are two things that can be done with this “infected” data, either throw the data away or attempt to clean the artefacts from the data. In a nutshell it will look like a simple subtraction, just subtract the clean (recorded) eye blink from the data and the other data will remain.

There can be software written for this artefact detection and removal, this will a lot of work, but it will always be good to do some routine manual checks. After this artefact removal, the data is clean enough to move on to the next step: classification, and eventually play Brains on Fire!

Thanks to Jason Farquhar for some information on this one!

About these ads

3 Responses to “MATLAB: Analyse EEG signal with FieldTrip”

  1. No shit Sherlock!

  2. [...] on Fire Play Guitar Hero using your Brain « MATLAB: Analyse EEG signal with FieldTrip BCI “Fun App”: Star Wars The Force Trainer January 5, 2010 So while my [...]

  3. Thanks for mentioning FieldTrip in relation to BCI research. Did you know that you can also use it for realtime analysis? We have implemented a method for buffering the data stream which facilitates real-time analysis in MATLAB. Check it out at http://fieldtrip.fcdonders.nl/development/realtime

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: