[FieldTrip] Importing EEGLAB data into Fieldtrip

Roy Cox roycox.roycox at gmail.com
Thu Mar 31 19:25:13 CEST 2022


hi Luisa,

Regarding ICA, I recently had a somewhat related issue and managed to solve
it with custom code (and help from this list), partly because I wasn't all
too sure about eeglab2fieldtrip.

First off: eeglab and fieldtrip rely on the exact same underlying ica
implementation (at least for runica, and I suspect for other variants as
well). If you have no specific requirement to run ica from eeglab, I think
it would be easiest to just import your (pre-ica) data into fieldtrip, and
run ica/reject components from fieldtrip (and let fieldtrip handle all the
bookkeeping).

If you somehow must convert eeglab's ica decomposition to fieldtrip you
could construct a fieldtrip component structure as follows (assuming *data_ft
*is your data in fieldtrip format, and *EEG *the eeglab format):







*cfg_comp = [];cfg_comp.demean    = 'no';           % This has to be
explicitly stated, as the default is to demean.cfg_comp.unmixing  =
pinv(EEG.icawinv);  % Supply the matrix necessary to 'unmix' the
channel-series data into componentscfg_comp.topolabel = data_ft.label(:); %
Supply the original channel label information%calculate component
topographies and time courses for entire datacomp =
ft_componentanalysis(cfg_comp, data_ft);*

you should get something like this (I ran ICA with pca 64 option):













*comp =   struct with fields:       fsample: 250          time: {[1×7747289
double]}         trial: {[64×7747289 double]}          topo: [249×64
double]      unmixing: [64×249 double]         label: {64×1 cell}
 topolabel: {249×1 cell}          elec: [1×1 struct]    sampleinfo: [1
7747289]*
           cfg: [1×1 struct]

Rejecting components can then be done as follows:



*cfg=[];cfg.component=badCompInds;data=ft_rejectcomponent(cfg, comp);*

where you could get *badCompInds *from inspecting components within
fieldtrip, or from somewhere in* EEG.reject* to remove already marked
components (you'd have to check what field exactly).

Roy

On Thu, Mar 31, 2022 at 5:43 PM Julian Keil via fieldtrip <
fieldtrip at science.ru.nl> wrote:

> Dear Luisa,
>
> Regarding your first question, it is im my experience easier to recreate
> the .trialinfo field from the EEGLab event-info after exporting from EEGLab
> to FieldTrip.
> You can find an example from a recent project here:
> https://osf.io/ph5xm/ for the export to Fieldtrip
> https://osf.io/n27pe/ for the function to get the trial-info
>
> Regarding your ICA-questions, in the aforementioned project, I did the
> whole preprocessing in EEGLab, including the IC rejection, as I only needed
> the „clean“ data later on. However, I guess this strongly depends on what
> you want to do with your data later on.
>
> Hope this helps,
>
> Julian
>
> ________________
> Prof. Dr. Julian Keil
>
> Biologische Psychologie
> Olshausenstraße 62 - R. 306
> 24118 Kiel
>
> 0431 / 880 - 4872
> http://www.biopsych.uni-kiel.de/
>
>
> Am 31.03.2022 um 16:35 schrieb Luisa Roeder via fieldtrip <
> fieldtrip at science.ru.nl>:
>
> Dear Community,
>
> My name is Luisa Roeder and I am a postdoc in Prof Joachim Hermsdoerfer’s
> lab at Technical University Munich. Currently, we are working on a grip
> force control project, and I am analysing combined EEG-EMG data.
> I hope my email is not too long; I have a few questions re importing data
> from EEGLAB to Fieldtrip.
>
> I have pre-processed the data in EEGLAB and would now like to import them
> into Fieldtrip. For this, I used ft_preprocessing with the details shown
> below. However, in the Fieldtrip structure I receive, I cannot seem to find
> any information on the events/triggers I had in the .set file.
> Where do I find the event information that was saved in the eeglab (.set)
> file as EEG.event? Is it possible to also import this event information
> (i.e. their indices and type of event) into Fieldtrip, or do I need to save
> this information separately and then use ft_definetrial to re-create my
> events in fieldtrip? If this is the case, what would be the best
> way/structure and file format for saving the events from eeglab?
>
> Below are the details of my code and output:
>
> cfg = []; cfg.dataset = 'data01_cond1.set'; ft_data1 = ft_preprocessing(cfg);
>
> and receive the output
> ft_data1 =
>   struct with fields:
>            hdr: [1×1 struct]
>          label: {61×1 cell}
>           time: {[1×692901 double]}
>          trial: {[61×692901 double]}
>        fsample: 500
>     sampleinfo: [1 692901]
>           elec: [1×1 struct]
>            cfg: [1×1 struct]
>
>
> I noticed when I use
> ft_data1 = eeglab2fieldtrip(EEG, ‘raw’);
> with segmented (epoched) EEGLAB data, I receive some information on my
> trigger events I used for segmenting (in ft_data1.trialinfo), but this does
> not include the indices of the events (‘latency’ in EEG.event), nor the
> other types of events I had in EEGLAB in addition to the trigger I used for
> segmenting (also saved in EEG.event). In my case I have six different types
> of events in EEG.event which I would like to import into Fieldtrip.
> The output from eeglab2fieldtrip(EEG,’raw’) is
> ft_data1 =
>   struct with fields:
>          elec: [1×1 struct]
>       fsample: 500
>         trial: {1×99 cell}
>          time: {1×99 cell}
>         label: {1×61 cell}
>     trialinfo: [99×2 table]
>           cfg: [1×1 struct]
>
> In general, is it best to import continuous data into Fieldtrip or
> segmented data?
>
> I have another few questions re importing/book-keep the ICA results from
> EEGLAB once I import my data into Fieldtrip.
> Is it best to exclude ICs in EEGLAB, then back project onto channels and
> then export the clean channel data into Fieldtrip? How do I keep track of
> the rank/dimensionality of the clean data then? Should I additionally also
> export the ICA results via ft_ICdata = eeglab2fieldtrip(EEG, 'comp'); and
> save those results separately? In the EEGLAB tutorials it is recommended to
> only mark/flag the ICs but not to reject artefact ICs – if I do that, how
> do get this information across to Fieldtrip?
>
> Thank you for your help.
> Best,
> Luisa
>
> _______________________________________________
> fieldtrip mailing list
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
> https://doi.org/10.1371/journal.pcbi.1002202
>
>
> _______________________________________________
> fieldtrip mailing list
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
> https://doi.org/10.1371/journal.pcbi.1002202
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20220331/7d2c24be/attachment.htm>


More information about the fieldtrip mailing list