1 %
biosig2eeglab() - convert BIOSIG structue to EEGLAB structure
4 % >> OUTEEG = pop_biosig2eeglab(hdr, data, interval);
8 % data - BIOSIG data array
11 % interval - BIOSIG does not remove
event which are outside of
12 % the data range when importing data range subsets. This
13 % parameter helps fix
this problem.
16 % OUTEEG - EEGLAB data structure
18 % Author: Arnaud Delorme, SCCN, INC, UCSD, Oct. 29, 2009-
20 % Note: BIOSIG toolbox must be installed. Download BIOSIG at
22 % Contact a.schloegl@ieee.org
for troubleshooting
using BIOSIG.
24 % Copyright (C) 2003 Arnaud Delorme, SCCN, INC, UCSD, arno@salk.edu
26 % This program is free software; you can redistribute it and/or modify
27 % it under the terms of the GNU General Public License as published by
28 % the Free Software Foundation; either version 2 of the License, or
29 % (at your option) any later version.
31 % This program is distributed in the hope that it will be useful,
32 % but WITHOUT ANY WARRANTY; without even the implied warranty of
33 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 % GNU General Public License
for more details.
36 % You should have received a copy of the GNU General Public License
37 % along with
this program;
if not, write to the Free Software
38 % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 function EEG =
biosig2eeglab(dat, DAT, interval, channels, importevent);
61 % convert to seconds for sread
62 % ----------------------------
63 EEG.nbchan = size(DAT,1);
64 EEG.srate = dat.SampleRate(1);
67 % try % why would you do the following??????? JO
68 % EEG.data = EEG.data';
71 % EEG.data = EEG.data
';
73 EEG.setname = sprintf('%s file
', dat.TYPE);
74 EEG.comments = [ 'Original file:
' dat.FileName ];
78 EEG.pnts = size(EEG.data,2)/nepoch;
80 if isfield(dat, 'Label
') & ~isempty(dat.Label)
82 EEG.chanlocs = struct('labels
', cellstr(char(dat.Label)));
84 EEG.chanlocs = struct('labels
', dat.Label(1:min(length(dat.Label), size(EEG.data,1))));
87 EEG.chanlocs = EEG.chanlocs(channels);
90 EEG = eeg_checkset(EEG);
92 % extract events % this part I totally revamped to work... JO
96 % startval = mode(EEG.data(end,:)); % my code
97 % for p = 2:size(EEG.data,2)-1
98 % [codeout] = code(EEG.data(end,p));
99 % if EEG.data(end,p) > EEG.data(end,p-1) & EEG.data(end,p) >= EEG.data(end,p+1)
100 % EEG.event(end+1).latency = p;
101 % EEG.event(end).type = bitand(double(EEG.data(end,p)-startval),255);
105 % lastout = mod(EEG.data(end,1),256);newevs = []; % andrey's code 8 bits
106 % codeout = mod(EEG.data(end,2),256);
107 %
for p = 2:size(EEG.data,2)-1
108 % nextcode = mod(EEG.data(end,p+1),256);
109 %
if codeout > lastout & codeout >= nextcode
110 % newevs = [newevs codeout];
111 % EEG.event(end+1).latency = p;
112 % EEG.event(end).type = codeout;
115 % codeout = nextcode;
118 %lastout = mod(EEG.data(end,1),256*256);newevs = []; % andrey
's code 16 bits
119 %codeout = mod(EEG.data(end,2),256*256);
120 %for p = 2:size(EEG.data,2)-1
121 % nextcode = mod(EEG.data(end,p+1),256*256);
122 % if (codeout > lastout) & (codeout >= nextcode)
123 % newevs = [newevs codeout];
124 % EEG.event(end+1).latency = p;
125 % EEG.event(end).type = codeout;
128 % codeout = nextcode;
132 if isfield(dat, 'BDF
')
133 if dat.BDF.Status.Channel <= size(EEG.data,1)
134 EEG.data(dat.BDF.Status.Channel,:) = [];
136 EEG.nbchan = size(EEG.data,1);
137 if ~isempty(EEG.chanlocs) && dat.BDF.Status.Channel <= length(EEG.chanlocs)
138 EEG.chanlocs(dat.BDF.Status.Channel,:) = [];
140 elseif isempty(dat.EVENT.POS)
141 disp('Extracting events from last EEG channel...
');
142 %Modifieded by Andrey (Aug.5,2008) to detect all non-zero codes:
143 if length(unique(EEG.data(end, 1:100))) > 20
144 disp('Warning:
event extraction failure, the last channel contains data
');
145 elseif length(unique(EEG.data(end, :))) > 5000
146 disp('Warning:
event extraction failure, the last channel contains data
');
149 for p = 1:size(EEG.data,2)*size(EEG.data,3)-1
151 thiscode = mod(EEG.data(end,p),256*256); % andrey's code - 16 bits
152 if (thiscode ~= 0) && (thiscode~=prevcode)
153 EEG.event(end+1).latency = p;
154 EEG.event(end).type = thiscode;
157 EEG.data(end,:) = [];
158 EEG.chanlocs(end) = [];
160 % recreate the epoch field
if necessary
161 % -------------------------------------
163 for i = 1:length(EEG.event)
164 EEG.event(i).epoch = ceil(EEG.event(i).latency/EEG.pnts);
170 if ~isempty(dat.EVENT.POS)
171 if isfield(dat, 'out') % Alois fix for event interval does not work
172 if isfield(dat.out, 'EVENT')
173 dat.EVENT = dat.out.EVENT;
178 % recreate the epoch field if necessary
179 % -------------------------------------
181 for i = 1:length(EEG.event)
182 EEG.event(i).epoch = ceil(EEG.event(i).latency/EEG.pnts);
187 elseif isempty(EEG.event)
188 disp('Warning: no event found. Events might be embeded in a data channel.');
189 disp(' To extract events, use menu File > Import Event Info > From data channel');
193 % convert data to single if necessary
194 % -----------------------------------
195 EEG =
eeg_checkset(EEG,'makeur'); % Make EEG.urevent field