.mat
-filesSome researchers were able to control a quadrocoptor with nothing but thoughts. Now we want to replicate this work.
To do this, first we need to measure brain activity. This can be done using EEG (electroencephalogram). A test participant wears a cap with embedded electrodes. The participant then repeatedly moves their left or right hand or no hand at all, while we measure the electric field with the electrodes. Luckily this data has already been recorded and can be downloaded here. We'll be using 'EEG_ParticipantB_30_09_2013.mat'.
Once we have downloaded the first data file, we want to:
First, let's have a look at the data file we downloaded. The file is a .mat-file. This is a special MATLAB file type that can be used to store multiple variables at once. To load the stored variables back into memory, type
load('data/EEG_ParticipantB_28_09_2013.mat');
If we have a look at our Workspace, we see that two new variables have been loaded: data_epoch_B and data_key_B.
The recorded data is stored in data_epoch_B
, the classification key is stored in data_key_B
.
Each column in data_epoch_B contains the recorded data of one trial, corresponding to one value in data_key_B (1 = left hand press, 2 = right hand press, 3 = no hand press). The first 100 values in each column are the recordings during 0.4 ms of one electrode, the second 100 values of the second electrode and so on.
We now want to have not one, but three arrays, one for each condition (1 = left hand press, 2 = right hand press, 3 = no hand press). MATLAB provides us with a handy way of obtaining all indexes for fields that meet a certain condition. This method is called logical indexing.
For example, we have recorded how many mice our cat caught each day for one week.
mice = [4 5 2 6 7 8 3];
Now if we want to know how often our cat has brought home 4 or more mice, we can check that by typing:
mice>=4
The response is a vector with ones wherever this condition is true.
ans = 1 1 0 1 1 1 0
And even look at which values it takes
vector(vector>=2)
We've now grouped the data in three groups, but in order to visualise it, we might want to compute the average of each group and each channel (we now have 100 values per channel.)
Now, we want to plot the data. We could go ahead and write our own plotting function, but for a (relatively) common task like plotting EEG data, we could instead have a look to see if someone has already written a function. A good place to look for code is MATLAB File Exchange. Other users write and upload code that can then be rated.
We've found the what we need to plot our EEG data, a function called 'BrainMap'. The code we downloaded needs some more data for configuration. Luckily all that data is provided in 'brain_data_for_BrainMap.mat'.
load('data/brain_data_for_BrainMap.mat');
BrainMap(neither_mean,x_full, y_full, mx, my);
Here are the images we should be seeing:
No hand squeeze:
Left hand squeeze:
Right had squeeze:
We can clearly see that the activity in the brain differs for the different activities we recorded. For trained people, this brain activity also differs if they just think about the action of squeezing a hand. Having a clear idea of these measurement values, we should be able to control a motor using nothing but brain measurements.