How can I import my own dataformat?

There are two approaches for importing data from an unsupported format: you can extend FieldTrip with new code, or you can circumvent the import procedure.

Extend the FieldTrip reading functions

The first and preferred way of implementing a new dataformat is by extending the ft_read_header, ft_read_data and ft_read_event functions. These functions are wrappers around many different fileformats and provide a common interface. Probably you will also have to add your fileformat to fileformat function so that the files are properly recognized. You could even replace the ft_read_xxx functions completely by your own functions, as long as their interface stays the same. Depending on the complexity of your experimental design (e.g. conditional trigger sequences), you might want to write a custom function for the trial definition.

In Contact us if you need help.

Circumvent the FieldTrip reading functions

Alternatively, if you already are able to read the data into MATLAB somehow, you can reformat that data within Matlab into a datastructure that is compatible with FieldTrip. Raw data that is comparable with the output of preprocessing should consist of a structure with the fields

data.label      % cell-array containing strings, Nchan*1
data.fsample    % sampling frequency in Hz, single number
data.trial      % cell-array containing a data matrix for each 
                % trial (1 X Ntrial), each data matrix is a Nchan*Nsamples matrix 
data.time       % cell-array containing a time axis for each 
                % trial (1 X Ntrial), each time axis is a 1*Nsamples vector 
data.trialinfo  % this field is optional, but can be used to store 
                % trial-specific information, such as condition numbers, 
                % reaction times, correct responses etc. The dimensionality 
                % is Ntrial*M, where M is an arbitrary number of columns

Each trial can have a different number of samples (i.e. variable length), that is why each trial needs an individual time axis. If your data consists of trials with a fixed length, then each vector data.time{i} is equal to data.time{1}. If your data consists of a single trial, e.g. when it is a continuous recording, there is only a single data.time{1} and single data.trial{1}. The data format is described in more detail in ft_datatype_raw. The main FieldTrip data structures are jointly described in this FAQ.

If your data represents a continuous recording, you can also consider taking a simple two-step approach by first representing your data into one long trial as described above, and then cutting it up into individual trials using ft_redefinetrial.

Note that to do so you need to enter another field that makes the data recognizable as a long trial:

data.sampleinfo % array containing [startsample endsample] of data

Note also that if you want to add trial-specific information related to the short trials that are going to be created in the next step, you need to create the trialinfo field only after your call to ft_redefinetrial

Now you simply call ft_redefinetrial, supplying a trialstructure in the config, e.g.:

cfg.trl = [1    100 -10;
           101  200 -10;
           201  300 -10];
newdata = ft_redefinetrial(cfg,data);

The second approach for importing data is relevant if you do not want to read the raw data from file, i.e. you do not want to do everything (starting with preprocessing) using FieldTrip, but only the final stages of your analysis. This is the approach for example taken in the besa2fieldtrip and spm2fieldtrip functions.

faq/how_can_i_import_my_own_dataformat.txt · Last modified: 2015/11/26 14:32 by robert

You are here: startfaqhow_can_i_import_my_own_dataformat
CC Attribution-Share Alike 3.0 Unported Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0
This DokuWiki features an Anymorphic Webdesign theme, customised by Eelke Spaak and Stephen Whitmarsh.
Mobile Analytics Website Security Test