Skip navigation

You are in:  Home » Research at the Unit » EEG/MEG Research on Language

Matlab tools for processing ERP data

Matlab tools for processing ERP data



How to run it:
Make sure you have added the folder containing the matlab programs to your Matlab path list (File->Set path->Add path/folder, save).Start Matlab, and type
pre_proc('{command_file}')
in the command window, e.g. pre_proc('my_analysis.txt').


General:
  • Commands following "###" are common to all files to be processed, e.g. the output of results shall be written in a single output file "all.txt" in the above example
  • Each of the commands listed below can also be used after the "###" option. It will then be applied to each file of the list. If the corresponding parameter is additionally specified for an individual file, this overrides the general specification (but only for this particular file).
  • Text strings starting with a "#" are the actual commands, possibly followed by further specifications (see below)
  • Commands following a "+" at the beginning of a line are a continuation of the line above. The use of this feature is optional, but will make command files easier to understand
  • Text following a "%", as well as empty lines, will be ignored. This feature can be used for inserting comments into a command file. (Use it!)
  • At this point, the sequence of processing steps cannot be influenced. It is: baseline correction-> linear detrending->re-referencing->SNR computation->means over time ranges->normalisation->mean over channel groups; only if the corresponding options are specified, of course.


  • List of commands
    In the following, items in {} are to be specified by the user.

  • #avr, #avg, #asc, #asct: The following string specifies new input file, either in BESA avr-format, Scan avg-format, plain matrix without header timepoints fastest (i.e. one row per channel), or plain matrix channels fastest (i.e. one row per timepoint)
  • #baseline {start_lat} {end_lat}: Specifies baseline interval in ms used for baseline correction
  • #ref {reference}: Specifies reference to be applied.
    "#ref avg": average reference (Average over all valid electrodes is subtracted from each electrode)
    "#ref {chan_nr}": Data are referenced to channel "chan_nr", e.g. "#ref 64"
    "#ref {chan_nr1}+{chan_nr2}": Data are referenced to the sum of channels "chan_nr1" and "chan_nr2", e.g. "#ref 63+64"
    "#ref {chan_nr1}-{chan_nr2}": Data are referenced to the difference of channels "chan_nr1" and "chan_nr2", e.g. "#ref 63-64"
    "#ref {chan_nr1}m{chan_nr2}": Data are referenced to the mean of channels "chan_nr1" and "chan_nr2", e.g. "#ref 63m64"
  • #bad_chan {bad_channels_list}: List of channels to be omitted from processing. Channels have to be separated by ",", e.g. "#bad_chan 1,2,3,63,64". These channels are not included in processing (like average referencing), but are not removed from the data and are included in the output.
  • #reduce_chan {channels_list}: List of channels to be removed from data. Channels have to be separated by ",", e.g. "#reduce_chan 1,2,3,63,64".
  • #reduce_time {start_lat} {end_lat}: Data will be reduced to this time range before processing starts. The latency range must include the baseline interval and all other time intervals required for the remaining processing steps (if specified).
  • #avg_time [{range1}][{range2}]...: Time ranges for which mean topographies shall be computed and output. Every range has to be in square brackets, latencies must be separated by ",", e.g. "#avg_time [100,200][200,300][550,600]"
  • #chan_mean [{list1}][{list2}]...: Channel clusters over which an average shall be computed. Every cluster has to be specified within square brackets, channels must be separated by ",", e.g. "#chan_avg [1,2,3][14,15][60,61,62,63,64]". If "#chan_mean all " is specified, the mean across all valid channels is computed.
  • #chan_rms [{list1}][{list2}]...: Like '#chan_mean' (see above), but the root-mean-square (RMS) over channel groups is computed.
  • #outavg {outfilename}: Specifies filename for output of individual results for current file. However, Scan avg-files can only be output if the input file is an avg-file as well.
  • #outavr {outfilename}: BESA avr-files are written. Can be chosen independently of the format of the input file.
  • #outasc {outfilename}: Plain ascii matrices (without header) are written, timepoints fastest (i.e. one row per channel)
  • #outasct {outfilename}: Plain ascii matrices (without header) are written, channels fastest (i.e. one row per timepoint)
  • #norm {normalisation}: Specifies which normalisation procedure for topographies shall be used.
    "#norm vector": Normalisation to unit Euclidean vector length
    "#norm maxmin": Normalisation to mean=0, max-min=1
  • #reduce {start_lat} {end_lat}: Reduce data to the specified latency range.
  • #detrend: Channelwise linear detrending (best-fitting line over all time points is subtracted for each channel)
  • #highpass {frequency (Hz)}: High-pass filtering at cut-off 'frequency' with 2nd order Butterworth filter (uses 'filtfilt' from Matlab Signal Analysis toolbox).
  • #lowpass {frequency (Hz)}: Low-pass filtering at cut-off 'frequency' with 2nd order Butterworth filter (uses 'filtfilt' from Matlab Signal Analysis toolbox).
  • #pca_filter {nr_of_components}: Compose data out of first 'nr_of_components' principal components, i.e. leave out the remaining ones (which might represent noise or other non-desired activity). Roughly speaking this behaves like a spatial and temporal low-pass filter.
  • #extract_pca {nr_of_components}: Extract the first 'nr_of_components' principal components (spatial and temporal). The spatial components are handled and output like normal data (i.e. each component takes one column, channels are organised in rows). Temporal components and eigenvalues will be output (individually or combined, as specified) in files with extensions '*.ev' or '*.tmc', respectively. Note that in contrast to '#pca_filter", in this case the PCA-components are output separately, and not recombined.
  • #peakabs: Determines latency of maximum absolute amplitude for each valid channel in time ranges specified under "#avg_time". If no time range is specified the whole file is considered. Peaks are defined as having maximum absolute amplitude, regardless of negativity or positivity, within the specified time range. Both peak values and latencies are output in one file: The upper half of rows (1:nr_chan) contains the peak amplitudes (with sign), the lower half (nr_chan+1:2*nr_chan) the peak latencies.
  • #peakneg: Determines latency of minimum amplitude for each valid channel in time ranges specified under "#avg_time". If no time range is specified the whole file is considered. Output like for '#peakabs'.
  • #peakpos: Determines latency of maximum amplitude for each valid channel in time ranges specified under "#avg_time". If no time range is specified the whole file is considered. Output like for '#peakabs'.
  • #scale_snr {lat1} {lat2}: For each channel, the amplitudes at each time point will be divided by the standard deviation of the interval from {lat1} to {lat2} in ms (e.g. the baseline interval).
  • ### #output {output_type} {outfilename}: Specifies the way all results shall be output together.
    "### #output all {filename}": Unformatted output as one big matrix. Individual output data are simply concatenated (column-wise), and output without header line.
    "### #output timetopo {filename}": BESA avr-format, each column is one topography. Every column consists of a list of channels or channel groups, respectively. The input sequence is preserved.
    "### #output timestat {filename}": Separate files for separate time ranges. Individual results are concatenated column-wise. Separate rows for separate files (e.g. subjects). No header line. This option is meant to be optimal for statistical analysis.
    "### #output timestat2 {filename}": Separate columns for separate files (e.g. conditions) and channel groups. Separate rows for separate time points (if no average time ranges specified). This option is useful if separate files correspond to different conditions, and columns within files refer to different subjects. The output will then have separate rows for different subjects, which is convenient for statistical analysis.
  • ### #difference: The difference of successive files is computed (first-second). The result is written in the output file specified for the second file of each pair, i.e. the file name specified by the #outavr or #outavg option.
  • ### #snr {filename}: Compute the signal-to-noise ratio for each time point and write it columnwise in 'filename'. The SNR in this case is computed as the ratio of the signal at each channel at each time point, devided by the standard deviation of the baseline interval for this channel. Three output files are created: curves containing the max/min/mean values over channels for each time point. A baseline interval must be specified.
  • ### #grandmean {filename}: Compute grand-mean over all result files and write in to file 'filename' (avr-format).
  • ### #anova {filename}: Performs a two-way ANOVA on each channel and timepoint. The resulting p-values are written in BESA ascii format to {filename} (one row per channel, one column per timepoint). The data are divided into an upper and lower half, and those are compared to each other.
  • ### #ttest {mean} {alpha} {tail}: Performs a T-test on each channel and timepoint. If mean=0: The mean over all data sets will be tested against 0. If mean<>0: The data are divided into an upper and lower half, and those are compared to each other. alpha is the desired significance level. tail can be 0/1/-1 according to the null hypothesis to be falsified: mean of upper half not equal to mean of lower half/ mean of upper half larger than mean of lower half/ mean of upper half smaller than mean of lower half. The resulting p-values are written in BESA ascii format to {filename} (one row per channel, one column per timepoint).


  • A command file might look like this:

% Output for all files in "all.txt"
### #output all c:/temp/all.txt
Baseline correction for all files -100ms to 0ms
+ #baseline -100 0

% First file in Scan format "brain1.avr", average time ranges 0-100ms, 200-300ms
#avg c:/temp/brain1.avg #avg_time [0,100][200,300]
% Compute average reference
+ #ref avg
% Results for this file individually output in brain1out.txt
+ #output brain1out.txt
% Exclude channels 1-5 from analysis
+ #bad_chan 1,2,3,4,5

% File 2 in BESA format "brain2.txt", baseline interval -200-0ms used
#avr c:/temp/brain2.avr
+ #ref avg
+ #output brain2out.txt
% channel clusters to be averaged
+ #chan_avg [1,2,3,4][5,6][7,8,9]
This specific file shall be baseline corrected from -200ms to 0ms
#baseline -200 0

#avg c:/temp/brain3.avg #baseline -300 0
% Re-reference to the sum of channels 1 and 2
+ #avg 1+2
+ #avg_time [400,500][500,600][700,800][900,1000]
+ #output brain3out.txt
+ #bad_chan 1,2,3,40,50


Any feedback and suggestions welcome!

Olaf Hauk , 2002