[FieldTrip] No mtmconvol on data with partial nans

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Wed May 25 15:48:18 CEST 2016

Hi Stephen, 

This is how you could ‘glue’ together the fragments of your trials:

freq.powspctrm(~isfinite(freq.powspctrm)) = 0; % converting the nans to 0 allows for summation

nrpt = numel(unique(freq.trialinfo(:,1))); % assume that the first column of trialinfo is the counter of the original trials

siz  = size(freq.powspctrm);
newpowspctrm = zeros([nrpt siz(2:end)]);

for k = 1:nrpt
  for m = find(freq.trialinfo(:,1)==k)’
    newpowspctrm(k,:,:,:) = newpowspctrm(k,:,:,:)+freq.powspctrm(m,:,:,:);
newpowspctrm(newpowspctrm==0) = nan;

% now you can create your new freq structure with the additional metadata (possibly corrected for the new number of ‘rpt’s.


> On 25 May 2016, at 15:26, Stephen Whitmarsh <stephen.whitmarsh at gmail.com> wrote:
> Hi FieldTrippers,
> I hope someone can help me with the following.
> My problem is that I like to maintain my original rpt/chan/time/freq size after artefact rejection based on the time series data, i.e. to have the same dimensions of the TFR as if I did not reject data. This is for reasons of bookkeeping between different types of channels that are processed differently throughout my analysis.
> What works well is to detect artifacts in the data and replace those intervals with nans using ft_rejectartifact, with cfg.reject = 'nan'. So far this is perfect for the approach I had in mind.
> However, ft_freqanalysis (method = 'mtmconvol') outputs whole trials as nans whenever a (small) period has nans. What I would need - and in fact expect - is that only those time/frequency windows that have (one or more) nan values will output nan, while the rest should merrily go round giving power values. After all, the data is there.
> It is unclear to me whether this is expected behaviour or not. I might be making a mistake but some simple tests replicated this behaviour. 
> Is there a solution that still allows me to end up with a rpt/chan/time/freq representation of the same size as when i would not have rejected artifacts?
> The only other FieldTrip-like option I can think of is to use ft_rejectartifact with method = 'partial', do the freqanalysis on trial parts, and somehow glue the separate trial parts together again afterwards. But I really don't want to go in that direction.
> In the end I'm afraid I don't understand the core of ft_specest_mtmconvol enough to see where I could hack it. I hope some of you might be able to help.
> Best wishes,
> Stephen
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip

More information about the fieldtrip mailing list