<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div>Dear Fieldtrip Community,</div>
<div><br>
</div>
<div>my name is Giulio Piperno, and I am working as Ph.D. Student in Cognitive Neuroscience at La Sapienza University of Rome.</div>
<div><br>
</div>
<div>I am new to Fieldtrip, and I am currently using it to analyze the data of an ERP experiment. After the filtering, the segmentation, and the baseline correction,  I encounter a problem with the automatic artifact detection, using the function ft_artifact_threshold</div>
<div><br>
</div>
<div>More specifically, I receive thefollowing  error messages:</div>
<div><br>
</div>
<div>Error using ft_fetch_data (line 165)
<div>some of the requested samples occur twice in the data and have conflicting values</div>
<div><br>
</div>
<div>Error in ft_artifact_threshold (line 183)</div>
<div>    dat = ft_fetch_data(data,        'header', hdr, 'begsample', trl(trlop,1), 'endsample', trl(trlop,2),</div>
    'chanindx', chanindx, 'checkboundary', strcmp(cfg.continuous, 'no'));</div>
<div><br>
</div>
<div><br>
</div>
<div>I suspect the problem is related to the presence of overlapping trials.  The interval between the triggers is 550 ms, and the error message appears only when I try to take segments longer than 550 ms in the segmentation process (E.g. form 250 ms before
 the trigger up to 400 ms after the stimuli). If I reduce the length of the epochs, I receive no error. Unfortunatly, I need to take long segments, because I am interested in both prestimulus (around 250 ms) activity and a peak occurring around 200-400 ms after
 the stimulus<br>
</div>
<div><br>
</div>
<div>However the problem could be rather something related to the baseline correction step:  If I run  ft_artifact_threshold on the data before the baseline correction, I receive no error (even when I take segments with -250 400 ms interval and therefore I
 have overlapping trials)</div>
<div><br>
</div>
<div>I tried to insert the command cfg.allowerlap = "yes" in the preprocessing but it didn't work</div>
<div><br>
</div>
<div><br>
</div>
<div>Could someone tell me if there is something wrong with the cfg settings I 'am using or if I am doing something wrong at any other place? Is there a way to perform both baseline correction and automatic artifact detection on a dataset with partially overlapping
 trials? <br>
</div>
<div><br>
</div>
<div>Here I leave the code I am using:</div>
<div><br>
</div>
<div>%%% FILTERING %%%<br>
</div>
<div>cfg = [];
<div>cfg.bpfilter = 'yes'; <br>
</div>
<div>cfg.bpfiltord = 3 ;<br>
</div>
<div>cfg.bpfreq = [0.1  30];</div>
data_cleaned_filtered = ft_preprocessing(cfg, data )</div>
<div><br>
</div>
<div><br>
</div>
<div>%%% SEGMENTATION %%%</div>
<div><br>
</div>
<div>filename= 'C01.cnt'
<div><br>
</div>
<div>cfg = [];</div>
<div>cfg.dataset = filename</div>
<div>cfg.trialdef.eventtype  = 'trigger'; </div>
<div>cfg.trialdef.eventvalue = 1:1:37; </div>
<div>cfg.trialdef.prestim    = 0.25; % in seconds </div>
<div>cfg.trialdef.poststim   = 0.4; % in seconds</div>
<div>cfg.trialfun            = 'ft_trialfun_general'; </div>
<div>data_trl= ft_definetrial(cfg);</div>
<div>data_trl.trl=round(data_trl.trl)</div>
<div><br>
</div>
<div>cfg = [];</div>
<div>cfg.trl       = data_trl.trl;</div>
data_segmented = ft_redefinetrial(cfg, data_cleaned_filtered);</div>
<div><br>
</div>
<div><br>
</div>
<div>%%%  BASELINE CORRECTION %%%
<div><br>
</div>
<div>cfg          = [];</div>
<div>cfg.demean        = 'yes'; % <br>
</div>
<div>cfg.baselinewindow = [-.25 -.15]; <br>
</div>
data_baseline = ft_preprocessing(cfg, data_segmented);<br>
</div>
<div><br>
</div>
<div>%%% AUTOMATIC ARTIFACT DETECTION %%%</div>
<div><br>
</div>
<div>cfg = [];
<div>cfg.continuous = 'no';</div>
<div>cfg.artfctdef.threshold.channel     = 'EEG';</div>
<div>cfg.artfctdef.threshold.bpfilter     = 'no';</div>
<div>cfg.artfctdef.threshold.max = 100; %value in uV or T, default  inf</div>
<div>cfg.artfctdef.threshold.min = -100; %value in uV or T, default -inf</div>
[cfg, artifact_EEG] = ft_artifact_threshold(cfg, data_baseline);<br>
</div>
<div><br>
</div>
<div>Thanks in advance for your help!</div>
<div><br>
</div>
<div>Best Regards</div>
<div><br>
</div>
Giulio Piperno<br>
</div>
</body>
</html>