1 %
pop_biosig() -
import data files into EEGLAB
using BIOSIG toolbox
5 % >> OUTEEG =
pop_biosig( filename, channels, type);
8 % filename - [string] file name
11 %
'channels' - [integer array] list of channel indices
12 %
'blockrange' - [min max] integer range of data blocks to
import, in seconds.
13 % Entering [0 3] will
import the first three blocks of data.
14 % Default is empty ->
import all data blocks.
15 %
'importevent' - [
'on'|
'off']
import events. Default
if 'on'.
16 %
'importannot' - [
'on'|
'off']
import annotations (EDF+ only). Default
if 'on'
17 %
'blockepoch' - [
'on'|
'off'] force importing continuous data. Default is
'on'
18 %
'ref' - [integer] channel index or index(s)
for the reference.
19 % Reference channels are not removed from the data,
20 % allowing easy re-referencing. If more than one
21 % channel, data are referenced to the average of the
22 % indexed channels. WARNING! Biosemi Active II data
23 % are recorded reference-free, but LOSE 40 dB of SNR
24 %
if no reference is used!. If you
do not know which
25 % channel to use, pick one and then re-reference after
26 % the channel locations are read in. {
default: none}
27 %
'rmeventchan' - [
'on'|
'off'] remove
event channel after
event
28 % extraction. Default is
'on'.
31 % OUTEEG - EEGLAB data structure
33 % Author: Arnaud Delorme, SCCN, INC, UCSD, Oct. 29, 2003-
35 % Note: BIOSIG toolbox must be installed. Download BIOSIG at
37 % Contact a.schloegl@ieee.org
for troubleshooting
using BIOSIG.
39 % Copyright (C) 2003 Arnaud Delorme, SCCN, INC, UCSD, arno@salk.edu
41 % This program is free software; you can redistribute it and/or modify
42 % it under the terms of the GNU General Public License as published by
43 % the Free Software Foundation; either version 2 of the License, or
44 % (at your option) any later version.
46 % This program is distributed in the hope that it will be useful,
47 % but WITHOUT ANY WARRANTY; without even the implied warranty of
48 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 % GNU General Public License
for more details.
51 % You should have received a copy of the GNU General Public License
52 % along with
this program;
if not, write to the Free Software
53 % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
55 function [EEG, command, dat] =
pop_biosig(filename, varargin);
61 [filename, filepath] = uigetfile(
'*.*',
'Choose a data file -- pop_biosig()'); %%%
this is incorrect in original version!!!!!!!!!!!!!!
64 if filename == 0
return; end;
65 filename = [filepath filename];
70 if strcmpi(filepath(end-3:end-1),
'.ds'), filename = filepath(1:end-1); end;
73 % open file to get infos
74 % ----------------------
75 disp(
'Reading data file header...');
76 dat =
sopen(filename);
77 if ~isfield(dat,
'NRec')
78 error('Unsuported data format');
83 if strcmpi(dat.TYPE, 'BDF')
84 disp('We highly recommend that you choose a reference channel IF these are Biosemi data');
85 disp('(e.g., a mastoid or other channel). Otherwise the data will lose 40 dB of SNR!');
87 uilist = { {
'style' 'text' 'String' 'Channel list (defaut all):' } ...
88 {
'style' 'edit' 'string' '' } ...
89 {
'style' 'text' 'String' [
'Data range (in seconds) to read (default all [0 ' int2str(dat.NRec)
'])' ] } ...
90 {
'style' 'edit' 'string' '' } ...
91 {
'style' 'text' 'String' 'Extract event' } ...
92 {
'style' 'checkbox' 'string' '' 'value' 1
'enable' 'on' } {} ...
93 {
'style' 'text' 'String' 'Import anotations (EDF+ only)' } ...
94 {
'style' 'checkbox' 'string' '' 'value' 1
'enable' 'on' } {} ...
95 {
'style' 'text' 'String' 'Force importing continuous data' 'value' 1} ...
96 {
'style' 'checkbox' 'string' '' 'value' 0 } {} ...
97 {
'style' 'text' 'String' 'Reference chan(s) indices - required for BIOSEMI' } ...
98 {
'style' 'edit' 'string' '' } };
99 geom = { [3 1] [3 1] [3 0.35 0.5] [3 0.35 0.5] [3 0.35 0.5] [3 1] };
101 result = inputgui( geom, uilist,
'pophelp(''pop_biosig'')', ...
102 'Load data using BIOSIG -- pop_biosig()');
103 if length(result) == 0
return; end;
108 if ~isempty(result{1}), options = { options{:}
'channels' eval( [
'[' result{1}
']' ] ) }; end;
109 if ~isempty(result{2}), options = { options{:}
'blockrange' eval( [
'[' result{2}
']' ] ) }; end;
110 if length(result) > 2
111 if ~isempty(result{6}), options = { options{:}
'ref' eval( [
'[' result{6}
']' ] ) }; end;
112 if ~result{3}, options = { options{:}
'importevent' 'off' }; end;
113 if ~result{4}, options = { options{:}
'importannot' 'off' }; end;
114 if result{5}, options = { options{:}
'blockepoch' 'off' }; end;
120 % decode imput parameters
121 % -----------------------
122 g =
finputcheck( options, {
'blockrange' 'integer' [0 Inf] [];
123 'channels' 'integer' [0 Inf] [];
124 'ref' 'integer' [0 Inf] [];
125 'rmeventchan' 'string' {
'on';
'off' }
'on';
126 'importevent' 'string' {
'on';
'off' }
'on';
127 'importannot' 'string' {
'on';
'off' }
'on';
128 'blockepoch' 'string' {
'on';
'off' }
'off' },
'pop_biosig');
129 if isstr(g), error(g); end;
134 if ~isempty(g.channels)
135 dat =
sopen(filename, 'r', g.channels,'OVERFLOWDETECTION:OFF');
136 else dat =
sopen(filename, 'r', 0,'OVERFLOWDETECTION:OFF');
138 fprintf('Reading data in %s format...\n', dat.TYPE);
140 if ~isempty(g.blockrange)
141 newblockrange = g.blockrange;
142 newblockrange(2) = min(newblockrange(2), dat.NRec);
143 newblockrange = newblockrange*dat.Dur;
144 DAT=
sread(dat, newblockrange(2)-newblockrange(1), newblockrange(1));
146 DAT=
sread(dat, Inf);% this isn't transposed in original!!!!!!!!
151 if strcmpi(g.blockepoch, 'off')
155 if ~isempty(newblockrange)
156 interval(1) = newblockrange(1) * dat.SampleRate(1) + 1;
157 interval(2) = newblockrange(2) * dat.SampleRate(1);
161 EEG =
biosig2eeglab(dat, DAT, interval, g.channels, strcmpi(g.importevent, 'on'));
163 if strcmpi(g.rmeventchan, 'on') & strcmpi(dat.TYPE, 'BDF') & isfield(dat, 'BDF')
164 if size(EEG.data,1) >= dat.BDF.Status.Channel,
165 disp('Removing event channel...');
166 EEG.data(dat.BDF.Status.Channel,:) = [];
167 if ~isempty(EEG.chanlocs) && length(EEG.chanlocs) >= dat.BDF.Status.Channel
168 EEG.chanlocs(dat.BDF.Status.Channel) = [];
171 EEG.nbchan = size(EEG.data,1);
177 disp('Re-referencing...');
178 EEG = pop_reref(EEG, g.ref);
179 % EEG.data = EEG.data - repmat(mean(EEG.data(g.ref,:),1), [size(EEG.data,1) 1]);
180 % if length(g.ref) == size(EEG.data,1)
181 % EEG.ref = 'averef';
183 % if length(g.ref) == 1
184 % disp([ 'Warning: channel ' int2str(g.ref) ' is now zeroed (but still present in the data)' ]);
186 % disp([ 'Warning: data matrix rank has decreased through re-referencing' ]);
190 % test if annotation channel is present
191 % -------------------------------------
192 if isfield(dat, 'EDFplus') && strcmpi(g.importannot, 'on')
193 tmpfields = fieldnames(dat.EDFplus);
194 for ind = 1:length(tmpfields)
195 tmpdat = getfield(dat.EDFplus, tmpfields{ind});
196 if length(tmpdat) == EEG.pnts
197 EEG.data(end+1,:) = tmpdat;
198 EEG.nbchan = EEG.nbchan+1;
199 if ~isempty(EEG.chanlocs)
200 EEG.chanlocs(end+1).labels = tmpfields{ind};
206 % convert data to single
if necessary
207 % -----------------------------------
208 EEG =
eeg_checkset(EEG,
'makeur'); % Make EEG.urevent field
214 command = sprintf(
'EEG = pop_biosig(''%s'');', filename);
216 command = sprintf(
'EEG = pop_biosig(''%s'', %s);', filename, vararg2str(options));