Hello Sally,
I did manage to over come the problem.
I added this line to the script:
D.events.types=[1];
I don't know if/ what is the fundamental difference between :
D.events.types and D.events.type. Perhaps they have the same function and
it's just a typo?
I added several more things to the script:
D.data=[]
D.events.blinks = zeros(1, D.events.Ntypes);
D.events.repl=150;
Also note that although the number of samples (D.Nsamples) is X,
the total: D.events.start+ D.events.stop, should add up to X-1.
D.Nsamples = 154;
D.events.start = 25
D.events.stop = 128; %154-25-1
And another important thing: EOG channels should always be at the end of
the converted data file.
-I didn't export additional EXG channels (like nose, mastoids), I think
additional modifications are needed for this.
I am sending the script I use, I wrote 'CHANGE' by the lines I added or
changed.
The script receives a directory containing all the .dat , .vhdr files
created by Analyzer. Each analyzer data-file is an average of 1 condition
for 1 subject.
Good luck,
Yael.
----------------
Hello Yael,
My name is Sally, I'm a PhD student at Nottingham University, UK. I read
your email from the spm archive regarding the use of the averaged EEG data
by Analyzer software in spm5. We managed to convert the averaged data to
SPM (.mat and .dat files) but it gives us the same error you got when using
the 2D interpolation.
??? Reference to non-existent field 'types'.
Error in ==> spm_eeg_convertmat2ana at 78
Itrials = find(D{k}.events.code == D{k}.events.types(i) & ~D
{k}.events.reject);
Error in ==> spm_eeg_TF_images at 206
spm_eeg_convertmat2ana(S);
??? Error while evaluating uicontrol Callback.
I wonder if you made any further progress in this (since I saw you had
questions on later steps in the processing on the mail list).
Sorry for any inconvenience. Thank you very much for any help.
Regards,
Sally
--1:-?Dc8(7XUlfFi.bFkj+SC.TIDqS3wGDB+ZQ-qyyQ-BWQymjUzRt(b7ijVZ?z,:+-Gaq)
Content-Transfer-Encoding: 7bit
Content-Type: TEXT/PLAIN;
name="meeg_read_data_Analyzer.m"
% This is an example script to convert epoched and averaged data (ERP/ERF)
% to SPM format. Please adapt to your needs.
%The script receives a directory containing all the .dat , .vhdr files
%created by Analyzer and converts them to SPM format.
%Modified by Yael Weisberger HCNL-HUJI
clear all
%-----------------------------------
% part 1: information about the data
%-----------------------------------
% change the following values according to your data
%to make life easier evrey variable you need to change will be marked by
%[*UPDATE_VAR*]
%%[*UPDATE_VAR*]- the name of the directory containing all the .dat , .vhdr files
INPUT_DIRECTORY_NAME='L:\Methodology\SPM\testing_tool\Yael\try\MMN_Dyslexia_data\Data';
%--------------------------------------------------------------------------
INPUT_DIR = dir([INPUT_DIRECTORY_NAME,'\*.dat']);
for i = 1: length(INPUT_DIR)
DATA_FILE=INPUT_DIR(i).name ;
% %[*UPDATE_VAR*]- sampling rate in Hz (usually 256)
D.Radc = 256;
% %[*UPDATE_VAR*] -Number of time bins in peri-stimulus time
D.Nsamples = 154; %header says 154 but SPM read 155
%%[*UPDATE_VAR*]- Number of ERPs (if you export avraged data, this is 1)
D.Nevents = 1;
% %[*UPDATE_VAR*]- channel template file
D.channels.ctf = 'biosemi_only32.mat'; %from:K:\CommonResources\Tools\Matlab_Tools\spm5\EEGtemplates
%%[*UPDATE_VAR*]- Names of channels in order of the data in analyzer, EOG
%%should always be at the end
D.channels.name = { 'Fp1', 'AF3', 'F7', 'F3', 'FC1', 'FC5', 'T7', 'C3', 'CP1', 'CP5', 'P7' , 'P3', 'Pz', 'PO3', 'O1' , 'Oz' , 'O2' , 'PO4', 'P4', 'P8' , 'CP6' , 'CP2', 'C4' , 'T8' , 'FC6' , 'FC2', 'F4' , 'F8' , 'AF4' , 'Fp2' , 'Fz' , 'Cz','VEOG', 'HEOG'};
Analyzer_EOG_Order_FLAG= 1; %if the EOG channels in the Analyzer foramt ( .dat) are are at the
% begining of the list flag=1, if at the end flag=0
D.Nchannels = length(D.channels.name);
%D.Nchannels.exg=[36 37]; %CHANGE: 23.1.06
% %[*UPDATE_VAR*]index vector of bad channels
D.channels.Bad = [];
% %[*UPDATE_VAR*]- nr of time bins before stimulus onset (this excludes the time bin at
% zero)
D.events.start = 25;% 100/3.9 %change from:26 to 25, since I get an error in the display- no match between num of events and data. I can also do the change in spm_eeg_display_ui
% %[*UPDATE_VAR*]- nr of time bins after stimulus onset (this excludes the time bin at
% zero)
D.events.stop = 128; %154-26
% name of SPM mat file
D.fname = [strtok(DATA_FILE,'.'),'_SPM.mat'];
D.modality = 'EEG';
D.units = '\muV';
D.data=[]; % CHANGE 23.1.06
%-------------------------------------
% Don't change these
D.channels.reference = 0;
D.channels.ref_name = 'none';
%D.channels.exg=[ 35 36 37];%CHANGE: 23.1.06: m2,m1
D.events.type = [1:D.Nevents];
D.events.Ntypes = length(D.events.type);
D.events.code = [1:D.Nevents];
D.events.reject = zeros(1, D.events.Ntypes);
D.events.blinks = zeros(1, D.events.Ntypes); %CHANGE: 23.1.06
D.events.time=[];
D.events.types=[1];
AveragedSegments_DEFAULT=150; %CHANGE: 23.1.06
D.events.repl=AveragedSegments_DEFAULT; %CHANGE number of segments avreged together
%finding AveragedSegments field in vhdr file, for D.events.repl %ADDED
%13.2.06
header_file=[ INPUT_DIRECTORY_NAME,'\',strtok(DATA_FILE,'.') , '.vhdr'];
file_lines=textread(char(header_file),'%s','delimiter','\n','whitespace','');
i=1;
while ( isempty(strfind(file_lines{i},'AveragedSegments')) ) & (length(file_lines)>i)
i=i+1;
end
if ~isempty(strfind(file_lines{i},'AveragedSegments'))
[tmp,num_seg] = strtok(file_lines{i},'=');
num_seg=num_seg(2:length(num_seg));
D.events.repl=[str2num(num_seg)];
else
warning('no AveragedSegments field in file');
end
D.path = fileparts(D.fname); % Q: 23.1.06- why is this field empty? which path should it contain?
D.fname = spm_str_manip(D.fname, 't');
D.fnamedat = [spm_str_manip(D.fname, 'r') '.dat'];
%----------------------------------------------------
% part 2: read data: adapt this to read your own data
%----------------------------------------------------
%data = randn(D.Nchannels, D.Nsamples, D.Nevents);
data=load([INPUT_DIRECTORY_NAME,'\',DATA_FILE]);
if Analyzer_EOG_Order_FLAG==1
data=circshift(data, [-2, 0]); % CHANGE 31.1.06- SPM assumes EEG data is in the begining, and EOG,exg at the end- this shifts the heog, veog to the end
end
%-----------------------------------
% part 3: write data, don't change
%-----------------------------------
Csetup = load(fullfile(spm('dir'), 'EEGtemplates', D.channels.ctf));
% Map name of channels (EEG only) to channel order specified in channel
% template file.
D.channels.heog = find(strncmpi('HEOG', D.channels.name, 4));
if isempty(D.channels.heog)
warning(sprintf('No HEOG channel found.'));
D.channels.heog = 0;
else
D.channels.heog = D.channels.heog(1) ;
end
D.channels.veog = find(strncmpi('VEOG', D.channels.name, 4));
if isempty(D.channels.veog)
warning(sprintf('No VEOG channel found.'));
D.channels.veog = 0;
else
D.channels.veog = D.channels.veog(1);
end
D.channels.eeg = setdiff([1:D.Nchannels], [D.channels.veog D.channels.heog ]);%D.channels.exg ]); %CHANGE 23.1.06: what about exg channels? (33 34 35)
for i = D.channels.eeg
index = [];
for j = 1:Csetup.Nchannels
if ~isempty(find(strcmpi(D.channels.name{i}, Csetup.Cnames{j})))
index = [index j];
end
end
if isempty(index)
warning(sprintf('No channel named %s found in channel template file.', D.channels.name{i}));
else
% take only the first found channel descriptor
D.channels.order(i) =index(1);
end
end
%D.channels.order(33) =33;%CHANGE 31.1.06
%D.channels.order(34) =34;%CHANGE 31.1.06
D.scale = ones(D.Nchannels, 1);
D.datatype = 'float32';
fpd = fopen(fullfile(D.path, D.fnamedat), 'w');
D.scale(:, 1) =spm_eeg_write(fpd, data, 2, D.datatype); %was in a comment -check!!!
fclose(fpd);
if str2num(version('-release'))>=14
save(fullfile(D.path, D.fname), '-V6', 'D');
else
save(fullfile(D.path, D.fname), 'D');
end
spm('Pointer', 'Arrow');
end
--1:-?Dc8(7XUlfFi.bFkj+SC.TIDqS3wGDB+ZQ-qyyQ-BWQymjUzRt(b7ijVZ?z,:+-Gaq)--
|