[FieldTrip] read tfcs from BESA in Fieldtrip

Epstein, Michael MEpstein at NKI.RFMH.ORG
Thu Jan 24 16:42:43 CET 2013

My lab needed to do the same thing. After communicating with BESA, they
sent a function to do just that. (I also wrote one custom for our data).
I'm adding the code BESA sent to this email. If you want, email me
separately and I'll send other code as well. 

Hope this works for you :)



function tfc_data = readBESAtfcs(filename)

% readBESAtfcs reads single trial TFC data exported from BESA Research.
% Use as
%   tfc = readBESAtfcs(filename)
% The output is a structure containing a 3D matrix with complex numbers 
% for every trial. The size of the matrix is 
% [NChannels x NFreqSamples x NTimeSamples]. 
% Created June 28, 2012 Todor Jordanov

if isempty(findstr(filename,'.'))
  filename = [filename,'.tfcs'];

fp = fopen(filename, 'r');

if (fp)
    tfc_data.trials = {};
    n_trials = 0;
    n_channels = 0;
    n_freqs = 0;

    tline = fgetl(fp);
    tline = strtrim(tline);
    while ischar(tline)
        if(strncmpi(tline, 'Trial', 5))
            n_trials = n_trials + 1;
            n_channels = 0;
            n_freqs = 0;
        elseif(strncmpi(tline, 'Channel', 7))

            n_channels = n_channels + 1;
            n_freqs = 0;

            tline = strtrim(tline);
            tmp = regexp(tline, '\t', 'split');
            n_samples = size(tmp, 2);
            n_freqs = n_freqs + 1;
            for i=1:n_samples
                two_reals = sscanf(tmp{i}, '%f +i* %f');
                tfc_data.trials{n_trials}(n_channels, n_freqs, i) = ...
                    complex(two_reals(1), two_reals(2));
        tline = fgetl(fp);





-----Original Message-----
From: fieldtrip-bounces at science.ru.nl
[mailto:fieldtrip-bounces at science.ru.nl] On Behalf Of Chrysa Lithari
Sent: Thursday, January 24, 2013 10:34 AM
To: fieldtrip at science.ru.nl
Subject: [FieldTrip] read tfcs from BESA in Fieldtrip

Hi to all,

I am trying to read time-frequency single trials from BESA with
The function besa2fieldtrip deals only with tfc files that are averaged
and not with tfcs that contains the single trials.
Has anybody expand this function to read also tfcs files?

thanks in advance,
Chrysa Lithari

fieldtrip mailing list
fieldtrip at donders.ru.nl

Conserve Resources. Print only when necessary.

IMPORTANT NOTICE: This e-mail is meant only for the use of the intended recipient. It may contain confidential information which is legally privilegedor otherwise protected by law. If you received this e-mail in error or from someone who is not authorized to send it to you, you are strictly prohibited from reviewing, using, disseminating, distributing or copying the e-mail. PLEASE NOTIFY US IMMEDIATELY OF THE ERROR BY RETURN E-MAIL AND DELETE THIS MESSAGE FROM YOUR SYSTEM. Thank you for your cooperation.

More information about the fieldtrip mailing list