page 7 of 12 www.brainproducts.com The first text box works in the same way in both cases. You can enter all the code required to process your EEG data, set properties and create new markers in the “Code Executed on Creation of Node” text box. You need to know the fundamentals of MATLAB® to gain full benefit from this tool. If you are not already an expert MATLAB® user, it will help if you go through the MATLAB® “Getting started” manual. First example – rearranging the channels In order to check that all ocular artifacts have been removed from the data after ocular correction, you generally compare the frontal channels with the ocular channels. In other words, you compare HEOG and VEOG with the channels FP1, FPZ and FP2. Unfortunately, in the standard view the FP1, FPZ and FP2 channels are generally right at the top and the VEOG und HEOG channels are at the bottom of the list. It would be nice to have these channels next to each other in order to compare them. For a data set with 32 channels, the next two lines of code put the last two channels in the first two positions, followed by the remaining channels. The first line rearranges the lines of the data matrix (i.e. the data), while the second line rearranges the descriptions of the channels accordingly (i.e. the names and coordinates). Analyzer 2 in practice MATLAB® transform fundamentals When you open the MATLAB® transform, you see only a single, uncluttered dialog box. But don’t get misled by this Spartan look: It’s a very powerful tool that combines the advantages of two different worlds and allows you to access numerous functions. Approaching the challenge slowly, we’ll begin with an intro- duction to the dialog box. Then you’ll learn some useful little tricks, and we’ll finish off with a little MATLAB® code that allows you to explore your data with a t-test. Clearly, most of what we are doing here we can also do in Analyzer 2.0. But the point of this is to provide a demonstration of the Matlab interface. To display the transform dialog box, choose Transformations > Others > Matlab. The dialog box is shown in figure 1. The first thing you have to do is to decide whether you want to have the calculation done on request or when a node is created (by selecting the corresponding radio button). After we have gone through the examples below, it will be clear to you which option you need to choose when. Two of the check boxes shown are only required if you want to work in EEGLAB or with EEGLAB functions. You can either export your EEG to MATLAB® in EEGLAB format or you can additionally have EEGLAB start up immediately after the data is transferred by clicking the second option as well. The other three check boxes allow you to adjust performance. They are of course described in the manual. If you select the “Calculate Data on Request” radio button, a second text box appears in the dialog box. In this text box you can enter the MATLAB® code to be processed on request. The dialog box will be as shown in figure 2. by Patrick Britz, Sales Figure 1 Figure 2 EEGData = EEGData(:,[31 32 1:30]); Properties.Channels = Properties.Channels(:,[31 32 1:30]); Brain Products Press Release December 2008
3
Embed
Analyzer 2 in practice MATLAB® transform fundamentals · 2019-02-18 · Analyzer 2 in practice MATLAB® transform fundamentals When you open the MATLAB® transform, you see only
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
page 7 of 12www.brainproducts.com
The first text box works in the same way in both cases. You
can enter all the code required to process your EEG data, set properties
and create new markers in the “Code Executed on Creation of Node”
text box.
You need to know the fundamentals of MATLAB® to gain full
benefit from this tool. If you are not already an expert MATLAB®
user, it will help if you go through the MATLAB® “Getting
started” manual.
First example – rearranging the channelsIn order to check that all ocular artifacts have been removed
from the data after ocular correction, you generally compare
the frontal channels with the ocular channels. In other words,
you compare HEOG and VEOG with the channels FP1, FPZ and
FP2. Unfortunately, in the standard view the FP1, FPZ and FP2
channels are generally right at the top and the VEOG und HEOG
channels are at the bottom of the list. It would be nice to have these
channels next to each other in order to compare them.
For a data set with 32 channels, the next two lines of code put the
last two channels in the first two positions, followed by the remaining
channels. The first line rearranges the lines of the data matrix (i.e.
the data), while the second line rearranges the descriptions of the
channels accordingly (i.e. the names and coordinates).
Analyzer 2 in practice
MATLAB® transform fundamentals
When you open the MATLAB® transform, you see only a single,
uncluttered dialog box. But don’t get misled by this Spartan look:
It’s a very powerful tool that combines the advantages of two
different worlds and allows you to access numerous functions.
Approaching the challenge slowly, we’ll begin with an intro-
duction to the dialog box. Then you’ll learn some useful little
tricks, and we’ll finish off with a little MATLAB® code that allows
you to explore your data with a t-test. Clearly, most of what we
are doing here we can also do in Analyzer 2.0. But the point of
this is to provide a demonstration of the Matlab interface.
To display the transform dialog box, choose Transformations >
Others > Matlab. The dialog box is shown in figure 1. The first
thing you have to do is to decide whether you want to have
the calculation done on request or when a node is created (by
selecting the corresponding radio button). After we have gone
through the examples below, it will be clear to you which option
you need to choose when. Two of the check boxes shown are only
required if you want to work in EEGLAB or with EEGLAB functions.
You can either export your EEG to MATLAB® in EEGLAB format
or you can additionally have EEGLAB start up immediately after
the data is transferred by clicking the second option as well. The
other three check boxes allow you to adjust performance. They
are of course described in the manual.
If you select the “Calculate Data on Request” radio button, a
second text box appears in the dialog box. In this text box you
can enter the MATLAB® code to be processed on request.
number of data points per average-value node. In our case,
there are 250 data points (a second of data at 250 Hz).
We can now take a look at this matrix in Matlab. We do this
either by clicking it and then clicking “plot” or by means of the
following line of code:
All of the averages are drawn one behind the other, as shown
in figure 4.
Clearly, this plot is not ideal, however, because it continues to
draw the channels from one average to the next.
It’s clear we need to put our data matrix into a useful form: in
other words, to turn our 2D matrix of 2500 by 32 into a 3D matrix
with 10 averages by 32 channels by 250 data points. The first
line of the code below rearranges the original matrix (myEEGfile)
column by column to form a new matrix (AllAvgs). As a result of
the column-based approach, however, the dimensions of the
matrix are no longer in the desired order. This is dealt with by
the second line of code, which shifts the second dimension
(averages) to first place, the third dimension (channels) to second
place and the first dimension (sampling points) to last place.
You can no longer display this 3D matrix by means of a 2D plot.
To display the first layer (i.e. the first average) of this new matrix,
you have to assign it to a new matrix. The “squeeze” command
reduces the emerging 3D matrix by a single dimension to form
a 2D matrix.
We can, of course, now do this for all of our 10 averages, but
it’s easier if we use the Matlab function „subplot“. This allows
us to arrange the various graphs (see figure 5). The following
code shows our 10 averages in two columns containing five lines
each:
Incidentally, if you change the code above from “(count,: ,:)” to “(:,count, :)”, you will see an overlay of all of the averages (in our case 10) for the first 10 channels. Moreover, if you use the line “imagesc(Avg);” instead of the line “plot (Avg…)”
above, you will get color-coded plots like the one in figure 3a.
Let’s turn our attention to the t-test nowTo make it easier to follow, I’ve divided it up into three steps,
but you can, of course, put everything in a single line. We
begin by arranging our two conditions in the two matrices
“Condition1” and “Condition2”. We then calculate a t-test of
the two matrices against each other. Matlab always calculates
the t-test across the first dimension of the matrices. That
means we don’t have to carry out any further rearrangement
here. The result of a t-test consists of two matrices in our case.
The first matrix (“h”) makes a statement about the acceptance
or rejection of the null hypothesis and contains only the
values zero and one. Zero means the null hypothesis is accepted,
and one means it is rejected. The second matrix (“pValues”)
contains the p-values for the t-test. The last line displays
the p-values for each channel and each point in time.
We have just calculated a t-test for each data point and each
channel. Admittedly, that was a lot of tests so let’s not get into
the subject of multiple testing just yet. Clearly, we are only
exploring our data here.
But it’s a great way to do it, isn’t it? And it’s possible to do it
even more elegantly than we’ve done it here. If you want, you
can put all of the code in a “.m” file and run it automatically
just like an Analyzer template. Alternatively, you can use
EEGLab functions to display your data (or p-values) in a more
EEG-like way.
Many thanks for reading this article. Until next time.