import bva time-freq data

Robert Oostenveld r.oostenveld at FCDONDERS.RU.NL
Wed Jul 26 09:46:59 CEST 2006


Hi Stephan,

On 25 Jul 2006, at 17:39, Stephan Bickel wrote:
> I try to import brainvision analyzer dat files of wavelet time-
> frequency
> decompositions into fieldtrip. I exported an average file, so it
> consists
> only of a single segment. However I have some problems with it I am
> not sure
...
> cfg.trialdef.trgfile  = 'c:\HumanEEG_data\Vision_Exports
> \WT_all_ft_test.vmrk';
> cfg.trialdef.stim  = 'New Segment';
> %cfg.trialdef.segment  = 'yes';
> cfg.trialdef.timezero = 'yes';
> % cfg.trialdef.eventtype  = 'Time 0';

In general I would recommend to use the trialfun_general instead of
the trialfun_brainvision (but the latter should also work). The
trialfun_general was written later and will work for any dataformat
that is supported by read_fcdc_event, the trialfun_brainvision is
only there to support old scripts (i.e. scripts that predate the
read_fcdc_event function).

If not specified manually as trialfun, the trialfun_general or
trialfun_brainvision is selected automatically based on the cfg
settings. In your case you could do
    cfg.trialdef.eventtype  = 'New Segment' or 'Time 0'
    cfg.trialdef.prestim    = number, latency in seconds (optional)
    cfg.trialdef.poststim   = number, latency in seconds (optional)
See teh help of DEFINETRIAL.

But in your case this is not the problem. The problem lies in
> cfg.trialdef.prestim    = 0.500;
> cfg.trialdef.poststim   = 1.600;

If I do
   event = read_fcdc_event('WT_all_ft_test.vmrk')
then I see that

 >> event(1)
ans =
         type: 'New Segment'
        value: '1'
       sample: 1
     duration: 0
       offset: []

 >> event(2)
ans =
         type: 'Time 0'
        value: '251'
       sample: 1
     duration: 0
       offset: []

The 'New Segment' event is at sample 1, hence you cannot select a
500ms pre-stimulus window before it (you cannot read before the
beginning of the data). The alternative 'Time 0' event is also at
sample 1. It specifies a value of 251, which surprises me. I would
expect that event to be present at sample 251.

Reading the marker file with a text editor, I see (abbreviated) the
explanation
    Mk<number>=<Type>,<Description>,<Position>,<Size>,
<Channelnumber>,<Date>
and the markers
    Mk1=New Segment,,1,1,0,00000000000000000000
    Mk2=Time 0,,251,1,0
So Mk2 should indeed be at sample 251.

With the matlab debugger in the private/read_event.m file (around
line 164) I notice that the problem lies in the missing value of the
second field, i.e.
    Mk2=Time 0,,251,1,0
is interpreted as
    Mk2=Time 0,251,1,0  (one comma less)
All fields are shifted by one, resulting in the sample number being
interpreted as the description (i.e. value).

I have fixed it in read_event, by replacing line 151 from
   tok = tokenize(line, '=');
into
   tok = tokenize(line, '=', 0);  % do not squeeze repetitions of the
seperator
and by replacing line 157 from
   tok = tokenize(tok{2}, ',');
into
   tok = tokenize(tok{2}, ',', 0);    % do not squeeze repetitions of
the seperator
i.e. both calls to the tokenize function now use the third argument.
You can apply the same change to your copy, but please check that you
have an up to date version of tokenize that accepts 3 input arguments
(tokenize is in private as well). I will include the bug fix in the
upcoming nightly release of FieldTrip. Better upgrade tomorrow to the
latest FT version from the FTP server.

I think that sofar it was not noticed since people here at the
Donders typically use triggers as markers in their Brainvision data,
and in case of triggers the second field would not be empty.

If I now do
   cfg = [];
   cfg.dataset = 'WT_all_ft_test.vhdr'
   cfg.trialdef.eventtype = 'Time 0'
   cfg.trialdef.prestim  =  0.5000
   cfg.trialdef.poststim =  1
   cfg = definetrial(cfg)
I get
   evaluating trialfunction 'trialfun_general'
   found 2 events
   created 1 trials
   cfg =
        dataset: 'WT_all_ft_test.vhdr'
       trialdef: [1x1 struct]
       datafile: []
     headerfile: 'WT_all_ft_test.vhdr'
       trialfun: 'trialfun_general'
          event: [1x2 struct]
            trl: [1 750 -250]
        version: [1x1 struct]
which is correct. The trial (cfg.trl) runs from sample 1 to sample
750 in the data file, and the first sample of that trial corresponds
with time cfg.trl(1,3)/fsample=-0.500 seconds.

Thanks for reporting the bug,
Robert



More information about the fieldtrip mailing list