1 %This file is part of TEAP.
3 %TEAP is free software: you can redistribute it and/or modify
4 %it under the terms of the GNU General Public License as published by
5 %the Free Software Foundation, either version 3 of the License, or
6 %(at your option) any later version.
8 %TEAP is distributed in the hope that it will be useful,
9 %but WITHOUT ANY WARRANTY; without even the implied warranty of
10 %MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 %GNU General Public License
for more details.
13 %You should have received a copy of the GNU General Public License
14 %along with TEAP. If not, see <http://www.gnu.org/licenses/>.
17 %> @brief Loads a bdf file, into a TEAP bulk signal, containing EEG, ECG,
19 %> @param file_name:
this variable includes the full path;
20 %> it can be any file supported by biogs
sload/sopn
22 %> @retval BulkSig a TEAP bulk signal vector
25 %Copyright Mohammad Soleymani, 2014
28 error(
'Usage: BulkSig = Bulk_load(phys_data)');
31 if (~exist(file_name,
'file'))
32 error(
'Usage: the input file does not exist');
34 %
if it is a mat file; it is assumed to be an EEGLAB file
35 if strcmp(file_name(end-2:end),
'mat')
38 phys_data = S.(vars{1});
39 else %otherwise load the file
43 %initialize signals to load
46 %initialize EEG electrode labels
48 electrode_labels =
struct;
52 nEpochs = length(phys_data.epoch);
57 for iEpoch = [1:nEpochs]
60 eval([
'Bulk = add' signal{1}
'(Bulk, iEpoch, electrode_labels.' signal{1}
');']);
62 BulkSig(iEpoch) = Bulk;
68 eval([
'Bulk = add' signal{1}
'(Bulk, 0, electrode_labels.' signal{1}
');']);
76 function BulkSig =
addEEG(BulkSig, iEpoch,correspondance)
77 numel = length(correspondance);
78 datlen = length(phys_data.data(1, :, 1));
79 data = zeros(numel, datlen);
82 chaname = strtrim(correspondance{i});
84 % disp([
'Will do ' chaname
' - ' num2str(chan)]);
86 warning([
'The EEG channel ' correspondance{i}
' does not '...
87 'exist. Aborting EEG']);
91 data(i,:) = squeeze(phys_data.data(chan, :));
93 data(i, :) = squeeze(phys_data.data(chan, :, iEpoch));
102 function BulkSig =
addGSR(BulkSig, iEpoch,correspondance)
108 data = phys_data.data(GSRChannel, :);
110 data = phys_data.data(GSRChannel, :, iEpoch);
118 function BulkSig =
addHST(BulkSig, iEpoch,correspondance)
124 data = phys_data.data(HSTChannel, :);
126 data = phys_data.data(HSTChannel, :, iEpoch);
134 function BulkSig =
addRES(BulkSig, iEpoch,correspondance)
140 data = phys_data.data(RESChannel, :);
142 data = phys_data.data(RESChannel, :, iEpoch);
150 function BulkSig =
addBVP(BulkSig, iEpoch,correspondance)
156 data = phys_data.data(BVPChannel, :);
158 data = phys_data.data(BVPChannel, :, iEpoch);
166 function BulkSig =
addEMG(BulkSig, iEpoch,correspondance)
167 for i = 1:length(correspondance)
170 if any(EMGChannel == 0)
174 data = phys_data.data(EMGChannel, :);
176 data = phys_data.data(EMGChannel, :, iEpoch);
178 temp = squeeze(zeros(size(data,1)/2,size(data,2),size(data,3)));
179 if mod(size(data,1),2)==0
180 for j = 1:size(data,1)/2
181 temp(j,:,:) = data(j*2-1,:,:) - data(j*2,:,:); %subtracting two leads
185 error('Usage: You need two leads!');
193 for i = 1:length(correspondance)
196 if any(ECGChannel == 0)
200 data = phys_data.data(ECGChannel, :);
202 data = phys_data.data(ECGChannel, :, iEpoch);
203 data = squeeze(data);
206 data = data(1,:,:) - data(2,:,:); %subtracting two leads
207 elseif size(data,1)>2
208 error('Usage: We dont support more than two leads at the moment!');
210 error('Usage: You need two leads at least!');
219 for iChannel = [1:length(phys_data.chanlocs)]
220 % disp(['Will compare ' chanName ' and ' phys_data.chanlocs(iChannel).labels]);
221 if(strcmp(chanName, phys_data.chanlocs(iChannel).labels) == 1)
226 warning(['Could not find channel ' chanName ', it will not be included in the bulk. Please correct the configuration file (config_file.m) accordingly'])