Data Exchange with Matlab / Octave

Introduction

It is possible to access the EEP binary data files (*.cnt, *.avr) within Matlab and Octave.

For Matlab, it is done via "Matlab Extension" (mex) functions. They are installed in the /usr/local/share/mex subdirectory, which has to be included in the MATLABPATH environment variable.

For Octave, the functions are installed in the /usr/local/share/eep/octave subdirectory which can be activated by placing the line
LOADPATH=strcat(LOADPATH, ":/usr/local/share/eep/octave//");
in your $HOME/.octaverc.

The functions are documented in Matlab style - type 'help <function>' in the Matlab prompt or have a look at the associated .m files.

Functions

Please contact ANT Software for further information on the Matlab/Octave data exchange.

A (*) indicates functions which are available for Matlab only, not for Octave.

The following functions provide basic cnt file read/write access.

CNT_OPEN
CNT_LOAD
CNT_DUP(*)
CNT_APPEND(*)
CNT_CLOSE
The cnt write access is somewhat restricted: There is no function to create a cnt file from scratch; you will have to duplicate(CNT_DUP) an input cnt. This safes you from supplying all the data which are needed to create a valid cnt, they are just copied. At the other hand, this means that you cannot change such things as the number of channels or the sampling rate. Furthermore, because a cnt file is a "compressed signal archive", there is no way to write data at random positions. You can only write sequentially (CNT_APPEND).

The following functions provide trial-based cnt file read access, employing the same lists and configuration as cntaverage:

TRIAL_OPEN(*)
TRIAL_LOAD(*)
TRIAL_CLOSE(*)
The following functions allow to load the contents of an .avr file into a Matlab structure or to store such a structure as .avr file to disk. These are completely written as m-files - feel free to improve/adapt if needed.

AVR_LOAD
AVR_STORE
Note that the EEP modules store the variance in .avr files as
s2 = 1 / n * (sum(x2) - n * (mean(x))2)
You eventually need to scale it by n / (n - 1).

Example

The following Matlab code fragments illustrate how to use the functions. Note that you must write nested open/close pairs for your handles (each open handle costs one file descriptor and dozens KB of memory).

% trial-based read access ---------------------------------------

% open the EEP files for a subject "pa53" in the cwd

[src, chan, length, rate] = cnt_open('pa53.cnt');
[th,co,st,cl,le] = trial_open(src, '../cfg/average.cfg', 'pa53.trg', 'pa53.rej');

% add some code to find interesting trial indices using
% the condition vector co and the classification vector cl
% note that the first trial has the index 0 in trial_load !!!

need_this_one = ...

% load the trial number need_this_one
% (m has 2*le elements in this case)

m = trial_load(th, need_this_one, ['EOGV';'EOGH']);

% do not forget to close the handles

trial_close(th);
cnt_close(src);

% plain read/write access ---------------------------------------

% create input/output handles
[src, chan, length, rate] = cnt_open('pa53.cnt');
dst = cnt_dup('pa53_new.cnt', src, 0);

% now you can load data from src, do something intelligent
% with it and write it to dst

M = cnt_load(src, 0, 1000, chan);
do_what_I_want(M);
cnt_append(M);

cnt_close(dst);
cnt_close(src);


EEP 3.1 - MPI/ANT(eeprobe@ant-software.nl), 09.08.1999
Copyright © 1996-99 Max-Planck-Institute of Cognitive Neuroscience. All rights reserved.