-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchanscale_common.m
176 lines (162 loc) · 7.63 KB
/
chanscale_common.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
function data = chanscale_common(cfg, data)
% CHANSCALE_COMMON applies a scaling to specific channel types
%
% Use as
% data = chanscale_common(cfg, data)
% where the configuration contains
% cfg.parameter
%
% For specific channel groups you can use
% cfg.eegscale = number, scaling to apply to the EEG channels prior to display
% cfg.eogscale = number, scaling to apply to the EOG channels prior to display
% cfg.ecgscale = number, scaling to apply to the ECG channels prior to display
% cfg.emgscale = number, scaling to apply to the EMG channels prior to display
% cfg.megscale = number, scaling to apply to the MEG channels prior to display
% cfg.magscale = number, scaling to apply to the MEG magnetometer channels prior to display (in addition to the cfg.megscale factor)
% cfg.gradscale = number, scaling to apply to the MEG gradiometer channels prior to display (in addition to the cfg.megscale factor)
%
% For individual control off the scaling for all channels you can use
% cfg.chanscale = Nx1 vector with scaling factors, one per channel specified in cfg.channel
%
% For control over specific channels you can use
% cfg.mychanscale = number, scaling to apply to the channels specified in cfg.mychan
% cfg.mychan = Nx1 cell-array with selection of channels
% Copyright (C) 2017, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
% FieldTrip 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 3 of the License, or
% (at your option) any later version.
%
% FieldTrip 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 FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$
cfg.eegscale = ft_getopt(cfg, 'eegscale');
cfg.eogscale = ft_getopt(cfg, 'eogscale');
cfg.ecgscale = ft_getopt(cfg, 'ecgscale');
cfg.emgscale = ft_getopt(cfg, 'emgscale');
cfg.megscale = ft_getopt(cfg, 'megscale');
cfg.gradscale = ft_getopt(cfg, 'gradscale');
cfg.magscale = ft_getopt(cfg, 'magscale');
cfg.chanscale = ft_getopt(cfg, 'chanscale');
cfg.mychanscale = ft_getopt(cfg, 'mychanscale');
cfg.mychan = ft_getopt(cfg, 'mychan');
% these should be column vectors
cfg.chanscale = cfg.chanscale(:);
cfg.mychanscale = cfg.mychanscale(:);
dimord = getdimord(data, cfg.parameter);
switch dimord
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case {'chan_time' 'chan_freq' 'chan_comp' 'chan_freq_time' 'chan_time_freq'}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% get the data from the structure
dat = data.(cfg.parameter);
% apply scaling to selected channels, using wildcard to support subselection of channels
if ~isempty(cfg.eegscale)
chansel = match_str(data.label, ft_channelselection('EEG', data.label));
dat(chansel,:,:) = dat(chansel,:,:) .* cfg.eegscale;
end
if ~isempty(cfg.eogscale)
chansel = match_str(data.label, ft_channelselection('EOG', data.label));
dat(chansel,:,:) = dat(chansel,:,:) .* cfg.eogscale;
end
if ~isempty(cfg.ecgscale)
chansel = match_str(data.label, ft_channelselection('ECG', data.label));
dat(chansel,:,:) = dat(chansel,:,:) .* cfg.ecgscale;
end
if ~isempty(cfg.emgscale)
chansel = match_str(data.label, ft_channelselection('EMG', data.label));
dat(chansel,:,:) = dat(chansel,:,:) .* cfg.emgscale;
end
if ~isempty(cfg.megscale)
type = opt.hdr.grad.type;
chansel = match_str(data.label, ft_channelselection('MEG', data.label, type));
dat(chansel,:,:) = dat(chansel,:,:) .* cfg.megscale;
end
if ~isempty(cfg.magscale)
chansel = match_str(data.label, ft_channelselection('MEGMAG', data.label));
dat(chansel,:,:) = dat(chansel,:,:) .* cfg.magscale;
end
if ~isempty(cfg.gradscale)
chansel = match_str(data.label, ft_channelselection('MEGGRAD', data.label));
dat(chansel,:,:) = dat(chansel,:,:) .* cfg.gradscale;
end
if ~isempty(cfg.chanscale)
chansel = match_str(data.label, ft_channelselection(cfg.channel, data.label));
dat(chansel,:,:) = dat(chansel,:,:) .* repmat(cfg.chanscale,1,size(dat,2),size(dat,3));
end
if ~isempty(cfg.mychanscale)
[chansel, scalesel] = match_str(data.label, cfg.mychan);
dat(chansel,:,:) = dat(chansel,:,:) .* repmat(cfg.mychanscale(scalesel),1,size(dat,2),size(dat,3));
end
% put the data back into the structure
data.(cfg.parameter) = dat;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case '{rpt}_chan_time'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:numel(data.(cfg.parameter))
% get the data from the structure
dat = data.(cfg.parameter){i};
% apply scaling to selected channels, using wildcard to support subselection of channels
if ~isempty(cfg.eegscale)
chansel = match_str(data.label, ft_channelselection('EEG', data.label));
dat(chansel,:) = dat(chansel,:) .* cfg.eegscale;
end
if ~isempty(cfg.eogscale)
chansel = match_str(data.label, ft_channelselection('EOG', data.label));
dat(chansel,:) = dat(chansel,:) .* cfg.eogscale;
end
if ~isempty(cfg.ecgscale)
chansel = match_str(data.label, ft_channelselection('ECG', data.label));
dat(chansel,:) = dat(chansel,:) .* cfg.ecgscale;
end
if ~isempty(cfg.emgscale)
chansel = match_str(data.label, ft_channelselection('EMG', data.label));
dat(chansel,:) = dat(chansel,:) .* cfg.emgscale;
end
if ~isempty(cfg.megscale)
type = opt.hdr.grad.type;
chansel = match_str(data.label, ft_channelselection('MEG', data.label, type));
dat(chansel,:) = dat(chansel,:) .* cfg.megscale;
end
if ~isempty(cfg.magscale)
chansel = match_str(data.label, ft_channelselection('MEGMAG', data.label));
dat(chansel,:) = dat(chansel,:) .* cfg.magscale;
end
if ~isempty(cfg.gradscale)
chansel = match_str(data.label, ft_channelselection('MEGGRAD', data.label));
dat(chansel,:) = dat(chansel,:) .* cfg.gradscale;
end
if ~isempty(cfg.chanscale)
chansel = match_str(data.label, ft_channelselection(cfg.channel, data.label));
dat(chansel,:) = dat(chansel,:) .* repmat(cfg.chanscale,1,size(dat,2));
end
if ~isempty(cfg.mychanscale)
[chansel, scalesel] = match_str(data.label, cfg.mychan);
dat(chansel,:) = dat(chansel,:) .* repmat(cfg.mychanscale(scalesel),1,size(dat,2));
end
% put the data back into the structure
data.(cfg.parameter){i} = dat;
end % for each trial
otherwise
if ~isempty(cfg.eegscale) || ...
~isempty(cfg.eogscale) || ...
~isempty(cfg.ecgscale) || ...
~isempty(cfg.emgscale) || ...
~isempty(cfg.megscale) || ...
~isempty(cfg.magscale) || ...
~isempty(cfg.gradscale) || ...
~isempty(cfg.chanscale) || ...
~isempty(cfg.mychanscale)
ft_error('unsupported dimord "%s"', dimord);
end
end % switch dimord