-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathni2_sensors.m
122 lines (104 loc) · 3.52 KB
/
ni2_sensors.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
function sens = ni2_sensors(varargin)
% NI2_SENSORS creates an EEG or MEG sensor array.
%
% Use as
% sens = ni2_sensors('type', 'eeg')
% sens = ni2_sensors('type', 'meg')
% sens = ni2_sensors('type', 'ctf151')
% sens = ni2_sensors('type', 'ctf275')
% sens = ni2_sensors('type', 'bti248')
% sens = ni2_sensors('type', 'neuromag306')
% sens = ni2_sensors('type', 'eeg1020')
% sens = ni2_sensors('type', 'eeg1010')
%
% The default EEG sensor array consists of 91 electrodes over the upper half of a
% sphere. The default MEG sensor array consists of 301 axial magnetometers over the
% upper half of a sphere.
%
% Note that the units and the coordinate systems in which the sensors are described
% can differ.
type = ft_getopt(varargin, 'type', 'eeg');
jitter = ft_getopt(varargin, 'jitter', 0);
n = ft_getopt(varargin, 'n', 162); % number of vertices for the sphere, determines the number of electrodes, this is the old default
switch type
case 'eeg'
% create an electrode array
[chanpos, tri] = mesh_sphere(n);
chanpos = chanpos*10;
chanpos(chanpos(:,3)<0,:) = [];
if jitter
[th,phi,r] = cart2sph(chanpos(:,1), chanpos(:,2), chanpos(:,3));
shift1 = 2*jitter*(rand(numel(th),1) - 1);
shift2 = 2*jitter*(rand(numel(phi),1) - 1);
[chanpos(:,1),chanpos(:,2),chanpos(:,3)] = sph2cart(th+shift1(:),phi+shift2(:),r);
end
sens.unit = 'cm';
sens.coordsys = 'ctf';
sens.chanpos = chanpos;
sens.elecpos = chanpos;
for k = 1:size(chanpos,1)
sens.label{k,1} = sprintf('eeg% 02d', k);
sens.chantype{k,1} = 'eeg';
end
sens = ft_datatype_sens(sens);
case {'meg'}
% create a magnetometer array
[chanpos, tri] = icosahedron642;
coilori = chanpos;
chanpos = chanpos*12.5;
chanpos(:,3) = chanpos(:,3) - 1.5;
z = chanpos(:,3);
coilori = coilori(z>0,:);
chanpos = chanpos(z>0,:);
nchan = size(chanpos,1);
sens.unit = 'cm';
sens.coordsys = 'ctf';
sens.chanpos = chanpos;
sens.chanori = coilori;
sens.coilpos = chanpos;
sens.coilori = coilori;
sens.tra = eye(nchan);
for k = 1:nchan
sens.label{k,1} = sprintf('meg% 03d', k);
sens.chantype{k,1} = 'megmag';
end
sens = ft_datatype_sens(sens);
case 'ctf151'
load('ctf151');
% only keep the normal MEG channels
sel = strcmp(sens.chantype, 'meggrad');
sens.label = sens.label(sel);
sens.chantype = sens.chantype(sel);
sens.chanunit = sens.chanunit(sel);
sens.tra = sens.tra(sel,:);
sens.chanpos = sens.chanpos(sel,:);
sens.chanori = sens.chanori(sel,:);
case 'ctf275'
load('ctf275');
% only keep the normal MEG channels
sel = strcmp(sens.chantype, 'meggrad');
sens.label = sens.label(sel);
sens.chantype = sens.chantype(sel);
sens.chanunit = sens.chanunit(sel);
sens.tra = sens.tra(sel,:);
sens.chanpos = sens.chanpos(sel,:);
sens.chanori = sens.chanori(sel,:);
case 'bti248'
load('bti248');
% only keep the normal MEG channels
sel = strcmp(sens.chantype, 'megmag');
sens.label = sens.label(sel);
sens.chantype = sens.chantype(sel);
sens.chanunit = sens.chanunit(sel);
sens.tra = sens.tra(sel,:);
sens.chanpos = sens.chanpos(sel,:);
sens.chanori = sens.chanori(sel,:);
case 'neuromag306'
load('neuromag306');
case 'eeg1020'
load('eeg1020');
case 'eeg1010'
load('eeg1010');
otherwise
error('unsupported type % s', type);
end