-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpop_loadbva.m
140 lines (131 loc) · 5.78 KB
/
pop_loadbva.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
% pop_loadbva() - import a Matlab file from brain vision analyser
% software.
%
% Usage:
% >> OUTEEG = pop_loadbva( filename );
%
% Inputs:
% filename - file name
%
% Outputs:
% OUTEEG - EEGLAB data structure
%
% Author: Arnaud Delorme, SCCN/INC/UCSD, Dec 2003
%
% See also: eeglab()
% Copyright (C) 2003 Arnaud Delorme, Salk Institute, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function [EEG, com] = pop_loadbva(filename)
EEG = [];
com = '';
if nargin < 1
[tmpfilename, filepath] = uigetfile('*.mat;*.MAT', 'Choose a Matlab file from Brain Vision Analyser -- pop_loadbva');
if tmpfilename == 0 return; end;
filename = [ filepath tmpfilename ];
end;
disp('Importing data');
EEG = eeg_emptyset;
bva = load(filename, '-mat');
allfields = fieldnames(bva);
chanstruct = bva.Channels;
channames = lower({ chanstruct.Name });
for index = 1:length(allfields)
switch lower(allfields{index})
case { 't' 'markercount' 'markers' 'samplerate' 'segmentcount' 'channelcount' 'channels' },
otherwise
count1 = strmatch(lower(allfields{index}), channames, 'exact');
count2 = strmatch(lower(allfields{index}(2:end)), channames, 'exact');
if ~isempty(count1) | ~isempty(count2)
count = [ count1 count2 ];
count = count(1);
else
disp(['Warning: channel ''' lower(allfields{index}) ''' not in channel location structure']);
count = length(chanstruct)+1;
chanstruct(end+1).Name = allfields{index};
chanstruct(end+1).Phi = [];
chanstruct(end+1).Theta = [];
chanstruct(end+1).Radius = [];
end;
if bva.SegmentCount > 1
EEG.data(count,:,:) = getfield(bva, allfields{index})';
bva = rmfield(bva, allfields{index});
else
EEG.data(count,:) = getfield(bva, allfields{index});
bva = rmfield(bva, allfields{index});
end;
end;
end;
EEG.nbchan = size(EEG.data,1);
EEG.srate = bva.SampleRate;
EEG.xmin = bva.t(1)/1000;
EEG.xmax = bva.t(end)/1000;
EEG.pnts = size(EEG.data,2);
EEG.trials = size(EEG.data,3);
EEG.setname = 'Brain Vision Analyzer file';
EEG.comments = [ 'Original file: ' filename ];
% convert channel location structure
% ----------------------------------
disp('Importing channel location information');
for index = 1:length(chanstruct)
EEG.chanlocs(index).labels = chanstruct(index).Name;
if chanstruct(index).Radius ~= 0
EEG.chanlocs(index).sph_theta_besa = chanstruct(index).Theta;
EEG.chanlocs(index).sph_phi_besa = chanstruct(index).Phi;
EEG.chanlocs(index).sph_radius = chanstruct(index).Radius;
else
EEG.chanlocs(index).sph_theta_besa = [];
EEG.chanlocs(index).sph_phi_besa = [];
EEG.chanlocs(index).sph_radius = [];
end;
end;
EEG.chanlocs = convertlocs(EEG.chanlocs, 'sphbesa2all');
EEG.chanlocs = rmfield(EEG.chanlocs, 'sph_theta_besa');
EEG.chanlocs = rmfield(EEG.chanlocs, 'sph_phi_besa');
% convert event information
% -------------------------
disp('Importing events');
index = 0;
if isfield(bva, 'Markers')
for index1 = 1:size(bva.Markers,1)
for index2 = 0:size(bva.Markers,2)-1
if ~isempty(bva.Markers(index2*size(bva.Markers,1)+index1).Description)
index = index + 1;
EEG.event(index).type = bva.Markers(index2*size(bva.Markers,1)+index1).Description;
EEG.event(index).latency = bva.Markers(index2*size(bva.Markers,1)+index1).Position;
EEG.event(index).Points = bva.Markers(index2*size(bva.Markers,1)+index1).Points;
try
EEG.event(index).bvatype = bva.Markers(index2*size(bva.Markers,1)+index1).Type;
EEG.event(index).description = bva.Markers(index2*size(bva.Markers,1)+index1).Description;
catch, end;
try
EEG.event(index).chan = bva.Markers(index2*size(bva.Markers,1)+index1).Chan;
catch, end;
try
EEG.event(index).channelnumber = bva.Markers(index2*size(bva.Markers,1)+index1).ChannelNumber;
catch, end;
if bva.SegmentCount > 1
EEG.event(index).epoch = index1;
EEG.event(index).latency = bva.Markers(index2*size(bva.Markers,1)+index1).Position+(index1-1)*EEG.pnts;
else
EEG.event(index).latency = bva.Markers(index2*size(bva.Markers,1)+index1).Position;
end;
end;
end;
end;
end
EEG = eeg_checkset(EEG, 'makeur');
EEG = eeg_checkset(EEG, 'eventconsistency');
com = sprintf('EEG = pop_loadbva(''%s'');', filename);