-
Notifications
You must be signed in to change notification settings - Fork 162
/
tutorial_neuromag.m
277 lines (240 loc) · 10.2 KB
/
tutorial_neuromag.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
function tutorial_neuromag(tutorial_dir)
% TUTORIAL_NEUROMAG: Script that reproduces the results of the online tutorials "MEG median nerve (Elekta)"
%
% CORRESPONDING ONLINE TUTORIALS:
% https://neuroimage.usc.edu/brainstorm/Tutorials/TutMindNeuromag
%
% INPUTS:
% tutorial_dir: Directory where the sample_neuromag.zip file has been unzipped
% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
%
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
%
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Author: Francois Tadel, 2010-2016
% ===== FILES TO IMPORT =====
% You have to specify the folder in which the tutorial dataset is unzipped
if (nargin == 0) || isempty(tutorial_dir) || ~file_exist(tutorial_dir)
error('The first argument must be the full path to the tutorial dataset folder.');
end
% Build the path of the files to import
AnatDir = fullfile(tutorial_dir, 'sample_neuromag', 'anatomy');
RawFile = fullfile(tutorial_dir, 'sample_neuromag', 'data', 'mind004_050924_median01_raw.fif');
% Check if the folder contains the required files
if ~file_exist(RawFile)
error(['The folder ' tutorial_dir ' does not contain the folder from the file sample_neuromag.zip.']);
end
% ===== CREATE PROTOCOL =====
% The protocol name has to be a valid folder name (no spaces, no weird characters...)
ProtocolName = 'TutorialNeuromag';
% Start brainstorm without the GUI
if ~brainstorm('status')
brainstorm nogui
end
% Delete existing protocol
gui_brainstorm('DeleteProtocol', ProtocolName);
% Create new protocol
gui_brainstorm('CreateProtocol', ProtocolName, 0, 0);
% Start a new report
bst_report('Start');
% ===== ANATOMY =====
% Subject name
SubjectName = 'Subject01';
% Process: Import anatomy folder
bst_process('CallProcess', 'process_import_anatomy', [], [], ...
'subjectname', SubjectName, ...
'mrifile', {AnatDir, 'FreeSurfer'}, ...
'nvertices', 15000, ...
'nas', [131 232 123], ...
'lpa', [ 48 136 74], ...
'rpa', [204 131 67]);
% ===== LINK CONTINUOUS FILE =====
% Process: Create link to raw file
sFilesRaw = bst_process('CallProcess', 'process_import_data_raw', [], [], ...
'subjectname', SubjectName, ...
'datafile', {RawFile, 'FIF'}, ...
'channelreplace', 1, ...
'channelalign', 1);
% Process: Events: Read from channel
sFilesRaw = bst_process('CallProcess', 'process_evt_read', sFilesRaw, [], ...
'stimchan', 'STI 001; STI 002', ...
'trackmode', 1, ... % Value: detect the changes of channel value
'zero', 0);
% Process: Events: Group by name (Rename)
sFilesRaw = bst_process('CallProcess', 'process_evt_groupname', sFilesRaw, [], ...
'combine', ['Right=STI 001_5' 10 'Left=STI 002_5'], ...
'dt', 0, ...
'delete', 1);
% Process: Snapshot: Sensors/MRI registration
bst_process('CallProcess', 'process_snapshot', sFilesRaw, [], ...
'target', 1, ... % Sensors/MRI registration
'modality', 1, ... % MEG (All)
'orient', 1, ... % left
'Comment', 'MEG/MRI Registration');
% ===== REMOVE 60/120/180 Hz =====
% Process: Apply SSP & CTF compensation
sFilesClean = bst_process('CallProcess', 'process_ssp_apply', sFilesRaw, []);
% Process: Notch filter: 60Hz 120Hz 180Hz
sFilesClean = bst_process('CallProcess', 'process_notch', sFilesClean, [], ...
'freqlist', [60, 120, 180], ...
'sensortypes', 'MEG, EEG', ...
'read_all', 0);
% Process: Power spectrum density (Welch)
sFilesPsd = bst_process('CallProcess', 'process_psd', [sFilesRaw, sFilesClean], [], ...
'timewindow', [0, 200], ...
'win_length', 4, ...
'win_overlap', 50, ...
'clusters', {}, ...
'sensortypes', 'MEG', ...
'edit', struct(...
'Comment', 'Power', ...
'TimeBands', [], ...
'Freqs', [], ...
'ClusterFuncTime', 'none', ...
'Measure', 'power', ...
'Output', 'all', ...
'SaveKernel', 0));
% Process: Snapshot: Frequency spectrum
bst_process('CallProcess', 'process_snapshot', sFilesPsd, [], ...
'target', 10, ... % Frequency spectrum
'modality', 1, ... % MEG (All)
'Comment', 'Power spectrum density');
% ===== CORRECT BLINKS AND HEARTBEATS =====
% Process: Detect heartbeats
sFilesClean = bst_process('CallProcess', 'process_evt_detect_ecg', sFilesClean, [], ...
'channelname', 'ECG 063', ...
'timewindow', [], ...
'eventname', 'cardiac');
% Process: Detect eye blinks
sFilesClean = bst_process('CallProcess', 'process_evt_detect_eog', sFilesClean, [], ...
'channelname', 'EOG 062', ...
'timewindow', [], ...
'eventname', 'blink');
% Process: Remove simultaneous
sFilesClean = bst_process('CallProcess', 'process_evt_remove_simult', sFilesClean, [], ...
'remove', 'cardiac', ...
'target', 'blink', ...
'dt', 0.25, ...
'rename', 0);
% Process: SSP ECG: cardiac (MAG and GRAD)
sFilesClean = bst_process('CallProcess', 'process_ssp_ecg', sFilesClean, [], ...
'eventname', 'cardiac', ...
'sensortypes', 'MEG MAG', ...
'usessp', 1, ...
'select', 1); % Force selection of some components
sFilesClean = bst_process('CallProcess', 'process_ssp_ecg', sFilesClean, [], ...
'eventname', 'cardiac', ...
'sensortypes', 'MEG GRAD', ...
'usessp', 1, ...
'select', 1); % Force selection of some components
% Process: SSP EOG: blink (MAG and GRAD)
sFilesClean = bst_process('CallProcess', 'process_ssp_eog', sFilesClean, [], ...
'eventname', 'blink', ...
'sensortypes', 'MEG MAG', ...
'usessp', 1, ...
'select', 1); % Force selection of some components
sFilesClean = bst_process('CallProcess', 'process_ssp_eog', sFilesClean, [], ...
'eventname', 'blink', ...
'sensortypes', 'MEG GRAD', ...
'usessp', 1, ...
'select', 1); % Force selection of some components
% Process: Snapshot: SSP projectors
bst_process('CallProcess', 'process_snapshot', sFilesClean, [], ...
'target', 2, ... % SSP projectors
'Comment', 'SSP projectors');
% ===== IMPORT EVENTS =====
% Process: Import MEG/EEG: Events
sFilesEpochs = bst_process('CallProcess', 'process_import_data_event', sFilesClean, [], ...
'subjectname', SubjectName, ...
'condition', '', ...
'eventname', 'Right, Left', ...
'timewindow', [], ...
'epochtime', [-0.1, 0.3], ...
'createcond', 0, ...
'ignoreshort', 1, ...
'usectfcomp', 1, ...
'usessp', 1, ...
'freq', [], ...
'baseline', [-0.1, 0]);
% Process: Average: By condition (subject average)
sFilesAvg = bst_process('CallProcess', 'process_average', sFilesEpochs, [], ...
'avgtype', 6, ... % By trial groups (subject average)
'avg_func', 1, ... % Arithmetic average: mean(x)
'keepevents', 0);
% Process: Cut stimulation artifact: [0ms,4ms]
sFilesAvg = bst_process('CallProcess', 'process_cutstim', sFilesAvg, [], ...
'timewindow', [0, 0.0039], ...
'sensortypes', 'MEG, EEG', ...
'overwrite', 1);
% Process: Snapshot: Recordings time series
bst_process('CallProcess', 'process_snapshot', sFilesAvg, [], ...
'target', 5, ... % Recordings time series
'modality', 1, ... % MEG (All)
'Comment', 'Evoked response');
% ===== SOURCE MODELING =====
% Process: Compute head model
bst_process('CallProcess', 'process_headmodel', sFilesAvg, [], ...
'comment', '', ...
'sourcespace', 1, ...
'meg', 3); % Overlapping spheres
% Process: Compute noise covariance
bst_process('CallProcess', 'process_noisecov', sFilesEpochs, [], ...
'baseline', [-0.100, 0], ...
'dcoffset', 1, ...
'identity', 0, ...
'copycond', 0, ...
'copysubj', 0);
% Process: Compute sources
sFilesSrc = bst_process('CallProcess', 'process_inverse', sFilesAvg, [], ...
'comment', '', ...
'method', 2, ... % dSPM
'wmne', struct(...
'NoiseCov', [], ...
'InverseMethod', 'dspm2018', ...
'ChannelTypes', {{}}, ...
'SNR', 3, ...
'diagnoise', 0, ...
'SourceOrient', {{'fixed'}}, ...
'loose', 0.2, ...
'depth', 1, ...
'weightexp', 0.5, ...
'weightlimit', 10, ...
'regnoise', 1, ...
'magreg', 0.1, ...
'gradreg', 0.1, ...
'eegreg', 0.1, ...
'ecogreg', 0.1, ...
'seegreg', 0.1, ...
'fMRI', [], ...
'fMRIthresh', [], ...
'fMRIoff', 0.1, ...
'pca', 1), ...
'sensortypes', 'MEG, MEG MAG, MEG GRAD, EEG', ...
'output', 1); % Kernel only: shared
% Process: Snapshot: Noise covariance
bst_process('CallProcess', 'process_snapshot', sFilesSrc, [], ...
'target', 3, ... % Noise covariance
'Comment', 'Noise covariance');
% Process: Snapshot: Sources (one time)
bst_process('CallProcess', 'process_snapshot', sFilesSrc, [], ...
'target', 8, ... % Sources (one time)
'modality', 1, ... % MEG (All)
'orient', 3, ... % top
'time', 0.023, ...
'Comment', 'Source maps at 35ms');
% Save and display report
ReportFile = bst_report('Save', sFilesSrc);
bst_report('Open', ReportFile);