[FieldTrip] generic data format

Roemer van der Meij r.vandermeij at donders.ru.nl
Mon Sep 23 14:48:57 CEST 2013

Hi Alex,

Sorry for the late response.
With regards to the first question, all filtering frequencies should be
specified in Hz. So, if you want a low pass at 10Hz, a high pass at 100Hz,
and a band-stop between 59 and 61 Hz, you should specify (which likely
fixes the error):
cfg.lpfreq        = 100
cfg.hpfreq        = 10
cfg.bsfreq        = [59 61]
Padding should be specified as the total number of seconds of each trial,
and (200-30)/2 seconds on each side seems a bit rigorous for removing
filtering artifacts ;). Unless you were intentionally using a low pass of
10/500 = 0.02 Hz. The longer the impulse response of the filter, the more
padding is needed to remove edge artifacts. (A 4th order butt of a very low
low-pass would have the IIR's filters version of an impulse response that
is very very long). In general, when using the above suggested filtering
frequencies and a 4th order butterworth and a sampling of 500Hz, a few
seconds of padding on both sides of the trial will likely be enough to
prevent edge artifacts.

However, when importing an unsupported data format, you cannot make use of
data-padding, which is the most optimal one. You could opt for
zero/mean/mirror padding, but they add transition artifacts, which might be
even worse than your edge-artifacts. Don't use these unless it's really the
only option, and be careful when doing so. My suggestion in your case would
be to segment the data (during importing) with additional data, and remove
this data after filtering, by hand (take care to adjust not only
data.trial, but also data.time). So, if trial #2 would last from 30 to 60
seconds, segment it from 25 to 65, filter it, and remove the first 5 and
the last 5 seconds. This will, of course, create issues if you want to use
the first 5 seconds of data.

With regards to your second question, the error suggests you used an
improper cfg.pad option. I don't see this in your code though, are you
absolutely sure you didn't include a cfg.pad? This should be specified in
seconds, which is the total length of each trial + padding. If left out,
this defaults to the length of the largest trial. Note though, this refers
to zero padding for spectral interpolation. Also, the option cfg.tapsmofrq
is only used if you specifiy cfg.taper = 'dpss'. It isn't used when using
cfg.taper = 'hanning'.


On Thu, Sep 12, 2013 at 5:54 PM, Alexander Reyes <reyesale at usc.edu> wrote:

> Hello,
> I am having some difficulty getting my data into a format that can be read
> by FieldTrip correctly. I apologize in advance for the length of this e
> mail. This is actually a two part question.
> 1. The data I am trying to analyze consists of electrocorticography (ECoG)
> data rather than EEG or MEG and was collected with a system not supported
> by FieldTrip. My raw data are segmented into 30 second trials (22 in total)
> and arranged into columns representing 76 ECoG and 8 EMG channels and
> sampled at 500 Hz. There are no markers or triggers in my data as of now
> since this is preliminary data. Additionally, I have not removed any
> artifacts from the data nor have I redefined any trials.
> Following the FAQ for importing a generic data format, I have successfully
> created the following structure:
> data.label =          subjectData.Labels;
> data.fsample =     subjectData.Fs;
> data.trial =         subjectData.TrialData;
> data.time =          subjectData.Ref;
> I have fed this data into the ft_preprocessing.m function with the
> configuration shown below.
> cfg = [];
> cfg.channel       = 'C*';
> cfg.lpfilter      = 'yes';
> cfg.hpfilter      = 'yes';
> cfg.bsfilter      = 'yes';
> cfg.lpfreq        = 100/data.fsample;
> cfg.hpfreq        = 10/data.fsample;
> cfg.bsfreq        = [59 61]/data.fsample;
> cfg.lpfiltord     = 4;
> cfg.hpfiltord     = 4;
> cfg.bpfiltord     = 4;
> cfg.lpfilttype    = 'but';
> cfg.hpfilttype    = 'but';
> ecog = ft_preprocessing(cfg,data);
> The generated file filters the data correctly, but there are edge effects
> so I would like to pad the data. However, when I insert the two extra lines
> shown below and then run ft_preprocessing, I get the error that follows.
> cfg.padding       = 200;
> cfg.padtype       = 'data';
> Error using butter (line 83)
> butter: critical frequencies must be in (0 1)
> Error in ft_preproc_lowpassfilter (line 93)
>     [B, A] = butter(N, max(Flp)/Fn);
> Error in preproc (line 297)
> if strcmp(cfg.lpfilter, 'yes'),     dat = ft_preproc_lowpassfilter(dat,
> fsample, cfg.lpfreq, cfg.lpfiltord, cfg.lpfilttype,
> cfg.lpfiltdir, cfg.lpinstabilityfix); end
> Error in ft_preprocessing (line 323)
>     [dataout.trial{i}, dataout.label, dataout.time{i}, cfg] =
> preproc(data.trial{i}(rawindx,:), data.label(rawindx),  data.time{i},
>     cfg, begpadding, endpadding);
> I would appreciate some help as to why the padding does not work for my
> data set.
> 2. In an attempt to keep moving forward, I have bypassed the padding and
> tried to do a simple frequency analysis using the following configuration:
> cfg = [];
> cfg.method = 'mtmfft';
> cfg.output = 'pow';
> cfg.foi = [1:30];
> cfg.taper = 'hanning';
> cfg.t_ftimwin = 4./cfg.foi;
> cfg.toi = 0:0.5:30;
> cfg.tapsmofrq = 4;
> freq = ft_freqanalysis (cfg,ecog);
> But I get the following error:
> Error using ft_specest_mtmfft (line 75)
> the padding that you specified is shorter than the data
> Error in ft_freqanalysis (line 503)
>       [spectrum,ntaper,foi] = ft_specest_mtmfft(dat, time, 'taper',
> cfg.taper, options{:}, 'feedback', fbopt);
> I was wondering if I could get some help decrypting this error message.
> Thank you in advance.
> Alex.
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip

Roemer van der Meij M.Sc.
PhD Candidate
Donders Institute for Brain, Cognition and Behaviour
Centre for Cognition
P.O. Box 9104
6500 HE Nijmegen
The Netherlands
Tel: +31(0)24 3655932
E-mail: r.vandermeij at donders.ru.nl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20130923/3b0491c0/attachment-0002.html>

More information about the fieldtrip mailing list