-
Notifications
You must be signed in to change notification settings - Fork 9
/
eeg_pac_test_cases.m
396 lines (384 loc) · 25.6 KB
/
eeg_pac_test_cases.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
% Testing cases for eeg_pac function.
% Useful guide for the use of different combinations and methods in the
% toolbox
%
% Author: Ramon Martinez Cancino SCCN/INC, UCSD 2018
%
% Copyright (C) 2018 Martinez Cancino, INC, SCCN
%
% 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
%% Parameters
% Signal parameters
fc = 60; % Frequency of the carrier wave. Recommended: [60]
fm = 8; % Frequency of the modulating wave. Recommended: [60]
max_time = 7; % Time of the simulation. Recommended: single trial [6], multiple trials [2]
n_trials = 200; % Number of trials. Recommended: single trial [1], multiple trials [1000]
s_rate = 500; % Sampling rate. Recommended: single trial [500], multiple trials [250]
padtime = 0; % Padding time at the start and end of the signal.
snrval = 50; % Signal to noise ratio. Recommended: [5]
maxshift = 10; % Maximum shifts (jitter) injected into the data. Recommended: single trial [1], multiple trials [10]
nsegm = 5; % Number of segments in the data. Each segment is a block with our without modulation
% Method parameters
nfreqsphase = 3; % Number of frequencies used for the phase. Recommended: [10]
nfreqsamp = 2; % Number of frequencies used for the amplitude. Recommended: [10]
alpha = 0.05; % Alpha value used for statistics. If alpha = [] the statistics are not computed.
% Recommended: [0.05] (or [] for less computationtime)
compute_mvl = true; % Compute the Mean Vector Length Modulation Index
compute_kl = true; % Compute the Kullback Leibler Modulation Index
compute_glm = true; % Compute the GLM Modulation Index
phaserange = 8; % Range of phases to be used
% Recommended: [4 25]
amprange = 60; % Range of amplitudes to be used Recommended: [30 100]
nsurrogate = 10; % Number of surrogates. Recommended: [200].
nbinskl = 18; % Number of bins for the Kullback Leibler Modulation
% index. Recommended: [8]
% Do not modify the code beyond this point
%% Generate 1D data
tlimits = [0 max_time];
plot_flag = 1;
[~, data_singletrial,t_outtmp] = pop_genpac(fc,fm,tlimits,'Ac',5,'Am',1,'srate',s_rate,'cpfunc','block','blockamp',1, 'nsegm',nsegm,'plot_flag', plot_flag,'padtime',padtime,'snr',snrval,'m',1);
%% INSTMIPAC (no surr)
try
mipacvarthreshval =0.002;
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_singletrial', data_singletrial', s_rate,...
'method', 'instmipac',...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'nfreqs2', nfreqsamp,...
'freqs2', amprange,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'butterorder', 6, ...
'mipacvarthresh', mipacvarthreshval,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', length(data_singletrial));
disp(' Successful computation: INSTMIPAC (no surr)');
catch
disp('Error computing: INSTMIPAC (no surr)');
end
%% MVLMI (no surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_singletrial', data_singletrial', s_rate,...
'method', 'mvlmi',...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'nfreqs2', nfreqsamp,...
'freqs2', amprange,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', length(data_singletrial));
disp(' Successful computation: MVLMI (no surr)');
catch
disp('Error computing: MVLMI (no surr)');
end
%% GLM (no surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_singletrial', data_singletrial', s_rate,...
'method', 'glm',...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'nfreqs2', nfreqsamp,...
'freqs2', amprange,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', length(data_singletrial));
catch
disp('Error computing: GLM (no surr)');
end
%% KLMI (no surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_singletrial', data_singletrial', s_rate,...
'method', 'klmi',...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'nfreqs2', nfreqsamp,...
'freqs2', amprange,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', length(data_singletrial));
disp(' Successful computation: KLMI (no surr)');
catch
disp('Error computing: KLMI (no surr)');
end
%% INSTMIPAC (surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_singletrial', data_singletrial', s_rate,...
'method', 'instmipac',...
'alpha', alpha ,...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'nfreqs2', nfreqsamp,...
'freqs2', amprange,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', length(data_singletrial));
disp(' Successful computation: INSTMIPAC (surr)');
catch
disp('Error computing: INSTMIPAC (surr)');
end
%% MVLMI (surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_singletrial', data_singletrial', s_rate,...
'method', 'mvlmi',...
'alpha', alpha ,...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'nfreqs2', nfreqsamp,...
'freqs2', amprange,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', length(data_singletrial));
disp(' Successful computation: MVLMI (surr)');
catch
disp('Error computing: MVLMI (surr)');
end
%% GLM (surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_singletrial', data_singletrial', s_rate,...
'method', 'glm',...
'alpha', alpha ,...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'nfreqs2', nfreqsamp,...
'freqs2', amprange,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', length(data_singletrial));
disp(' Successful computation: GLM (surr)');
catch
disp('Error computing: GLM (surr)');
end
%% KLMI (surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_singletrial', data_singletrial', s_rate,...
'method', 'klmi',...
'alpha', alpha ,...
'freqs', phaserange ,...
'alpha', alpha ,...
'nfreqs1', nfreqsphase,...
'nfreqs2', nfreqsamp,...
'freqs2', amprange,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', length(data_singletrial));
disp(' Successful computation: KLMI (surr)');
catch
disp('Error computing: KLMI (surr)');
end
%% Generate 2D data
nfreqsphase = 1;
nfreqsamp = 1;
tlimits = [-1 1];
s_rate = 100;
snrval = 10;
[~, data_pac,t_outtmp] = pop_genpac(fc,fm,tlimits,'Ac',5,'Am',1,'srate',s_rate,'cpfunc','block','blockamp',1, 'nsegm',nsegm,'plot_flag', plot_flag,'padtime',padtime,'snr',snrval,'m',1,'ntrials',n_trials,'maxshift',10);
%% MVLMI (no surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_pac, data_pac, s_rate,...
'method', 'mvlmi',...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'freqs2', amprange,...
'nfreqs2', nfreqsamp,...
'winsize', s_rate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', size(data_pac,2));
disp(' Successful computation: MVLMI (no surr) 2D');
catch
disp('Error computing: MVLMI (no surr) 2D');
end
%% MVLMI (w surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_pac, data_pac, s_rate,...
'method', 'mvlmi',...
'alpha', alpha ,...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'freqs2', amprange,...
'nfreqs2', nfreqsamp,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'tlimits', tlimits, ...
'bonfcorr', 1,...
'freqscale', 'linear',...
'ntimesout', size(data_pac,2));
disp(' Successful computation: MVLMI (w surr) 2D');
catch
disp('Error computing: MVLMI (w surr) 2D');
end
%% KLMI (no surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_pac, data_pac, s_rate,...
'method', 'klmi',...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'freqs2', amprange,...
'nfreqs2', nfreqsamp,...
'winsize', s_rate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', size(data_pac,2));
disp(' Successful computation: KLMI (no surr) 2D');
catch
disp('Error computing: KLMI (no surr) 2D');
end
%% KLMI (w surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_pac, data_pac, s_rate,...
'method', 'klmi',...
'alpha', alpha ,...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'freqs2', amprange,...
'nfreqs2', nfreqsamp,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'tlimits', tlimits, ...
'bonfcorr', 1,...
'freqscale', 'linear',...
'ntimesout', size(data_pac,2));
disp(' Successful computation: KLMI (w surr) 2D');
catch
disp('Error computing: KLMI (w surr) 2D');
end
%% GLMmi (no surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_pac, data_pac, s_rate,...
'method', 'glm',...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'freqs2', amprange,...
'nfreqs2', nfreqsamp,...
'winsize', s_rate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', size(data_pac,2));
disp(' Successful computation: GLMmi (no surr) 2D');
catch
disp('Error computing: GLMmi (no surr) 2D');
end
%% GLMmi (w surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_pac, data_pac, s_rate,...
'method', 'glm',...
'alpha', alpha ,...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'freqs2', amprange,...
'nfreqs2', nfreqsamp,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'tlimits', tlimits, ...
'bonfcorr', 1,...
'freqscale', 'linear',...
'ntimesout', size(data_pac,2));
disp(' Successful computation: GLMmi (w surr) 2D');
catch
disp('Error computing: GLMmi (w surr) 2D');
end
%% ERMIPAC (no surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_pac, data_pac, s_rate,...
'method', 'ermipac',...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'freqs2', amprange,...
'nfreqs2', nfreqsamp,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'tlimits', tlimits, ...
'bonfcorr', 1,...
'freqscale', 'linear',...
'ntimesout', size(data_pac,2));
disp(' Successful computation: ERMIPAC (no surr) 2D');
catch
disp('Error computing: ERMIPAC (no surr) 2D');
end
%% ERMIPAC (w surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_pac, data_pac, s_rate,...
'method', 'ermipac',...
'alpha', alpha,...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'freqs2', amprange,...
'nfreqs2', nfreqsamp,...
'winsize', s_rate,...
'nboot', nsurrogate,...
'timefreq', 1,...
'tlimits', tlimits, ...
'bonfcorr', 1,...
'freqscale', 'linear',...
'ntimesout', size(data_pac,2));
disp(' Successful computation: ERMIPAC (w surr) 2D');
catch
disp('Error computing: ERMIPAC (w surr) 2D');
end
%%
%% Compute PAC multiple freqs
phaserange = [8 712];
amprange = [60 70];
nfreqsphase = 3;
nfreqsamp = 3;
%% MVLMI (no surr)
try
[pacval, ~, ~, ~, ~, ~,~, pacstruct] = eeg_pac(data_pac, data_pac, s_rate,...
'method', 'mvlmi',...
'freqs', phaserange ,...
'nfreqs1', nfreqsphase,...
'freqs2', amprange,...
'nfreqs2', nfreqsamp,...
'winsize', s_rate,...
'timefreq', 1,...
'freqscale', 'linear',...
'ntimesout', size(data_pac,2));
disp(' Successful computation: MVLMI (no surr) multiple freqs');
catch
disp('Error computing: MVLMI (no surr) multiple freqs');
end
%% TESTING pop_pac
try
tlimits = [0 7];
padtime = 1;
snrval = 20;
EEG = pop_genpac(fc,fm,tlimits,'Ac',5,'Am',1,'srate',s_rate,'cpfunc','block','blockamp',1, 'nsegm',nsegm,'plot_flag', 1,'padtime',padtime,'snr',snrval,'m',1,'ntrials',1,'nchan',3);
EEG = pop_pac(EEG,'Channels',[4 15],[30 100],[1 2],[1 2],'method','mvlmi', 'nboot',200,'alpha',[],'nfreqs1',6,'nfreqs2',7,'bonfcorr',0,'freqscale', 'linear');
EEG = pop_pac(EEG,'Channels',[4 15],[30 100],[1 2],[1 2],'method','klmi', 'nboot',200,'alpha',[],'nfreqs1',6,'nfreqs2',7,'bonfcorr',0,'freqscale', 'linear');
EEG = pop_pac(EEG,'Channels',[4 15],[30 100],[1 2],[1 2],'method','glm', 'nboot',200,'alpha',[],'nfreqs1',6,'nfreqs2',7,'bonfcorr',0,'freqscale', 'linear');
EEG = pop_pac(EEG,'Channels',[4 15],[30 100],[1 2],[1 2],'method','instmipac','nboot',200,'alpha',[],'nfreqs1',6,'nfreqs2',7,'bonfcorr',0,'freqscale', 'linear');
disp(' Successful computation: pop_pac.m');
catch
disp('Error computing: pop_pac.m');
end