<div dir="ltr"><div>Dear Duru,</div><div><br></div><div>1) Yes, cfg.trials does not work on ft_preprocessing, so you will end up concatinating ntrials x ntrials :-). I thought you would be using ft_timelockbaseline (but even there isn't a cfg.trials option. My bad. I'll make up for it below :-))<br></div><div>2) After appending data, the .sampleinfo field is removed, and no reference to the original data is made, as it is done by ft_databrowser to plot the events from the original data (who gets some info from the .cfg field as well, i.e. the original file). This is because typically appending data goes over several datasets, and references to 1 original file doesn't make sense anymore.</div><div>3) About baseline correcting with other data, i.e,. outside of the trial duration; It seems in general you would benefit from just making your own baseline correction, which will solve all your issues and is pretty simple.</div><div><br></div><div>For example (there are many ways, but this would be my way) you could do the following in which you preprocess and epoch both the baseline period, and trail period (including any other 'baseline' pre-stim period) separately<br></div><div><br></div><div>% preprocess data as you did before<br></div><div>cfg = [];</div><div>cfg.trl = 'your data trl'<br></div><div>
data_base_end_E = ft_preprocessing(cfg);</div><div><br></div><div>% preprocess only your baseline periods</div><div>cfg = [];</div><div>cfg.trial = 'your "BaselineWindow" however you want to define it, including an arbitrary offset, say 0; Of course the same amount of trials as your data'<br></div><div>data_baseline = ft_preprocessing(cfg);</div><div><br></div><div>% Calculate baseline value, i.e. the mean of the baseline period</div><div>for itrial = 1 : size(data_baseline.trial,2)</div><div>  baseline{itrial} = mean(data_baseline.trial{itrial})</div><div>end<br>

</div><div><br></div><div>% now just divide your data with the baseline value, or subtract for absolute baseline, or make a ratio, whatever you want.</div><div>
data_base_end_E_baseline = 
data_base_end_E;



</div><div>for itrial = 1 : size(
data_base_end_E.trial,2) <br></div><div>  
data_base_end_E_baseline.trial{itrial} = 
data_base_end_E.trial{itrial} / baseline{itrial};</div><div>end</div><div><br></div><div>Doing it like this, also allows you even to extract baselines of unequal duration is you want to. I now realize though that by preprocessing your data separately, you might introduce differences in e.g. filtering between the baseline period and the trial data, especially when using short and variable trial lengths for either. So, even better would be to preprocess you data first as one trial, and then use ft_redefine trials to separate it in either baseline and baseline+data. Let's write it out:</div><div><div><br></div><div>----------</div><div><br></div><div>% preprocess all your data as one trial, i.e. without epoching:<br></div><div>cfg = [];</div><div>cfg.dataset = 'your datafile';</div><div>cfg.hpfilter = ... etc...</div><div>...<br></div><div>all_data = ft_preprocessing(cfg);</div>

</div><div>



</div>
<div><br></div><div>% epoch your trial data<br></div><div>cfg = [];</div><div>cfg.trl = 'your data trl'<br></div><div>
data_base_end_E = ft_redefinetrial(cfg,all_data);</div><div><br></div><div>% preprocess only your baseline periods</div><div>cfg = [];</div><div>
cfg.trl = your "BaselineWindow" trl, however you want to define it, including an arbitrary offset, say 0; Of course the same amount of trials as your data<br></div><div>data_baseline = 
ft_redefinetrial

(cfg,all_data);</div><div><br></div><div>% The rest is the same as above:</div><div><br></div><div>% Calculate baseline value, i.e. the mean of the baseline period</div><div>for itrial = 1 : size(data_baseline.trial,2)</div><div>  baseline{itrial} = mean(data_baseline.trial{itrial})</div><div>end<br>

</div><div><br></div><div>% now just divide your data with the baseline value, or subtract for absolute baseline, or make a ratio, whatever you want.</div><div>
data_base_end_E_baseline = 
data_base_end_E;



</div><div>for itrial = 1 : size(
data_base_end_E.trial,2) <br></div><div>  
data_base_end_E_baseline.trial{itrial} = 
data_base_end_E.trial{itrial} / baseline{itrial};</div><div>end</div><div><br></div>

<div>----------</div><div><br></div><div>This should take care of treating all data the same, and especially allows you e.g. to define a nice high-pass filter on all your data at once. There might be a typo in the code, but I how you get my idea.<br></div><div><br></div><div>Hope this helps,</div><div>Stephen<br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Op vr 20 sep. 2019 om 08:35 schreef Duru Gun Ozkan <<a href="mailto:durugun.ozkan@uniroma1.it">durugun.ozkan@uniroma1.it</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Dear Stephen,<div><br></div><div>Thank you for your response. It seemed like your suggestion helped, but I thave another potential issue now.</div><div>The problem is, when I use <i>ft_databrowser </i>to visualise the trials after baseline corection loop, I can no longer see the markers, even if I add <i> cfg.plotevents  = 'yes'</i>. I can see that this information exists in the data structure, so I'm not sure if this is a problem per se. But the bigger issue is, after running these loops, the data becomes very large (even after being appended), impossible to save, and slows down the rest of my analysis, where regular baseline correction doesn't cause this. </div><div><br></div><div> Any ideas where I might be going wrong? I suspect I might have used the wrong kinds of brackets, but the curly brackets as in your suggestion caused an error about cell structures, and when I run it as I wrote, the data structures actually look fine.Or it might be the way that I made a loop to append the data, instead of spelling it out for all of the 360 trials.</div><div><br></div><div>Another somewhat related question, is it possible to have the baseline window outside of the defined trial length? </div><div><br></div><div> Here is what I did:</div><div><br></div><div> for trial_index = 1:360<br>          <br>     cfg                = [];<br>     cfg.demean         = 'yes';<br>     cfg.baselinewindow = [BaselineWindow(trial_index,1) BaselineWindow(trial_index,2)];<br>     cfg.trials         = trial_index;<br>     bl_end_E(trial_index)  = ft_preprocessing(cfg, data_end_E);<br>     <br> end      <br> </div><div>%% This results in the struct:</div><div> bl_end_E =   1×360 struct array with 8 fields:<br>    hdr<br>    fsample<br>    trialinfo<br>    sampleinfo<br>    trial<br>    time<br>    label<br>    cfg</div><div><br></div><div>%% Then I append the data:<br> data_base_end_E = bl_end_E(1);<br> <br> for trial_ind = 2:360<br>          <br>     cfg                 = [];<br>     cfg.keepsampleinfo  = 'yes';<br>     data_base_end_E     = ft_appenddata(cfg,data_base_end_E,bl_end_E(trial_ind));<br><br> end<br> </div><div>%% This results in losing hdr and fsample fields: data_base_end_E =   struct with fields:<br><br>         label: {29×1 cell}<br>     trialinfo: [360×4 double]<br>    sampleinfo: [360×2 double]<br>         trial: {1×360 cell}<br>          time: {1×360 cell}<br>           cfg: [1×1 struct]<br>%% So I add them back:</div><div>  base_end_E.hdr = data_end_E.hdr;<br>  base_end_E.fsample = data_end_E.fsample;<br><br></div><div>    %% Visual data inspection <br>    cfg                   = [];<br>    cfg.viewmode  = 'vertical'; <br>    cfg.continuous = 'no'; <br>    cfg.blocksize   = 1.5;<br>    cfg.channel     = {'all'}; <br>    cfg                   = ft_databrowser(cfg,data_base_end_E);<br></div><div><div><br></div><div><br></div><div>Thanks again for the help!</div><div><br></div><div>Duru</div><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><i style="font-size:12.8px">Duru G</i><span style="font-family:Calibri,sans-serif;font-size:14.6667px;text-align:justify"><i>ü</i></span><i style="font-size:12.8px">n </i><span style="font-family:Calibri,sans-serif;font-size:14.6667px;text-align:justify"><i>Ö</i></span><i style="font-size:12.8px">zkan</i><div style="font-size:12.8px"><span style="font-size:12.8px"><i><br></i></span></div><div><div style="font-size:12.8px;color:rgb(136,136,136)"><font size="1" face="trebuchet ms, sans-serif"><b>Ph.D. student in Cognitive Social and Affective Neuroscience.<br></b></font></div><div style="font-size:12.8px;color:rgb(136,136,136)"><font size="1" face="trebuchet ms, sans-serif"><b>Department of Psychology.<br>University of Rome "La Sapienza".<br>Via dei Marsi 78 - 00185 - Roma.</b></font></div><div style="font-size:12.8px;color:rgb(136,136,136)"><font size="1" face="trebuchet ms, sans-serif"><b> </b></font><b style="font-family:"trebuchet ms",sans-serif;font-size:x-small">e-mail: <a href="mailto:vanessa.era@uniroma1.it" style="color:rgb(17,85,204)" target="_blank">durugun.ozkan@uniroma1.it</a></b></div><div><font size="1" color="#1155cc"><u><a href="https://agliotilab.org/lab-staff/phd-students/2nd-year#anchor" target="_blank">https://agliotilab.org/lab-staff/phd-students/2nd-year#anchor</a></u></font><br></div></div><div><font size="1" color="#1155cc"><br></font></div><div>> Hi Duru,<br><br>>   Use cfg.trials = trial_index<br>>   Put the output in a struct, i.e. bl{trial_index}<br>>   Then combine with ft_append_data([],bl{:});<br><br>>   Hope this helps,<br>>   Stephen<br><br><br>>   On Tue, 17 Sep 2019, 19:30 Duru Gun Ozkan, <<a href="mailto:durugun.ozkan@uniroma1.it" target="_blank">durugun.ozkan@uniroma1.it</a>><br>>   wrote:<br><br>> Hi everyone,<br>><br>> I have a question regarding specifying a different baseline correction<br>> time for each trial in ft_preprocessing.<br>> I had 360 audio stimuli all of which had different lengths. My trigger is<br>> located at the end of each stimuli, and I would like to place the baseline<br>> correction between 200 ms before stimulus start and stimulus start.<br>> I have a matrix for cfg.baselinewindow called BaselineWindow such as this:<br>> -1.83018 -1.630182<br>> -1.69807 -1.498071<br>> -0.58653 -0.38653<br>> -1.07604 -0.876039<br>> -2.2608 -2.060803<br>> -0.80863 -0.608632<br>> -1.55663 -1.356629<br>> -0.94261 -0.742605<br>> -1.20845 -1.008448 ...<br>> I tried to create a loop:<br>><br>> for trial_index = 1:360<br>><br>>      cfg = [];<br>>      cfg.demean        = 'yes';<br>>      cfg.baselinewindow = [BaselineWindow(trial_index,1)<br>> BaselineWindow(trial_index,2)];<br>><br>>      data_baselined_end_E = ft_preprocessing(cfg, data_end_E);<br>><br>>  end<br>><br>> This didn't work because it kept running the preprocessing with all the<br>> baselines with all trials, instead of keeping to its specific trial.<br>><br>> My question is, is there another way to specify individual baselines for<br>> individual trials? Or can anyone suggest to improve this loop to have the<br>> data preprocessed with its specific baseline windows?<br>><br>> Thank you in advance.<br>><br>> Best,<br>><br>>  <br><font size="1" color="#1155cc"><br></font></div></div></div></div></div></div></div></div></div>
</blockquote></div>