Hello Stefan,
Thank-you very much for the help with the scripts.
*The "meeg_read_data_Analyzer.m" script seems to work fine!
Now that I managed to convert my averaged data to SPM,
New questions have arisen:
1. Is it essential to use epoched data and not averaged data for the 2D
interpolation?
I tried using my averaged data (exported from analyzer and converted to SPM) for
2D interpolation but got the following error:
-------------------------------
??? 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.
-In the "meeg_read_data_Analyzer" script I defined :
% Number of ERPs
D.Nevents =1; % 0\1?
2. If I only have 32 or 64 electrodes and no MRI data can I use the 3D
projection or am I limited to the 2D projection?
* Regarding the The spm_eeg_rdata_bdf file:
I used the GUI to convert the bdf file.
-In the "external channel window"- I assume I give the channel numbers as they
appear in the command line? e.g: Heog channel:2 3.
-I specified there are 2 additional external channels (the 2 mastoids), which
appear in the template file as M1, M2, but I got a warning: "Warning: No exg
channel found in channel template file".
When I looked at structure D I saw they (M1,M2) appeared as 'exg1','exg2'.
--------------------------------------------------------
External channels:
1: Nose
2: HR
3: HL
4: EOGu
5: EOGd
6: M2
7: M1
8: EXG8
Warning: No exg channel found in channel template file.
> In spm_eeg_rdata_bdf at 228
In spm_eeg_converteeg2mat at 96
Warning: No exg channel found in channel template file.
> In spm_eeg_rdata_bdf at 228
In spm_eeg_converteeg2mat at 96
-------------------------------------------
In general I have an ERP experiment which checks the response to a gradient MMN
(small, medium & big deviant) in two groups (controls,dyslexic).
In one experiment I have 32 electrodes, and in the other 64.
I wanted to learn how SPM can contribute to the traditional way of analyzing ERP
data. I'm interested in the modeling and statistics part.
For example I want to contrast between the 2 groups and the 3 deviant types.
My data has already been preprocessed in Analyzer.
I thought of following these steps:
1. skip the pre-processing stage by exporting from Analyzer the data after it
was averaged for each subject and each condition.
2. Do a spatial projection using the averaged data.
Q: can I do a spatial projection with averaged data, or do I need to supply
epoched data?
Q: If I only have 32/64 electrodes and no MRI data can I use the 3D projection
or am I limited to the 2D projection?
3.Do the modeling and statistics using the projected images.
Thnk-you!!
Yael.
------------------------
Hi Yael,
ok, I got on your ftp server now.
I amended the spm_eeg_rdata_bdf to make it work for your data.
Now you have to explicitly say which channels are Veog, Heog, and
reference. It would have also been possible (for your data) to guess
from the names, which channels are which. But it would only work for
your data. Other people (like us) name their channels differently.
With you other script, the thing is that the original script was
intended to read multiple trials. Your data just consists of one ERP, so
I changed it a bit to make it work.
Let me know whether you're fine with the scripts...
All the best, Stefan
>I re-checked the ftp server, and found no problem.
>please try again through the explorer or by a ftp program (logging as
>annonymous).
>
>Another thing I tried doing is to export my processed data (avreged for each
>subject and each trial type) from Analyzer to SPM.
>I exported the avreged Analyzer data of 1 subject for one condition to a ASCII
>file. each row represents an electrode, and each line a time bin.
>
>I used the "meeg_read_data.m" script you provided.
>in part 2 of the script,Is it enough to write:
>data=load('s10_MMN_all_trials_AV_channels.dat');
>
>when runnig the script I got an error:
>
> ??? Subscripted assignment dimension mismatch.
>
>Error in ==> meeg_read_data_Analyzer at 117
> D.scale(:, 1, i) = spm_eeg_write(fpd, d, 2, D.datatype); %gives an
>
>
>
>I attached the averged data file and the script I used, and I also put them on
>the ftp server.
>
>
>Thanks in advance,
>Yael.
>
>
>
>Quoting Stefan Kiebel <[log in to unmask]>:
>
>
>
>>Hi Yael,
>>
>>thanks for your help....
>>
>>I tried connecting to this ftp server, but couldn't get a connection.
>>
>>Shall I try again at some point?
>>
>>Stefan
>>
>>
>>
>>>I put the bdf file I tried using at:
>>>ftp://pissaro.soc.huji.ac.il/pub/incoming/spm/
>>>
>>>I also included the script I used for the channel template.
>>>
>>>thanks very much for your help,
>>>Yael.
>>>
>>>
>>>Quoting Stefan Kiebel <[log in to unmask]>:
>>>
>>>
>>>
>>>
>>>
>>>>Hi Yael,
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>Hello,
>>>>>I couldn't find the example data set for EEG, mentioned in the spm5 manual
>>>>>
>>>>>
>>>>>
>>>>>
>>>>(page
>>>>
>>>>
>>>>
>>>>
>>>>>77).
>>>>>I looked under:http://www.fil.ion.ucl.ac.uk/spm/data/.
>>>>>The only EEG data was related to the "Multi-modal faces" set.
>>>>>
>>>>>
>>>>>I also had trouble with the channel template:
>>>>>1.
>>>>>Is the Nchannels variable suposed to be the number of ALL channels
>>>>>
>>>>>
>>including
>>
>>
>>>>>
>>>>>
>>>>exg
>>>>
>>>>
>>>>
>>>>
>>>>>channels? If so then in the script the line:Nchannels = length(Cnames)
>>>>>should come after defining the VEOG,HEOG.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>If you're talking about the script in \man\example_scripts: You're
>>>>right. I changes this. The changed script will be available with the
>>>>next update.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>2.
>>>>>If I have 2 channels for VEOG do I put them in 1 cell of the Cnames or can
>>>>>
>>>>>
>>I
>>
>>
>>>>>
>>>>>
>>>>put
>>>>
>>>>
>>>>
>>>>
>>>>>each channel in a separate cell of the Cnames?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>When you're having two VEOG channels, you have to reduce them to one
>>>>channel. For example, you might be interested in the difference signal.
>>>>This is what SPM5 does, when converting bdf-files: Two VEOG channels are
>>>>subtracted from each other to give one VEOG channel. If you want to keep
>>>>all channels as they are, you have to select them as 'other' data channels.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>3.
>>>>>Do I have to call my horizontal and vertical eye channels: HEOG,VEOG in
>>>>>
>>>>>
>>the
>>
>>
>>>>>channel template?
>>>>>e.g: Cnames{end+1} = {'HEOG','HL','HR'};
>>>>>In the bdf file they are named differently (e.g: EOGu,EOGd,HR,HL)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>Well... if 'EOGu, EOGd, HR, HL are some of the 8 exogeneous channels,
>>>>then you'll experience problems with SPM's conversion routine for
>>>>bdf-files. We assumed that exogeneous channels are called EXG1 - EXG8.
>>>>If this is not the case, e.g., for your setup, then we have to adapt the
>>>>routine. If possible, could you send me your bdf file? (also see below).
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>4.
>>>>>I'm using a 32,64 biosemi cap,plus: mastoids,2-HEOG,2-VEOG,Nose.
>>>>>Is there a ready made channel-template I can use?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>I'm afraid no. For our version of the 128 channel template file, we
>>>>used the fact that the locations can be constructed from concentric
>>>>rings. Is this maybe possible for the smaller caps as well?
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>5.
>>>>>When asked in the conversion process- (in read BDF data setup GUI) to
>>>>>
>>>>>
>>>>>
>>>>>
>>>>indicate
>>>>
>>>>
>>>>
>>>>
>>>>>the HEOG,VEOG.. do I give the index of the chanennl according to its
>>>>>
>>>>>
>>>>>
>>>>>
>>>>position
>>>>
>>>>
>>>>
>>>>
>>>>>in the Cnames?
>>>>>If my reference is the nose, do I answer 'no' when asked if I have any
>>>>>
>>>>>
>>other
>>
>>
>>>>>data?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>The 'other' channels is just for any other additional measurement
>>>>different from EOG or reference. If you already named your reference,
>>>>you should answer no.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>6.
>>>>>I used the script "make_Easycap_montage" you provided and added the
>>>>>
>>>>>
>>>>>
>>>>>
>>>>following:
>>>>
>>>>
>>>>
>>>>
>>>>>Cpos = [Cpos [0.4; 0.95]];
>>>>>Cnames{end+1} = {'HEOG','HL','HR'};
>>>>>Cpos = [Cpos [0.6; 0.95]];
>>>>>Cnames{end+1} = {'VEOG','EOGu','EOGd'};
>>>>>Cpos = [Cpos [0; 0]];
>>>>>Cnames{end+1} = 'Nose';
>>>>>Nchannels = length(Cnames); %%%? should Nchannels include exg channels?
>>>>>
>>>>>but when I ran the convertor from bdf to SPM got the following error
>>>>>
>>>>>
>>>>>
>>>>>
>>>>message:
>>>>
>>>>
>>>>
>>>>
>>>>>?? Attempted to access data.Record(74,:); index out of bounds because
>>>>>size(data.Record)=[41,256].
>>>>>
>>>>>Error in ==> spm_eeg_rdata_bdf at 293
>>>>> d = [d; data.Record(Cheog(1), :)];
>>>>>
>>>>>Error in ==> spm_eeg_converteeg2mat at 96
>>>>> D{i} = spm_eeg_rdata_bdf(S2);
>>>>>
>>>>>??? Error while evaluating uicontrol Callback.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>Hmm, could I have one of your bdf-files to check this? If convenient for
>>>>you, could you put it on an ftp site?
>>>>
>>>>Thanks, Stefan
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>Thanks,
>>>>>Yael.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>----------------------------------------------------------------
>>>>>This message was sent using IMP, the Internet Messaging Program.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>--
>>>>Dr. Stefan Kiebel
>>>>Wellcome Dept of Imaging Neuroscience
>>>>Institute of Neurology, UCL
>>>>12 Queen Square
>>>>London WC1N 3BG
>>>>
>>>>Phone: (+44) 20 7833 7478
>>>>Fax: (+44) 20 7813 1420
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>----------------------------------------------------------------
>>>This message was sent using IMP, the Internet Messaging Program.
>>>
>>>
>>>
>>>
>>>
>>>
>>--
>>Dr. Stefan Kiebel
>>Wellcome Dept of Imaging Neuroscience
>>Institute of Neurology, UCL
>>12 Queen Square
>>London WC1N 3BG
>>
>>Phone: (+44) 20 7833 7478
>>Fax: (+44) 20 7813 1420
>>
>>
>>
>
>
>
>
>----------------------------------------------------------------
>This message was sent using IMP, the Internet Messaging Program.
>
>
>------------------------------------------------------------------------
>
>% This is an example script to convert epoched and averaged data (ERP/ERF)
>% to SPM format. Please adapt to your needs.
>
>clear all
>
>%-----------------------------------
>% part 1: information about the data
>%-----------------------------------
>% change the following values according to your data
>
>% sampling rate in Hz
>D.Radc = 256;
>
>% Number of time bins in peri-stimulus time
>D.Nsamples = 101;
>
>% Number of ERPs
>D.Nevents = 1;
>
>% channel template file
>D.channels.ctf = 'biosemi32.mat';
%'L:\Experiments\Dyslexia\MMN_Dyslexia\SPM\Yael\biosemi32.mat';
>
>% Names of channels in order of the data
>D.channels.name = {'VEOG', 'HEOG', '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','Nose' ,'M2','M1'
>};
>D.Nchannels = length(D.channels.name);
>
>% index vector of bad channels
>D.channels.Bad = [];
>
>% nr of time bins before stimulus onset (this excludes the time bin at
>% zero)
>D.events.start = 25;% 100/3.9
>
>% nr of time bins after stimulus onset (this excludes the time bin at
>% zero)
>D.events.stop = 129; %154-25
>
>% name of SPM mat file
>D.fname = 's10_MMN_Dyslexia.mat';
>
>
>D.modality = 'EEG';
>D.units = '\muV';
>%-------------------------------------
>% Don't change these
>D.channels.reference = 0;
>D.channels.ref_name = 'none';
>
>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.path = fileparts(D.fname);
>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('L:\Experiments\Dyslexia\MMN_Dyslexia\SPM\Yael\MMN_Dyslexia_dat\s10_MMN_all_trials_AV_channels.dat');
>
>
>%-----------------------------------
>% 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]);
>
>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.scale = ones(D.Nchannels, 1, D.Nevents);
>D.datatype = 'float32';
>
>fpd = fopen(fullfile(D.path, D.fnamedat), 'w');
>
>for i = 1:D.Nevents
> d = squeeze(data(:, :, i));
> D.scale(:, 1, i) = spm_eeg_write(fpd, d, 2, D.datatype); %gives an
> %error
> end
>
>
>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');
>
>
>
--
Dr. Stefan Kiebel
Wellcome Dept of Imaging Neuroscience
Institute of Neurology, UCL
12 Queen Square
London WC1N 3BG
Phone: (+44) 20 7833 7478
Fax: (+44) 20 7813 1420
2 spm_eeg_rdata_bdf.m text/plain 10.95 KB
function D = spm_eeg_rdata_bdf(S)
% converts EEG data from BDF- to SPM-format
% FORMAT D = spm_eeg_rdata_bdf(S)
%
% S - struct (optional)
% (optional) fields of S:
% Fdata - filename of bdf-file
% Fchannels - filename of channel template
% exg_name - cell vector that code type of exogeneous channels. Allowed
% types are 'heog', 'veog', 'reference' and 'other'
%_______________________________________________________________________
%
% spm_eeg_rdata_bdf reads a continuous *.bdf file, stores everything
% in struct D and saves struct D to mat-file. The data is stored separately
% in a dat-file.
% There are calls to openbdf and readbdf, which are distributed under the
% GNU-license.
%_______________________________________________________________________
% Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
% Stefan Kiebel
% $Id: spm_eeg_rdata_bdf.m 333 2005-11-30 08:52:31Z james $
[Finter,Fgraph,CmdLine] = spm('FnUIsetup','read BDF data setup',0);
try
Fdata = S.Fdata;
catch
Fdata = spm_select(1, '\.bdf$', 'Select bdf-file');
end
try
Fchannels = S.Fchannels;
catch
Fchannels = spm_select(1, '\.mat$', 'Select channel template file', {},
fullfile(spm('dir'), 'EEGtemplates'));
end
D.channels.ctf = spm_str_manip(Fchannels, 't');
Csetup = load(Fchannels);
F = spm_str_manip(Fdata, 'rt');
P = spm_str_manip(Fdata, 'H');
D.fnamedat = [F '.dat'];
% read header
Hdata = openbdf(Fdata);
% build header for SPM format
%--------------------------------------------------
% find out how many channels
Cind = strmatch('Active Electrode', Hdata.Head.Transducer);
D.Nchannels = length(Cind);
% Bad channels entry
D.channels.Bad = [];
% read channel names
for i = 1:D.Nchannels
D.channels.name{i} = deblank(Hdata.Head.Label(i,:));
end
% go through 'external' channels and ask what they are
% Cexg = find(strncmpi('exg', D.channels.name, 3));
% assume that external channels are always the 8 channels after the EEG
% channels
Neeg = 2^fix(log2(D.Nchannels));
Cexg = [Neeg+1:Neeg+8];
% print names of external channels in matlab command window
disp(sprintf('External channels:'))
for i = 1:8
disp(sprintf('%d: %s', i, D.channels.name{Neeg+i}))
end
% HEOG, VEOG and reference
try
Cheog = S.Cheog;
catch
Cheog = spm_input('Heog channel(s)', 'i+1', 'i', '', inf, length(Cexg));
end
try
Cveog = S.Cveog;
catch
Cveog = spm_input('Veog channel(s)', 'i+1', 'i', '', inf, length(Cexg));
end
try
Creference = S.Creference;
catch
Creference = spm_input('Reference channel(s)', 'i+1', 'i', '', inf,
length(Cexg));
end
more_exg =spm_input('Do you have any other data?', '+1', 'y/n', [1,0], 2);
no_exg=0;
if more_exg==1
no_exg=spm_input('how many extra channels?', '+1', 'i', '', 1);
Chexg = spm_input('Enter exg (nose or others) channel(s)', 'i+1', 'i', '',
inf, length(Cexg));
end
spm('Pointer','Watch'); drawnow;
% number of EEG channels
Neeg = D.Nchannels - length(Cexg);
% save EEG channel indices
D.channels.eeg = [1:Neeg];
if Cheog == 0
warning(sprintf('No HEOG channel.'));
Cheog = 0;
elseif length(Cheog) > 2
error('Only up 2 heog channels allowed');
else
Cheog = Cheog + Neeg;
end
if Cveog == 0
warning(sprintf('No VEOG channel.'));
Cveog = 0;
elseif length(Cveog) > 2
error('Only up 2 veog channels allowed');
else
Cveog = Cveog + Neeg;
end
if Creference == 0
warning(sprintf('No reference channel.'));
Creference = 0;
else
Creference = Creference + Neeg;
end
if more_exg==1
Chexg = Chexg + Neeg;
end
% Map name of channels (EEG only) to channel order specified in channel
% template file. EOG channels will be added further below!
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
% Assume that each channel has the same sampling rate
D.Radc = Hdata.Head.SampleRate(Cind(1));
% open dat-file for writing
%---------------------------------------------------
Fout = [F '.dat'];
D.fnamedat = Fout;
fpout = fopen(fullfile(P, D.fnamedat), 'w');
counter = 0;
if Cheog ~= 0
counter = counter + 1;
D.channels.name{Neeg + counter} = 'HEOG';
D.channels.heog = Neeg + counter;
index = [];
for j = 1:Csetup.Nchannels
if ~isempty(find(strcmpi('HEOG', Csetup.Cnames{j})))
index = j; break;
end
end
if isempty(index)
warning(sprintf('No HEOG channel found in channel template file.'));
else
% take only the first found channel descriptor
D.channels.order(Neeg+counter) = index;
end
end
if Cveog ~= 0
counter = counter + 1;
D.channels.name{Neeg + counter} = 'VEOG';
D.channels.veog = Neeg + counter;
index = [];
for j = 1:Csetup.Nchannels
if ~isempty(find(strcmpi('VEOG', Csetup.Cnames{j})))
index = j; break;
end
end
if isempty(index)
warning(sprintf('No VEOG channel found in channel template file.'));
else
% take only the first found channel descriptor
D.channels.order(Neeg+counter) = index;
end
end
D.channels.reference = 0;
D.channels.ref_name = 'NIL';
if more_exg ==1
D.channels.exg=[];
for kl=1:no_exg
counter = counter + 1;
D.channels.name{Neeg + counter} = ['exg',num2str(kl)];
D.channels.exg = [ D.channels.exg ,Neeg + counter];
index = [];
for j = 1:Csetup.Nchannels
if ~isempty(find(strcmpi(['exg',num2str(kl)], Csetup.Cnames{j})))
index = j; break;
end
end
if isempty(index)
warning(sprintf('No exg channel found in channel template file.'));
else
% take only the first found channel descriptor
D.channels.order(Neeg+counter) = index;
end
end
end
D.Nchannels = Neeg + counter;
if D.Nchannels < length(D.channels.name);
D.channels.name(D.Nchannels+1:end) = [];
end
% No scaling, represent as float32
D.scale = ones(D.Nchannels, 1, 1);
D.events.code = [];
D.events.time = [];
D.Nsamples = 0;
% loop over seconds
Nblocks = Hdata.Head.NRec;
% sometimes Hdata.Head.NRec indicates more Nblocks than are actually there.
flen = dir(Fdata);
flen = flen.bytes;
Nblocks_alt =
(flen-Hdata.Head.HeadLen)/Hdata.Head.SampleRate(1)/Hdata.Head.NS/3;
if Nblocks_alt < Nblocks
warning('Nblocks too large. True Nblocks = %f', Nblocks_alt);
Nblocks = floor(Nblocks_alt);
end
% identify channel which stores event coding
Echannel = strmatch('Status', Hdata.Head.Label);
if length(Echannel) > 1
Echannel = Echannel(1);
end
lidiffs = 0;
lastevent = 0;
% check whether data would is too long for 32-Bit Windows system with 2 GB
% maximum memory, and downsample.
if D.Nchannels*Nblocks*D.Radc > 2^27
f = ceil(log2(D.Nchannels*Nblocks*D.Radc) - 27); % downsampling factor 2^f
warning('Data set will be downsampled from %d to %d Hz', D.Radc,
D.Radc/(2^f));
D.Radc = D.Radc/(2^f);
else
f = 0;
end
% progress bar
spm_progress_bar('Init', Hdata.Head.NRec, 'Seconds converted'); drawnow;
if Hdata.Head.NRec > 100, Ibar = floor(linspace(1, Hdata.Head.NRec,100));
else, Ibar = [1:Hdata.Head.NRec]; end
for t = 1:Nblocks
data = readbdf(Hdata,t,0);
% calibrate the data
% data.Record = data.Record.*repmat(data.Head.Cal, 1, size(data.Record, 2));
% store data
%-----------------------------------------------------
% the EEG data
d = data.Record(D.channels.eeg, :);
% horizontal EOG
if Cheog ~= 0
if length(Cheog) == 2
% take difference
d = [d; data.Record(Cheog(1), :) - data.Record(Cheog(2), :)];
else
d = [d; data.Record(Cheog(1), :)];
end
end
% vertical EOG
if Cveog ~= 0
if length(Cveog) == 2
% take difference
d = [d; data.Record(Cveog(1), :) - data.Record(Cveog(2), :)];
else
d = [d; data.Record(Cveog(1), :)];
end
end
% reference
if Creference ~= 0
if length(Creference) > 1
% take average
ref = mean(data.Record(Creference, :));
else
ref = data.Record(Creference(1), :);
end
d = d - repmat(ref, D.Nchannels-no_exg, 1);
end
if more_exg ==1
for kl=1:no_exg
d = [d; data.Record(Chexg(kl), :)];
end
end
% downsampling by simple decimating
d = d(:, 1:2^f:end);
fwrite(fpout, d, 'float32');
Nsamples = size(data.Record, 2); % the original size is needed for events
below
D.Nsamples = D.Nsamples + size(d, 2); % save downsampled Nsamples
% identify events
Ezero = 0;
if ~isempty(Echannel)
diffs=diff(data.Record(Echannel,:));
idiffs=find(diffs~=0);
idiffs=idiffs+1;
% safe-guard against some unexplained zeroing of Echannel
if data.Record(Echannel, 1) == 0
warning('Event channel is all zero.');
Ezero = 1;
break;
end
bytes=dec2bin(data.Record(Echannel,1));
bytes=bytes(end-7:end);
bytes=flipdim(bytes,2);
test_event=bin2dec(bytes);
if test_event~=lastevent
idiffs=[1,idiffs];
end
idsf=find(diff(idiffs)==1);
if ~isempty(idsf)
idiffs(idsf)='';
end
if ~isempty(idiffs)
if idiffs(1)==1 & lidiffs==1
D.events.code=D.events.code(1,1:end-1);
D.events.time=D.events.time(1,1:end-1);
end
for i = idiffs
bytes=dec2bin(data.Record(Echannel,i));
bytes=bytes(end-7:end);
bytes=flipdim(bytes,2);
event=bin2dec(bytes);
D.events.code = [D.events.code event];
if i==512
lidiffs=1;
else
lidiffs=0;
end
lastevent=event;
end
D.events.time = [D.events.time idiffs+(t-1)*Nsamples];
end
end
if ismember(t, Ibar)
spm_progress_bar('Set', t);
drawnow;
end
end
if f ~= 0
% if downsampling
D.events.time = ceil(D.events.time/2^f);
end
D.Nevents = 1;
D.events.types = unique(D.events.code);
D.datatype = 'float32';
D.modality = 'EEG';
D.units = '\muV';
fclose(fpout);
D.fname = [F '.mat'];
if str2num(version('-release'))>=14
save(fullfile(P, D.fname), '-V6', 'D');
else
save(fullfile(P, D.fname), 'D');
end
spm_progress_bar('Clear');
spm('Pointer','Arrow');
3 meeg_read_data_Analyzer.m text/plain 3.59 KB
% This is an example script to convert epoched and averaged data (ERP/ERF)
% to SPM format. Please adapt to your needs.
clear all
%-----------------------------------
% part 1: information about the data
%-----------------------------------
% change the following values according to your data
% sampling rate in Hz
D.Radc = 256;
% Number of time bins in peri-stimulus time
D.Nsamples = 101;
% Number of ERPs
D.Nevents = 1;
% channel template file
D.channels.ctf = 'biosemi32.mat';
%'L:\Experiments\Dyslexia\MMN_Dyslexia\SPM\Yael\biosemi32.mat';
% Names of channels in order of the data
D.channels.name = {'VEOG', 'HEOG', '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','Nose' ,'M2','M1'
};
D.Nchannels = length(D.channels.name);
% index vector of bad channels
D.channels.Bad = [];
% nr of time bins before stimulus onset (this excludes the time bin at
% zero)
D.events.start = 25;% 100/3.9
% nr of time bins after stimulus onset (this excludes the time bin at
% zero)
D.events.stop = 129; %154-25
% name of SPM mat file
D.fname = 's10_MMN_Dyslexia.mat';
D.modality = 'EEG';
D.units = '\muV';
%-------------------------------------
% Don't change these
D.channels.reference = 0;
D.channels.ref_name = 'none';
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.path = fileparts(D.fname);
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('s10_MMN_all_trials_AV_channels.dat')';
%-----------------------------------
% 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]);
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.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); %gives an
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');
<<<>>>***<<<>>>**<<<>>>**<<<>>>**<<<>>>**<<<>>>**<<<>>>**<<<>>>**<<<>>>**<<<>>>
Yael Weisberger
Department of Cognitive Science.
The Hebrew University of Jerusalem.
Jerusalem 91905
Israel
Tel. +972-2-5883195
Fax. +972-2-5881159
http://micro5.mscc.huji.ac.il/~ahissar/yael_page.html
http://pissaro.soc.huji.ac.il/~leon/Lab/
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
|