Applying ICA to Collections of Single Trials
Visualizing single trials data using erpimage()
'ERP image' plotting is a new and useful visualization tool for investigating variability in the latencies and amplitudes of collections of single-trial event-related response epochs. To plot an ERP image, potentials recorded at one scalp channel in each trial (or else, the time courses of activation of one response component) are sorted in order of a relevant response or data measure (for example, subject response time) and then plotted as parallel colored lines forming a colored rectangular image. The ERP image may be displayed before or after smoothing with a narrow (example: 5-30 trial) moving window to increase the salience of event- and/or measure-locked response features.
The erpimage() function is fundamental to our approach to single-trial analysis of event-related EEG data. ERP images can be used to visualize variability in the amplitudes and latencies of event-evoked responses, either by visualizing single-channel EEG epochs themselves, or by visualizing the single-trial activations of independent components of the data.
![]()
An example, shown in the left panel of the figure above plots an ERP image of 645 event-related single-trial epochs recorded at the parietal (Pz) and time-locked to onsets of target stimuli ( faint vertical dotted lines). Click on figure and resize popup window to view details. Each colored horizontal trace represents a one-second single-trial ERP record whose potential variations are coded by color (see color bar). The jagged thick vertical line plots the subject's response time in each trial. Note the trial-to-trial fluctuations in both ERP latency and reaction time. Sample Matlab code for constructing the figure above is shown below. Note: Some text in the figure above was added manually for purposes of publication.
% erpimage(data,sortvar,times,'title',avewidth,decimate,[option(s)]); figure; data = floatread('trialdata.fdt',[31,Inf]); % Read floating point 31-channel data load RTs.adt -ascii % Load a one-column ascii RT (ms) values file times = -100:1000/srate:899; % Time of each data frame in msec. sbplot(3,1,1); % Image data from channel 23. Do not sort by RTs. erpimage(data(23,:),RTs,times,'Single-trial ERPs at Pz',1,1,'erp','nosort'); sbplot(3,1,2); % Default: sort by the RTs variable. erpimage(data(23,:),RTs,times,'Ordered by RT',1,1,'erp'); sbplot(3,1,2); % Smooth with 20-trial moving window; decimate by 2. erpimage(data(23,:),RTs,times,'With 20-trial smoothing',20,2,'erp','cbar','caxis',0.5); % The argument to 'caxis' tells erpimage() to make the color scale limits % plus and minus half the abs(max()) value in the data. This makes the 0 value green. % The 'caxis' flag can also accept specific [lo,hi] limits.
The average of these trials and the median response time (RT) are plotted below the ERP images (above). Next, (middle panel) the same single trials were sorted in order of increasing subject response time and replotted using erpimage() with no vertical (across-trials) smoothing.
After erpimage() (right panel) smoothing with a 20-trial rectangular moving average, some features of the RT-sorted single-trial data set become more salient. For example, note (right panel) that in the short-RT trials the early features (P1, N1) are time-locked to stimulus onset (i.e., they are stimulus-locked), while the later `P3' feature follows the response in all but the longest-RT trials (i.e. it is mainly response-locked).
Note: The plot above shows the sum of all EEG and artifactual activities that contribute to the recording at site Pz (or at the reference site, the right mastoid). ICA can decompose this summed activity into separate neural and non-neural (artifactual) processes. The activities of these independent components in each trial can then be separately imaged using erpimage().
ERP images allow direct visualization of relationships between single event-related EEG trials and behavior, or between single trials and the ERP average. ERP images make visible links between subject behavior and dynamics of individual event-related responses. We have also successfully applied it to visualization of single-trial event-related MEG (MEG-image) and fMRI (BOLD-image) data.
An interesting feature of erpimage() is its 'phase' option to sort trials by their phase at a particular frequency and time window. Other options allow plotting the mean time course below the data image, plotting mean amplitude and inter-trial coherence traces at a particular frequency (with statistical limits determined by bootstrap), and showing the mean log power spectrum and scalp map of the plotted data, To display the help message for the frequency based arguments: >> erpimage moreargs
% erpimage(data,sortvar,times,'title',avewidth,decimate,[option(s)]); figure; data = floatread('15sstrialdata.fdt',[31,Inf]); % Read data from 15 Ss load RTs.adt -ascii % Load ascii RT values (in msec) times = -100:1000/srate:899; % Time of each data frame in msec. erpimage(data(16,:),RTs,times, ... % plot channel-16 data 'all 15 ss O1', ... % plot title 100,10, ... % smooth by 100 trials / decimate by 10 'srate',srate, ... % specify sampling rate (Hz) 'phase',[350,0.10,8,12],... % sort trials by 8-12 Hz peak alpha phase ... % 3-cycle window end at 350 ms ... % discard lowest-amp 10% 'coher',[1 0.01], ... % display ITC, show p=0.01 level ... % Note: follows phase freq (above) 'cbar','caxis',[-10 10],... % display color bar and set caxis 'erp'); % display the trial mean ERP
![]()
For example, above we have used the erpimage()) 'phase' option to sort data from a single scalp site (O1) in a selective visual attention experiment by phase at 10 Hz in a 3-cycle window centered at the peak of the N1 feature of the ERP (about 200 ms). Note that this sorting (followed by 20-trial moving window smoothing) also weakly organizes alpha phase before and after the sorting window (showing the system has phase memory). The sigmoidal curve of the isophase lines during (and after) the phase sorting window show an interaction between EEG phase and stimulus presentation, creating the "alpha ringing" ERP (top trace below the image). Yet, mean amplitude at 10 Hz increases only 1 dB (middle trace). The "alpha ringing" in the ERP, on the other hand, increases by about 10 dB above the ERP baseline. The "alpha ringing" ERP is thus produced by the phase of the alpha activity coming into (imperfect) alignment after stimulus presentation, as quanitified by the inter-trial coherence(ITC) (bottom trace) which rises above the bootstrap significance level (horizontal red line).
Other Single-Trial Data Functions
floatread()
This function reads floating point data (multiplexed by channels) into a data array.floatwrite()
This function writes floating point data (multiplexed by channels) into a data file.matsel()
This function simplifies extraction of selected epochs, frames and channels from a 2-dimensional (channels, frames*epochs) data matrix. Note: Given a three-dimensional (channels, frames, epochs) matrix M, then the matrix M(:,:) has the assumed two-dimensions.erpave()
A response averaging function that can extract single trials from a continuous data set. Returns them concatenated or averaged.movav()
A general-purpose moving average function that can perform windowed moving-averaging of single trials indexed by time or any other variable, even when the assumed x-values (e.g., times) are not evenly spaced.blockave()
A simple epoch block-averaging function for data formatted as size (channels,frames*epochs).eventlock()
A function (extracted from erpimage()) that allows a set of single trials to be time aligned to another set of events (one per trial). We use this to realign stimulus-locked trials to response times, etc.eegfilt()
A function (using functions from the MATLAB Signal Procesing toolbox) for filtering continuous or concatenated epoch data.Next remove artifacts from single-trial data ...
Open the function help window
View log of changes to this tutorial.
Comments and suggestions on this tutorial
are welcome. Email scott@salk.edu