forked from sccn/EEG-BIDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannelloc_to_tsv.m
36 lines (31 loc) · 1.36 KB
/
channelloc_to_tsv.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
function channelloc_to_tsv(EEG)
% From an EEG variable (i.e. EEG=pop_loadset(*.set), export the channel
% location as tsv file following the BIDS specification
%
% FORMAT channelloc_to_tvs(EEG)
%
% Author: Cyril Pernet - LIMO Team, University of Edinurgh
% list of labels for which we know it's not an EEG channel
known_labels = {'EXG','TRIG','ECG','EOG','VEOG','HEOG','EMG','MISC'};
% channel.tsv
for electrode = 1:size(EEG.chanlocs,2)
ename{electrode} = EEG.chanlocs(electrode).labels;
if contains(EEG.chanlocs(electrode).labels,known_labels)
type{electrode} = EEG.chanlocs(electrode).labels;
if contains(EEG.chanlocs(electrode).labels,'EOG')
unit{electrode} = [num2str(char(181)) 'V'];
elseif contains(EEG.chanlocs(electrode).labels,'ECG')
unit{electrode} = 'mV';
else
unit{electrode} = ' ';
end
else
type{electrode} = 'EEG';
unit{electrode} = [num2str(char(181)) 'V']; % char(181) is mu in ASCII
end
sampling_frequency(electrode) = EEG.srate;
reference{electrode} = EEG.ref;
end
t = table(ename',type',unit',sampling_frequency',reference','VariableNames',{'name','type','units','sampling_reference','reference'});
channels_tsv_name = [EEG.filepath filesep EEG.filename(1:end-4) '_channels.tsv'];
writetable(t,channels_tsv_name,'FileType','text','Delimiter','\t');