Hi Francois,
so, I tried to export Brainstorm data to Fieldtrip. It works pretty well, but I have one concern.
My goal was to obtain epoched data at the sensors level, in a fieldtrip format.
After preprocessing and epoching raw data in Brainstorm, I imported all the epochs in the database. Then, using out_fieldtrip_data in a for loop, I exported every epoch in a single matlab structure.
I added a trial definition, required by fieldtrip, containing 4 columns:
1- starting point of each trial
2- end point of each trial
3- stimulus occurrence
4- a number coding for the experimental condition associated to that trial
Then, if I average and plot all the epochs separately for each experimental condition, both in Brainstorm and in fieldtrip, the averages seem to correspond pretty well.
- Do you think that this is a proper way to export from brainstorm to fieltrip? (I mean, is this a proper way to use out_fieldtrip_data?)
- Would you say that, if the trial definition is correctly written, the exported data are reliable?
- Do you think that the out_fieldtrip_data function could be developed to include a trial definition by default?
I include the script I wrote to do what I described (sorry, it is probably badly written, I am not a programmer)
Cheers,
Rocco
%% Converting epoched data from Brainstorm to Fieldtrip
cond = {‘Cond_A’; ‘Cond_B’; ‘Cond_C’}; % condition names will be associated with a number (first cond = 1, second = 2, …)
ftData=[];
ep_data = [];
for kk = 1:length(sFiles)
ftData=[];
[ftData, ~, ~] = out_fieldtrip_data (sFiles(kk).FileName, sFiles(kk).ChannelFile,[],0);
% This section works and provides a trial definition - For sure it may be coded better
qq= [ftData.time{1,1}];
if kk == 1
prevendtrial = 0;
else prevendtrial = ep_data.cfg.trl((kk-1),2);
end
[~,endtrial] = size(ftData.time{1,1});
ep_data.cfg.trl(kk,2) = endtrial+prevendtrial; % ending point of each trial
ep_data.cfg.trl(kk,1) = prevendtrial+1; % starting point of each trial
ep_data.cfg.trl(kk,3) = (round(abs(qq(1)*(length(qq)/(abs(qq(1))+qq(end))))))+1+prevendtrial; % stimulus occurence
% Assigning the number of the condition to each trial
for ww = 1:length(cond)
if strcmp(sFiles(kk).Condition,cond(ww))
ep_data.cfg.trl(kk,4) = ww;
end
end
% Saving each epoch in the same ep_data file
ep_data.time(1,kk) = ftData.time(1,1);
ep_data.trial(1,kk) = ftData.trial(1,1);
ep_data.grad = ftData.grad;
ep_data.label = ftData.label;
ep_data.dimord = ftData.dimord;
end
%% Check - Averaging, saving avg in ft format, plotting condition avg
for yy = 1 : length(cond)
cfg = [];
cfg.layout = ep_data.grad;
cfg.trials = find(ep_data.cfg.trl(:,4)==yy);
avgCond{yy} = ft_timelockanalysis(cfg, ep_data);
cfg = [];
figure(yy); ft_multiplotER(cfg,avgCond{yy}); colorbar;
end