Information

Getting started with EEG data

Getting started with EEG data

I want to get started with getting signals from EEG and learning on how I can read data. I have some programming skills, so designing a database and manipulating data with ruby (python seems also cool, but never worked with) wouldn't be a problem, but I don't know where to start.

I'm interested in Neuromarketing because I'm working in advertising, but health is in my heart.

So can anyone please send me some books on what data I can get from EEG (theory) and what hardware should be good to use? Also books on how I can easily develop and calculate the data (emotiv sounds nice but not much electrodes and may not be working well, however for that money maybe good to begin with).

So something like getting started with EEG… Like with programming my first "Hello world" :)

UPDATE: Bought EPOC EEG Research edition :) And there I can even choose, I think I will go with ruby then :) But still need some very basic book on how to get long with all that data, I had suggestion on Introduction to Event Related Potential Technique and is there some easier to learn video tutorial or book… real basics :)


Steven J. Luck's "An Introduction to the Event-Related Potential Technique" is a great beginner's book on EEG. It's basic but not too simple, and it goes into the structure of the signals as well as into issues on experimental design.


Do you mean evoked potentials, or event-related potentials, or just straight-up EEG? The general way to distinguish between the two is that EEG will tell you about state (aroused, asleep, etc) where evoked or event-related potentials will tell you about operations (processing sound/language/etc); evoked or event-related potentials also generally require more, and more discrete, trials than EEG.

I'd recommend running some simple experiments yourself (on whoever is hanging about) and then analysing them. Do an auditory oddball experiment (Wikipedia's article is a pretty good intro) and analyse it; do a block experiment with basic state changes and analyse it.

I wouldn't start out trying to learn EEG AND program your own analysis suite at the same time; there are packages for EEG/ERP analysis in R (a free, open-source analysis language/platform) that will get you started much faster. But in general, people learn this stuff in labs, and learn it by helping on more experienced people's projects, so there's very little formal introductory material.

Good luck!


I will second the above comment that equipment like EPOC is unlikely to be of much use. EEG research generally requires relatively large numbers of trials per subject even when conducted under the best of circumstances (low impedance electrodes, a shielded chamber, etc.).

As for data analysis, the gold standard for open-source EEG analysis is EEGLAB, which is written in MATLAB. If you don't have access to MATLAB, I believe that Windows binaries are available.


If you are considering an alternative to matlab that is free I would recommend octave. If you are on linux you might consider the whole neurodebian. In terms of book I did not find Steve Luck's book very helpful, but Todd Handy's one was more suited for me. Also a very good book is van Drongelen's Signal Processing for Neuroscientists (cannot put the link sorry, not enough reputation), which includes matlab code with it. It is however tailored to a more technical audience. In terms of video I liked these youtube video. They are on brain computer interfaces, but the introduction also explains a bit about EEG. It is also a bit for the technically oriented.


Segmenting Data into Time Windows¶

To investigate the presence or absence of P300 waves, we must segment the data into time windows following each stimulus presentation. First, let’s take a closer look. Plot just the data from the stimulus channel (index 8) and Channel P3 (index 5).

It appears that some P300 waves are present following the three positive stimuli. Remember that this is the target letter ‘d’. The positive wave appears roughly 100 samples after the stimulus onset. Since the sampling frequency is 256 Hz, this is about 0.4 seconds, or 400 milliseconds, after the stimulus.

Now let’s collect all of the segments from this letter ‘d’ trial. First, find the sample indices where each stimulus starts, collect the displayed letters for each stimulus, and keep track of which stimuli are the target letter.

Good. Now, how long should each time window be? The number of samples between each stimulus onset is

and the minimum number is

so let’s use time windows of 210 samples. We can build a matrix with rows being segments, and each row being all indices for that segment by doing this.

And, finally, we can build an 80 x 210 x 8 array of segments.


Introduction¶

EEG, or electroencephalography, is a technique that records electrical activity from the brain. Typically, it is recorded non-invasively, from electrodes placed on the scalp, although it can also be recorded from electrodes placed directly on the surface of the brain (typically for clinical neurological purposes). EEG typically involves the use of between 1–250 electrodes even at the upper end of that range, clearly there are far fewer electrodes than the estimated 80 billion or so neurons in the brain. As well, the skull is a poor conductor of electricity. This means that what we record with EEG is inevitably the aggregated activity of large numbers of neurons working together.

Fig. 3 An EEG system. The person is wearing an EEG cap with electrodes plugged into it. The wires from the electrodes lead to the amplifier, which transmits the data to a computer for storage. The screen on the left presents stimuli to the person, while the screen on the right shows the EEG data in real time. Image courtesy Brain Vision LLC. ¶

EEG can be a bit challenging for people to get their heads around at first, because there are some non-intuitive features of the data. One of the most important considerations is that EEG is not a good technique for localizing where activity occurs in the brain. Because the electrodes are placed on the outside of the scalp, and because the brain and its encasing cerebrospinal fluid are very good electrical conductors, a signal that originates in one location in the brain will propagate throughout the brain. In other words, in principle any signal inside the brain should be detectable by an electrode placed anywhere on the outside of the brain. Add to this consideration of the fact that, inevitably, many brain areas will be active simultaneously (or in rapid but overlapping succession), and it becomes clear that any signal recorded outside the scalp is a mixture of the signals from all active parts of the brain — at least, those that generate a strong and coherent enough signal to pass through the poorly-conducting skull. For this reason, source localization with EEG is described as an inverse problem (finding the sources on the inside, given the data from the outside, of the head). Mathematically, the inverse problem is ill-posed, meaning that there are essentially an infinite number of possible solutions. This is not to say source localization is always impossible. Indeed, it can work quite well, especially for signals like early sensory responses, where the location of the neural generators of the signal are focal and well-known (e.g., primary visual or auditory cortex). However, the best and most widely-employed uses of EEG focus on the signals as they are recorded on the scalp. Decades of research have provided a substantial evidence base relating particular EEG signals to particular cognitive functions or tasks, and so a primary use of EEG is to identify if, and/or how strongly, one or more of these signals occurs during a task (and/or how the signals differ between task conditions). We’ll elaborate on these points in the sections that follow.

Fig. 4 A 5 s sample of continuous, raw EEG data. Each horizontal trace is the data from one electrode (channel). The large deflections, particularly evident in channel Fp2, are artifacts caused by eye blinks. The coloured vertical lines, which have labels at the top, represent specific events of experimental interest (e.g., stimulus onsets or participant responses). ¶

One important distinction between EEG and other types of data we have worked with so far is that EEG is recorded as a continuous, time-varying signal. This means the data are a time series. Although some of the single unit data we have seen before was stored in a time series (i.e., regularly-spaced data points over time), the signal was not continuous but rather discrete. That is, in single unit data, each time point could only be 0 (no spike) or 1 (spike). In contrast, EEG is recorded as electrical potential (voltage), which varies continuously (e.g., voltage could be 0, or 0.0001, or 10.352, or -82.43, etc.). EEG data also typically include a spatial dimension, because the electrodes are placed across the scalp and different electrodes will detect different signals depending on their location.

By Aaron J Newman
© Copyright 2020. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 Unported License.


One way to decrease the effect of eye blinks is to filter the data. Here is a link to the file bandpass.py , adapted from ObsPy, that defines the function bandpass . We can use it to pass frequencies from 1 to 30 Hz as follows:

There still seems to be a little eye blink present. Unfortunately, bandpass filtering filters each channel independently, so we cannot use information about the relative amplitudes among the channels. Eye blinks tend to affect channels near the front the scalp more. Methods that extract this pattern would do a better job of removing eye blinks, such as Signal Fraction Analysis (SFA).


Using ASA

The ASA software is already installed on the recording PCs that accompany each amplifier. The software is used for recording EEG data. For updates to the ASA software, check http://www.ant-neuro.com/products/asa/download-asa .

ASA can only be accessed from PCs that have the ASA dongle (i.e. the recording PCs). Although, a free trial is available from the website (follow the link above).

If you have any problems with ASA, feel free to use their support forum and help pages: http://ant.ipbhost.com/index.php . Note that you will have to register (free) and log in to access the ASA support pages.

To begin collecting data using ASA, you will need to set up a recording montage. The montage contains all of the information about your EEG setup such as the number and names/locations of channels, the type of reference used, and the recording of any auxiliary electrodes such as EOGs. The recording montage also allows you to setup an online filter of the data and control the display colors of the channels during recording. See the ASA manual for more information on setting up a recording montage.

ASA can be used for some simple analyses of EEG data. All of the processing and analysis steps are included in the graphical user interface (GUI), making it easy to use for demonstrations and for people with little scripting experience. However, we recommend that you export your data into a different programme (e.g. MATLAB) for analysis, since ASA is not suitable for more sophisticated analyses and it can only be accessed via the recording PCs. Many of these more sophisticated analysis tools also have well-developed GUIs, Wikis, Tutorials and support forums. For more information on analysis software, see the ‘Analysis Software’ section below.


Procedure

In this tutorial the following steps will be taken:

  • Read the data into MATLAB using ft_definetrial and ft_preprocessing
  • Extract bipolar EOG channels with ft_preprocessing and get rid of reference channels with ft_selectdata. Combine EOG and data channels with ft_appenddata.
  • Visual artifact rejection with ft_databrowser and ft_rejectvisual.
  • Computing trial averages with ft_timelockanalysis.
  • Plotting ERPs with ft_topoplotER

Getting started with EEG data - Psychology

“A unique and important resource, full of critical practical knowledge and technical details made readily accessible.”

- Tiffany Ito, University of Colorado at Boulder

“A comprehensive and engaging guide to EEG methods in social neuroscience Dickter and Kiefabber offer practical details for conducting EEG research in a social/personality lab, with a broad perspective on how neuroscience can inform psychology. This is a unique and invaluable resource - a must-have for scientists interested in the social brain.”

- David M. Amodio, New York University

Electroencephalography (EEG) has seen a dramatic increase in application as a research tool in the psychological sciences in recent years.

This book provides an introduction to the technology and techniques of EEG in the context of social and cognitive neuroscience research that will appeal to investigators (students or researchers) wishing to broaden their research aims to include EEG, and to those already using EEG but wishing to expand their analytic repertoire. It can also serve as a textbook for a postgraduate course or upper-level undergraduate course in any area of behavioural neuroscience.

The book provides an introduction to the theory, technology, and techniques of EEG data analysis along with the practical skills required to engage this popular technology. Beginning with a background in the neural origins and physical principles involved in recording EEG, readers will also find discussions of practical considerations regarding the recording of EEG in humans as well as tips for the configuration of an EEG laboratory.

The analytic methods covered include event-related brain potentials (ERPs), spectral asymmetry, and time-frequency analyses. A conceptual background and review of domain-specific applications of the method is provided for each type of analysis. There's also comprehensive guided analysis for each analytic method that includes tutorial-style instruction and sample datasets.

This book is perfect for advanced students and researchers in the psychological sciences and related disciplines who are using EEG in their research.


Restructuring EEG data

As mentioned in the introduction, the data is stored in epochs of one second. This can easily be solved by using the function edf2fieldtrip. The function first reads the data and the sample frequency of each channel. If there is a mismatch in sample frequencies between channels, the channels with a lower sample frequency will be up-sampled with ft_resampledata to the highest sample frequency. This may greatly increase the size of your data! In this particular situation, one channel is even up-sampled from 8 Hz to 1024 (i.e times 2^7.m). After up-sampling, the data is concatenated into one data structure.

After using edf2fieldtrip, some extra fields need to be created with the correct values, as to make the data struct complete. Both steps are shown in the following code.

Define trials

Now the data is structured nicely, we can continue with extracting the events. As mentioned before, you must have read the events via readevents(Events.edf,Raw.edf) in ABM’s B-Alert Lab software. Only after this, we can extract the events from a .csv file. Now, specifiy each of the configuration variables as shown below, so that ft_trialfun_balert can interpret it. There are no default values.

Nb. At the moment, ft_definetrial is not used for the segmentation. Instead, ft_trialfun_balert is called directly. This should be better integrated into FieldTrip, please contact the B-Alert support team for this.


Exploring the Example Data

The following GUI tour can be summarised, to some extent, in this command line script:
p = eeg_toolbox_defaults
p = eeg_open(p)
p = elec_open(p)
p = mesh_open(p)
p = gui_erp_plot(p)
p = eeg_contours_engine(p)
So, this will open an ERP file, the associated electrodes and realistic scalp mesh. It will then create GUI interfaces to explore the ERP data, including a timeseries plot and a topographic map. You can see how easy it is to use the toolbox, given the example data! At this point, you can explore the interface on the ERP plot and topographic map. Now for the GUI tour of how to get to this point.

Type 'eeg_toolbox' at the matlab prompt. It will initialise the default parameters and display the folling GUI:

This is the main access point to loading data. If this is the first time you've seen this, its best to reinitialise the default parameters using the Parameters -> Reset Defaults and then Parameters -> Save Defaults commands. If there are any problems at this stage, please email the errors to the eeg-users list. Assuming that works alright, lets now consider the 'file' menu:

From the file menu, open voltage, electrode, tesselations or mri data (see further details on these below). There is also an attempt to keep track of recent data structures. These can be created using Parameters -> Save As Data Workspace command.

The return command will return the toolbox data structure to the matlab workspace, although this structure is constantly updated in the workspace during operations in the toolbox. The default parameters can be used to explore the toolbox with the default data in 'eeg_example_data'. When you are familiar with the toolbox and can see some benefit from it, take a look at the 'eeg_toolbox_defaults.m' function and modify as necessary. This function initialises the data structure that is the key to everything. All functions in the toolbox pass and process the 'p' data structure. As matlab is smart at passing by reference or by value, as necessary, it shouldn't be too memory hungry, but there has been no conscientious effort to manage memory carefully. If you open too many datasets, especially ones with dense tesselations, it might get memory hungry.

To get started with looking at the example data, try File -> Open Voltage and leave all the defaults, click Plot and fill in the parameters with the values given below in the example figure (ERP PARAMETERS). Once this ERP plot is given, click the ELEC button and then return (or plot) in that GUI. That will load (and plot) the default electrode dataset. Then click on the MESH button and return to load the default mesh set. At this point, your ready to look at topographic maps. Select any time point of the ERP waveform by clicking on it and then hit the TOPO button. You should see a top view of the scalp topography. Click anywhere on the viewer and it will start to rotate with the mouse movements. Try the animation controls too (which allows saving of graphics and movies). That's the topography based on the electrodes only. Now close the topography window and go back to the ERP waveform plot. Click on the GUI checkbox below the TOPO button and then note the checkboxes near the bottom of the window - uncheck Elec Surface and check Mesh Surface. Then hit plot and wait - it will calculate a surface interpolation from the scalp electrodes to the scalp tesselation vertices and plot the realistic scalp topography. Yippee! If the MRI toolbox is installed, you can also open Analyze 7.5 data. If you get this far, your well on the way to using the toolbox on your data. Below is some more information about using the GUI interface. Play around with the ERP plot window, there are some nice interactive features for PRECISE measurement of data values. This GUI uses the same functions available in a general matlab function called crosshair (which has been downloaded thousands of times and used in all kinds of fascinating work around the globe -), see my matlab file exchange page). Place the mouse over various elements of the GUI and it will give popup help immediately.

Each of the file open GUIs appears very similar (as below). They each provide edit fields that contain the current file path and filename and facilities to browse for a file, plot the data and close the GUI. The 'Hold GUI' checkbox allows control of whether the GUI automatically closes after a plot command. Each of these GUIs returns the 'p' data structure to the main eeg_toolbox GUI and the matlab workspace. These GUIs call the eeg_open.m, elec_open.m and mesh_open.m functions, which control loading and plotting of the data. These functions can be called directly from the command prompt.

These GUIs provide access to various data types/formats.

For ERP timeseries, the ascii format should provide access to most data. The ascii file should contain only a matrix of potential values, no channel labels. The Neuroscan .avg format is well supported, and the matlab option provides access to binary files (via 'eeg_load.m').

The toolbox will attempt to arrange an EEG/ERP data matrix so that it has N rows of ERP sample points from M columns of electrodes (N>M is assumed). Many matlab functions assume that channels are given by column vectors (eg, the signal processing toolbox). One assumption made in the toolbox is that there are more ERP sample points than there are channels and it will try to arrange input data so that channels are column vectors.

An example of filtering an ERP waveform may be attained if you have the signal processing toolbox. For example, the following implements a 50 Hz lowpass filter:
lowpassHz = 50
[b,a] = butter(15,lowpassHz/p.volt.sampleHz)
data = filtfilt(b,a,p.volt.data)

The ERP parameters button provides GUI access to defining essential epoch and sampling parameters:

These parameters will be read from Neuroscan .avg files, where possible, but must be entered for ascii data (although a first guess at electrodes and points is made from the size of the data matrix). If all essential parameters are not defined, this dialog box is opened during the plot command.

For electrodes, ascii data is supported and some other formats are available (scantri is from Neuroscan 3Dspace, Brainstorm and EMSE files are also there, either in the GUI already or at least via the command line). The ascii files can be Cartesian or spherical coordinates. See 'help elec_load' for more information on ascii data and 'help elec_open' in general. Also see the format of the default electrode file in the example data folder.

For meshes (tesselations), the toolbox can read ascii data in the FreeSurfer or EMSE formats and functions are available to read binary FreeSurfer files too. The toolbox can also read BrainStorm tesselations. See 'help mesh_open' for more information.

Example Data

In the subfolder 'eeg_example_data', the file names are descriptive of the contents.


EEG Methods for the Psychological Sciences

“A comprehensive and engaging guide to EEG methods in social neuroscience Dickter and Kiefabber offer practical details for conducting EEG research in a social/personality lab, with a broad perspective on how neuroscience can inform psychology. This is a unique and invaluable resource - a must-have for scientists interested in the social brain.”

- David M. Amodio, New York University

Electroencephalography (EEG) has seen a dramatic increase in application as a research tool in the psychological sciences in recent years.

This book provides an introduction to the technology and techniques of EEG in the context of social and cognitive neuroscience research that will appeal to investigators (students or researchers) wishing to broaden their research aims to include EEG, and to those already using EEG but wishing to expand their analytic repertoire. It can also serve as a textbook for a postgraduate course or upper-level undergraduate course in any area of behavioural neuroscience.

The book provides an introduction to the theory, technology, and techniques of EEG data analysis along with the practical skills required to engage this popular technology. Beginning with a background in the neural origins and physical principles involved in recording EEG, readers will also find discussions of practical considerations regarding the recording of EEG in humans as well as tips for the configuration of an EEG laboratory.

The analytic methods covered include event-related brain potentials (ERPs), spectral asymmetry, and time-frequency analyses. A conceptual background and review of domain-specific applications of the method is provided for each type of analysis. There's also comprehensive guided analysis for each analytic method that includes tutorial-style instruction and sample datasets.

This book is perfect for advanced students and researchers in the psychological sciences and related disciplines who are using EEG in their research.


Watch the video: Introduction to EEG for neuromarketing (January 2022).