Read data structure-contd

Shantanu Ghosh sghosh at HSS.IITD.AC.IN
Tue Feb 27 05:59:57 CET 2007


Hello Christian,
Sorry to use this mail id, but the Listserv server was temporarily
unavailable from my IP address.

> Hi Shantanu
>
>> My data is  116384 datapoints long sampled at 115.34 Hz.
>> I can load my data data structure not in FT list)from single
>> subject in a
>> single recording session( in matlab workspace and implement the
>> following
>> code as suggested:
>>
>> data = [];
>>> data.fsample = 115.34
>>> data.label = {'Fz';'Fp1'; ... 'Oz'};
>>> data.trial = cell(Ntrial,1);
>>>  for i=1:Ntrial
>>>         data.trial{i} = 24 x 40
>>>  end
>>
>> However, at the prompt it says:
>>
>> Data structure not compatible. Error in matrix location or matrix
>> dimension.
>
> comment 1:
> the data structure also needs a (local) time axis for each trial:
>
> data.time = cell(Ntrial,1)
> for i=1:Ntrial
>         data.time{i} = [trial_start:dt:trial_stop];
>         % trial_start could be -1.5 seconds
>         % trial_stop could be 3.0 seconds
>         % dt = 1./data.fsample;
> end
>
>
>> My question is, how do you create the Nchan (=24) X NTrialSamp (=
>> 40 trials)
>> matrix from continuous data?
>
> comment 2:
> NTrialSamp is NOT the number of trials (NTrial = 40) but instead
> refers to the "Number_of_time_samples_per_trial" which is determined
> by the duration of the trial in seconds (TrialDuration) and your
> sampling frequency FSample:
>
> NTrialSamp = TrialDuration*FSample;
> % this can in principle be different for each trial
>
> % so you have
> data.trial = cell(Ntrial,1)
> for i=1:Ntrial
>         data.trial{i} = X;
>         % where X is a Nchan x NTrialSamp matrix containing the data from
> each trial
> end
>
>
> comment 3:
> Your question essentially is: How do youI get X from what you have
> read into Matlab?
>

>
> To answer this, you need to tell me what sort of variable your data
> are stored in once they have been read into Matlab. You can load your
> data in and then type "whos" at the command prompts and email me what
> is displayed on the screen after you press <ENTER>

> Reply to comment 3:

This is what is displayed at 'whos' command after the data is loaded:
>> y=dlmread('C:\\priyanka\\exp1\\SegmentedEEGData\\S1\\audi\\A1
\\1_E_1.txt');

>> whos
  Name      Size                    Bytes  Class

  y       347x1                      2776  double array

Grand total is 347 elements using 2776 bytes

>>
Additional comments:
The file is a 3 sec EEG voltage record from our experiment on episodic
memory encoding and recall in auditory mode ('Process'), for subject 'S1'
for electrode 'A1'. '1_E_1' refers to 'BlockNum_Process_TrialNumber'. The
experiment has the following design:

After displaying a blank screen for 1 min, a 4 sec red spot in the centre
of the screen alerts the subject that a CVC syllable is presented (trial).
There are 6 trials, each 
of 3 sec duration, followed by another green spot
in screen centre for 4 s to alert the subject that recall is to be
effected, followed by 6 trials of CVC sequences each of 3 sec, but only
half of them from the earlier encoding block. this [encoding-recall]
sequence is repeated for 20 times. All CVC sequences in encoding and
recall were randomised. EEG was acquired continuously.
The continuous EEG was then segmented stored in separate .txt files using
a Matlab routine (see attached file: 'mySegmentData.m').
One of these files is then loaded using 'dlmread'.
I also have the continuous EEG as .txt files for each electrode, as
separate files in a folder [say, called subject 'S1','S2',... ] (if you
require that data to get X)
Best and thanks,
Shantanu


-------------- next part --------------
% This codes segments the data of each subject for a specific mode
% (Auditory or Visual) and a specific channel depending on the stimulus,
% block and the process.
%
% Format of the Data File provided: Subject_Mode_eeg_Channel
%  Subject = S1, S2, S3, S4, S5, S6, S7, S8, S9, S10
%  Mode = audi (for Auditory), visu (for Visual)
%  Channel = F3, F4, F7, F8, T3, T4, T5, T6, P3, P4, Pz, O1, O2, Oz,
%  FP1, FP2, Fz, C3, C4, Cz, A1, A2, EKG
%
% Format of the Data File Outputted: Block_Process_Stimulus
%  Block = 1, 2,..., 10
%  Process = E (for Encoding), R (for Retrieval)
%  Stimulus = 1, 2, 3, 4, 5, 6

clc;
close all;
clear all;

SamplingTime = 0.00867; % in secs
InitialTime = 60; % in secs
GapTime = 4; % in secs
nBlocks = 10; % Number of Blocks
BlockTime = 18; % in secs
Process = {'E'; 'R'}; % Processes (E - Encoding; R - Retrieval)
nStimuli = 6; % Number of Stimuli
StimulusTime = 3; % in secs

% Subjects_Modes = {'Subject','Mode'}
%  Subjects = S1, S2, S3, S4, S5, S6, S7, S8, S9, S10
%  Modes = audi (for Auditory), visu (for Visual), both (for Both)
% Subjects_Modes = {'S1','both'; 'S2','both'; 'S3','both'; 'S4','both';...
%     'S5','both'; 'S6','both'; 'S7','both'; 'S8','both'; 'S9','both'; 'S10','both'};
Subjects_Modes = {'S1','both'; 'S2','both'; 'S3','both'; 'S4','both';...
    'S5','both'; 'S6','both'; 'S7','visu'; 'S8','both'; 'S9','both';...
    'S10','both'};

% Channels = {'F3'; 'F4'; 'F7'; 'F8'; 'T3'; 'T4'; 'T5'; 'T6';...
%     'P3'; 'P4'; 'Pz'; 'O1'; 'O2'; 'Oz';...
%     'FP1'; 'FP2'; 'Fz'; 'C3'; 'C4'; 'Cz'; 'A1'; 'A2'; 'EKG'};
Channels = {'F3'; 'F4'; 'F7'; 'F8'; 'T3'; 'T4'; 'T5'; 'T6';...
    'P3'; 'P4'; 'Pz'; 'O1'; 'O2'; 'Oz';...
    'FP1'; 'FP2'; 'Fz'; 'C3'; 'C4'; 'Cz'; 'A1'; 'A2'; 'EKG'};

for i = 1:size(Subjects_Modes,1) % Runs over all the Subjects
    Subject = Subjects_Modes{i,1};
    if Subjects_Modes{i,2} == 'both'
        Mode = {'audi'; 'visu'};
    else
        Mode = {Subjects_Modes{i,2}};
    end
    for j = 1:length(Mode) % Runs over all the Modes
        for k = 1:length(Channels) % Runs over all the Channels
            filename = ['eegdata','\',Subject,'\',Subject,'_',Mode{j},'_eeg_',Channels{k},'.eeg'];
            fid = fopen(filename); % Open a file
            if fid == -1
                break
            end
            entiredata = fscanf(fid,'%f'); % Read data from the file
            fclose(fid);

            directoryname = ['SegmentedEEGData','\',Subject,'\',Mode{j},'\',Channels{k}];
            mkdir(directoryname); % Create a directory
            entiredata = entiredata(round(InitialTime/SamplingTime):end);
                % Eliminate the first 1 min of the data
            flag = -1; % Flag for determining the process (E or R)
            for a = 1:2*nBlocks % Runs over all the blocks (both E and R)
                flag = -1*flag; % Toggle the flag
                if flag == 1
                    c = 1; % E Process
                else
                    c = 2; % R Process
                end
                for b = 1:nStimuli % Runs over all the Stimuli
                    l = round((a*GapTime + (a-1)*BlockTime + (b-1)*StimulusTime)/SamplingTime);
                    h = round((a*GapTime + (a-1)*BlockTime + b*StimulusTime)/SamplingTime);
                    data = entiredata(l:h);
                    filename = [directoryname,'\',num2str(a),'_',Process{c},'_',num2str(b),'.txt'];
                    fid = fopen(filename,'w'); % Open a file
                    if fid == -1
                        break
                    end
                    fprintf(fid,'%f\n',data); % Write data to a file
                    fclose(fid);
                end
            end
        end
    end
end
display('Files successfully segmented!')





More information about the fieldtrip mailing list