Skip to content

EEG: show traces

Fa-Hsuan Lin edited this page Jun 28, 2020 · 7 revisions

EEG: show traces

Here we show how to display multiple EEG traces in a GUI in Matlab. The data were from a steady-state visual evoked potential experiment. Data were collected from a system (BrainAmp MR Plus, Brain Products, Gilching, Germany) with a thirty-two channel electrodes EEG cap (EASYCAP, Herrsching, Germany).

All data can be downloaded here.

The follolwing line shows EEG traces.

etc_trace(eeg,'fs',fs,'trigger',trigger);   
  • eeg is a 2D matrix (#channel x # time)
  • fs is the sampling rate (in Hz).
  • trigger is a struct with the following two fields: event is a 1xn vector using numbers to code for n triggers. time is a 1xn vector to indicate the timing of each trigger (in sample).

Browse traces

You can use four buttons at the lower left corner of the figure ("<<", "<", ">", ">>") to move the window of all traces forward (">") or backward ("<"). The double-arrows are for fast-forwarding and fast-rewinding. "<" and ">" will temporally shift 1/5 of the traces in the window, while "<<" and ">>" will temporally shift one window span of all traces by a single button clicking.

You can also move the horizontal scroll bar to move the traces.

As you shift the traces across time, the corresponding timing indices, including the beginning and the ending indices (in samples; 1-based) and timing (in seconds) will be updated. These timing indices are shown in the edit boxes at the right-lower end of the trace window. As these are edit boxes, you can also manually set these timing indices. Traces will be moved accordingly.

Window span

The span of the trace window is set to 2 s by default. You may use the list box at the bottom at the center to select your window span, which can be 0.1 s, 0.5 s, 1 s, 2 s, 5 s, 10 s, or 30 s.

Triggers

Triggers indicating the onset of the visual stimuli were recorded in the data. They were numerically encoded by "1" and "10". To visualize EEG around these triggers, you can select the corresponding trigger in the list box at the right lower part of the window. For example, if you choose trigger "1", the trace will move to the first occurrence of this trigger by plotting a vertical green line. There are also two edit boxes showing the timing of the trigger (in samples and in seconds).

For all other triggers (than the selected one), they will be marked by vertical gray dashed lines, if they are inside the span of the display.

next/previous trigger

To move to the next (or previous) trigger (of the same number), you can click the button ">" (or "<") at the right (or left) side of the trigger list box. The window will move all traces to the next (or previous) trigger.

Select a time point

You can click the trace window. The time corresponding to your mouse click will be marked with a pink vertical line. This timing will be reported in the Matlab command window (both in samples and in seconds).

Select an electrode

As you click the time series of an electrode, that electrode will be selected. It will be shown by a thick blue trace. This selection can be canceled by click the same trace again.

Alternatively, you may select the time series at an electrode by first invoking a list box showing all electrodes. This is done by clicking "L" in the trace window. Then you can select the electrode in the list box. The time series of the selected electrode will be highlighted by showing a thicker trace. The figure below shows that the electrode "CP6" was selected.

Show the EEG topology over the scalp

You can type "t" in the trace window to show the EEG topology at the selected time point over the scalp. To do this, you need to provide a head model and the locations of electrodes. If you do not have this, you will be prompted to load a Matlab data file to supply this information. Basically this Matlab data file should include the following:

  • A 2D matrix (n x 3) named "vertex" indicating the (x, y, z) of each vertex of a head model
  • A 2D matrix (f x 3) named "face" indicating the f vertices (1-based) of each triangle of a head model
  • A string cell array (p x 1) named "electrode_name" indicating the names of electrodes.
  • A vector (p x 1) named "electrode_idx" indicating the vertex (1-based) of a head model for each electrodes.

Now you may select other time points by clicking at the desired timing in the trace window. The EEG trace topology will be updated in both trace window (by showing a different pink vertical line) and the brain topology window.

An example of the Matlab data file (topology_31ch_default.mat) for these 4 variables for a 31-electrode EEG system can be downloaded here.

Show/create EEG events

You can type "v" in the trace window to invoke a list showing all marked events, including their timing instants (in sample) and event type (class).

You can select these events by clicking the mouse at the corresponding entry (either timing instant or event type). As you choose an event, the trace window will also update. The event panel in the trace window (at the lower right corner) will change accordingly. Note that at the top of this event window, there are two edit boxes showing the currently selected time and suggested event type (class).

Add a new event

You can click at the trace window to label your interested instant. This instant will be reported in the edit box at the top of the event window. A suggested event type (class) will be given as well. If you want to add this instant and its associated event type (class) to the event list, simply add the "Add to labeled events" button.

Note that duplicated entry (the combination of time instant AND event type (class)) will NOT be added.

You can assign any event type (class) associated with the an instant by manually edit the edit boxes at the top of the event window.

Remove events

To remove an event from the list, simply click that entry in the list box. Then click 'DEL' or backspace key. It will be moved.

Example script

Here is an example script to do the pre-preocssing, analyze triggers, and show EEG traces. Pre-processing includes:

  1. re-referencing (subtracting the average time series across all electrodes from the time series at each electrode),
  2. high-pass filtering (cut-off at 0.1 Hz),
  3. trimming off the first 20 seconds off.

Data are here:

Clone this wiki locally