0001 function vb_meg_tutorial(tut_code)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 if ~exist('tut_code', 'var'), tut_code = []; end
0020 [tut_code, data_root] = inner_solve_env(tut_code);
0021
0022
0023
0024
0025
0026 proj_root = './tutorial/MEG/vbmeg_data';
0027
0028 switch tut_code
0029
0030
0031 case 1001
0032
0033 meg_parm = vb_meg_parm_set_measurement([], 'MEG', 'YOKOGAWA');
0034
0035 meg_data_dir = [data_root '/AM090311'];
0036 pos_data_dir = [data_root '/AM090311-POS'];
0037 meg_parm.yokogawa_file = [meg_data_dir '/AM090311a.con'];
0038 meg_parm.pos_file = [pos_data_dir '/AM090311.pos.mat'];
0039
0040
0041
0042 meg_parm.meg_file = sprintf('test.meg.mat');
0043
0044
0045
0046
0047
0048
0049
0050
0051 vb_job_meg(proj_root, meg_parm);
0052
0053 case 1002
0054
0055 meg_parm = vb_meg_parm_set_measurement([], 'MEG', 'YOKOGAWA');
0056 meg_data_dir = [data_root '/AM090311'];
0057 meg_parm.yokogawa_file = [meg_data_dir '/AM090311a.con'];
0058
0059
0060 meg_parm.meg_file = sprintf('test_%d.meg.mat', tut_code);
0061
0062 meg_parm.memory_max = 10000000;
0063 meg_parm.ex_ch_gain = [];
0064
0065 saveman.data_dir = sprintf('./binary_data_%d', tut_code);
0066 saveman.precision = 'float64';
0067 meg_parm.saveman = saveman;
0068
0069 vb_job_meg(proj_root, meg_parm);
0070
0071 case 1003
0072
0073 base_no = 1002;
0074
0075 meg_data_dir = proj_root;
0076 pos_data_dir = [data_root '/AM090311-POS'];
0077
0078 pos_file = [pos_data_dir '/AM090311.pos.mat'];
0079 meg_file = [meg_data_dir '/' sprintf('test_%d.meg.mat', base_no)];
0080
0081 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0082
0083 result = vb_posfile_remake_datafile(pos_file, meg_file, new_file);
0084 return;
0085
0086 case 1101
0087
0088 test_data_no = 1001;
0089
0090 file_name = sprintf('test_%d.meg.mat', test_data_no);
0091 meg_file = [proj_root '/' file_name];
0092
0093 new_file = sprintf('%s/load_%d.meg.mat', proj_root, tut_code);
0094 [meg_data, ch_info] = vb_load_meg_data(meg_file);
0095
0096 case 1102
0097
0098 base_no = 1001;
0099
0100 file_name = sprintf('test_%d.meg.mat', base_no);
0101 meg_file = [proj_root '/' file_name];
0102
0103 loadspec.ChannelType = 'EXTRA';
0104
0105 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0106 [meg_data, ch_info] = vb_load_meg_data(meg_file, loadspec, new_file);
0107
0108 case 1103
0109
0110 base_no = 1001;
0111
0112 file_name = sprintf('test_%d.meg.mat', base_no);
0113 meg_file = [proj_root '/' file_name];
0114
0115 loadspec.ChannelType = 'REFERENCE';
0116
0117 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0118 [meg_data, ch_info] = vb_load_meg_data(meg_file, loadspec, new_file);
0119
0120 case 1111
0121
0122 test_data_no = 1001;
0123
0124 file_name = sprintf('test_%d.meg.mat', test_data_no);
0125 meg_file = [proj_root '/' file_name];
0126
0127
0128
0129 ch_info_axial = vb_load_channel_info(meg_file, 'AXIAL');
0130
0131
0132
0133
0134
0135
0136 loadspec.ChannelName = ch_info_axial.Name;
0137
0138 new_file = sprintf('%s/load_%d.meg.mat', proj_root, tut_code);
0139 [meg_data, ch_info] = vb_load_meg_data(meg_file, loadspec, new_file);
0140
0141 case 1112
0142
0143 test_data_no = 1001;
0144
0145 file_name = sprintf('test_%d.meg.mat', test_data_no);
0146 meg_file = [proj_root '/' file_name];
0147
0148
0149
0150 ch_info_planar = vb_load_channel_info(meg_file, 'PLANAR');
0151
0152
0153
0154
0155
0156
0157 loadspec.ChannelName = ch_info_planar.Name;
0158
0159 new_file = sprintf('%s/load_%d.meg.mat', proj_root, tut_code);
0160 [meg_data, ch_info] = vb_load_meg_data(meg_file, loadspec, new_file);
0161
0162 case 1121
0163
0164 test_data_no = 1001;
0165 org_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0166 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0167 loadspec.ChannelType = 'ALL';
0168 loadspec.Trigger = [2000; 5000; 8000; 11000; 14000; 17000; 20000];
0169 loadspec.Pretrigger = 200;
0170 loadspec.Posttrigger = 2000;
0171 [loaded_data, ch_info] = vb_load_meg_data(org_file, loadspec, new_file);
0172
0173 case 1122
0174
0175 test_data_no = 1121;
0176 org_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0177 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0178 loadspec.ChannelType = 'ALL';
0179 loadspec.TrialNumber = [2;4;5];
0180 [loaded_data, ch_info] = vb_load_meg_data(org_file, loadspec, new_file);
0181
0182 case 2011
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 test_data_no = 1001;
0202
0203 file_name = sprintf('test_%d.meg.mat', test_data_no);
0204 meg_file = [proj_root '/' file_name];
0205
0206 meg_info = vb_load_meg_info(meg_file);
0207 vb_util_show_struct(meg_info, 0);
0208
0209 meg_info = vb_load_meg_info(meg_file, 1);
0210 vb_util_show_struct(meg_info, 0);
0211
0212 meg_info = vb_load_meg_info(meg_file, 2);
0213 vb_util_show_struct(meg_info, 0);
0214
0215 meg_info = vb_load_meg_info(meg_file, 3);
0216 vb_util_show_struct(meg_info, 0);
0217
0218 meg_info = vb_load_meg_info(meg_file, 4);
0219 vb_util_show_struct(meg_info, 0);
0220
0221 meg_info = vb_load_meg_info(meg_file, 5);
0222 vb_util_show_struct(meg_info, 0);
0223
0224 meg_info = vb_load_meg_info(meg_file, 6);
0225 vb_util_show_struct(meg_info, 0);
0226
0227 meg_info = vb_load_meg_info(meg_file, 7);
0228 vb_util_show_struct(meg_info, 0);
0229
0230 meg_info = vb_load_meg_info(meg_file, 8);
0231 vb_util_show_struct(meg_info, 0);
0232
0233 meg_info = vb_load_meg_info(meg_file, 9);
0234 vb_util_show_struct(meg_info, 0);
0235
0236 meg_info = vb_load_meg_info(meg_file, 10);
0237 vb_util_show_struct(meg_info, 0);
0238
0239 meg_info = vb_load_meg_info(meg_file, 11);
0240 vb_util_show_struct(meg_info, 0);
0241
0242 meg_info = vb_load_meg_info(meg_file, 12);
0243 vb_util_show_struct(meg_info, 0);
0244
0245 meg_info = vb_load_meg_info(meg_file, 13);
0246 vb_util_show_struct(meg_info, 0);
0247
0248 meg_info = vb_load_meg_info(meg_file, 14);
0249 vb_util_show_struct(meg_info, 0);
0250
0251 meg_info = vb_load_meg_info(meg_file, 15);
0252 vb_util_show_struct(meg_info, 0);
0253 return;
0254
0255 case 2021
0256 test_data_no = 1001;
0257
0258 file_name = sprintf('test_%d.meg.mat', test_data_no);
0259 meg_file = [proj_root '/' file_name];
0260
0261
0262 [ch_info] = vb_load_channel_info(meg_file);
0263 vb_util_show_struct(ch_info);
0264
0265
0266 [ch_info] = vb_load_channel_info(meg_file, 'MEG');
0267 vb_util_show_struct(ch_info);
0268
0269 [ch_info] = vb_load_channel_info(meg_file, 'EEG');
0270 vb_util_show_struct(ch_info);
0271
0272 [ch_info] = vb_load_channel_info(meg_file, 'EXTRA');
0273 vb_util_show_struct(ch_info);
0274
0275 [ch_info] = vb_load_channel_info(meg_file, 'REFERENCE');
0276 vb_util_show_struct(ch_info);
0277
0278 [ch_info] = vb_load_channel_info(meg_file, 'ALL');
0279 vb_util_show_struct(ch_info);
0280
0281 [ch_info] = vb_load_channel_info(meg_file, 'AXIAL');
0282 vb_util_show_struct(ch_info);
0283
0284 [ch_info] = vb_load_channel_info(meg_file, 'PLANAR');
0285 vb_util_show_struct(ch_info);
0286
0287 [ch_info] = vb_load_channel_info(meg_file, 'UNKNOWN');
0288 vb_util_show_struct(ch_info);
0289
0290 [ch_info] = vb_load_channel_info(meg_file, 'USER', {'10';'100';'200'});
0291 vb_util_show_struct(ch_info);
0292
0293 [ch_info] = vb_load_channel_info(meg_file, 'USER', [13;23;33;43;53;303]);
0294 vb_util_show_struct(ch_info);
0295
0296
0297 [ch_info] = vb_load_channel_info(meg_file, 2);
0298 vb_util_show_struct(ch_info);
0299
0300 [ch_info] = vb_load_channel_info(meg_file, 3);
0301 vb_util_show_struct(ch_info);
0302
0303 [ch_info] = vb_load_channel_info(meg_file, -1);
0304 vb_util_show_struct(ch_info);
0305
0306 [ch_info] = vb_load_channel_info(meg_file, -2);
0307 vb_util_show_struct(ch_info);
0308 return;
0309
0310 case 2022
0311
0312
0313
0314 test_data_no = 1001;
0315
0316 file_name = sprintf('test_%d.meg.mat', test_data_no);
0317 meg_file = [proj_root '/' file_name];
0318
0319 [p,q,c,v] = vb_load_sensor(meg_file);
0320 fprintf('[pick] size(p) = [%d x %d]\n', size(p,1), size(p,2));
0321 fprintf('[Qpick] size(q) = [%d x %d]\n', size(q,1), size(q,2));
0322 fprintf('[CoilWeight] size(c) = [%d x %d]\n', size(c,1), size(c,2));
0323 fprintf('[Vcenter] = (%f,%f,%f)\n', v(1),v(2),v(3));
0324 return;
0325
0326 case 3001
0327
0328 test_data_no = 1001;
0329 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0330
0331 proc_spec = [];
0332
0333 parm.filt_suffix = '_filt';
0334 parm.bias_flg = 1;
0335 parm.highpass = 0.5000;
0336 parm.lowpass = 100;
0337 parm.highpass_online = 1;
0338 parm.lowpass_online = 0;
0339 parm.common_flg = 0;
0340 parm.fsamp = [];
0341
0342 proc_spec.parm = parm;
0343
0344
0345 proc_spec.new_meg = sprintf('filtered_%d.meg.mat', tut_code);
0346 proc_spec.new_bin_dir = sprintf('binary_data_%d', tut_code);
0347
0348 result = vb_megfile_filter_ch_data(meg_file, proc_spec);
0349
0350 case 3002
0351
0352 test_data_no = 3001;
0353 meg_file_body = sprintf('filtered_%d', test_data_no);
0354 data_file{1} = meg_file_body;
0355 root_dir = proj_root;
0356
0357
0358
0359 plot_parm.mode = 0;
0360 plot_parm.NXmax = 6;
0361 plot_parm.NYmax = 5;
0362
0363
0364 condition = {'voice', 'mik_B', 'mik_G', 'ter_B', 'ter_G' };
0365 status_ch = { '442', '435', '436', '437', '438' };
0366 trig_type = {'voice', 'analog','analog','analog','analog'};
0367 slope = {'','low_to_high','low_to_high','low_to_high','low_to_high'};
0368 status_level = [ 0.02, 0.5 , 0.5 , 0.5 , 0.5 ] ;
0369 Pretrigger_ms = [ 500 , 0, 0, 0, 0];
0370 Posttrigger_ms = [1000 , 2000, 2000, 2000, 2000];
0371
0372 Nfile = length(data_file);
0373 Ncond = length(condition);
0374
0375
0376
0377 for n=1:Nfile
0378
0379 parm.data_file = [data_file{n} '.meg.mat'];
0380
0381 for m=1:Ncond
0382
0383 parm.condition = condition{m};
0384 parm.status_ch = status_ch{m};
0385 parm.trig_type = trig_type{m};
0386 parm.slope = slope{m};
0387
0388 parm.status_level = status_level(m);
0389 parm.Pretrigger_ms = Pretrigger_ms(m);
0390 parm.Posttrigger_ms = Posttrigger_ms(m);
0391
0392
0393 parm.trig_file = [data_file{n} '_' condition{m} '.mat'];
0394
0395
0396 vb_job_trial_onset(root_dir,parm);
0397
0398 if plot_parm.mode > 0
0399
0400 fpng = [root_dir '/' data_file{n} '_' condition{m} ];
0401 plot_parm.png = fpng;
0402
0403 vb_plot_status([root_dir '/' parm.trig_file ], plot_parm);
0404 end
0405 end
0406 end
0407 return;
0408
0409 case 3003
0410
0411 proc_spec = [];
0412 base_data_no = 3001;
0413 filter_type = 'voice';
0414
0415 proc_spec.trig_file = sprintf('filtered_%d_%s.mat', ...
0416 base_data_no, filter_type);
0417
0418
0419 proc_spec.root_dir = proj_root;
0420
0421 proc_spec.new_file = sprintf('%s/test_%d.meg.mat', ...
0422 proc_spec.root_dir, tut_code);
0423
0424
0425 proc_spec.new_bin_dir = sprintf('binary_data_%d', tut_code);
0426 [meg_data, ch_info] = vb_msrmnt_make_trial_data(proc_spec);
0427 fprintf('size of ''meg_data'' is [%d x %d x %d]\n', ...
0428 size(meg_data,1), size(meg_data,2), size(meg_data,3));
0429 vb_util_show_struct(ch_info);
0430 return;
0431
0432 case 3004
0433
0434 test_no = 3003;
0435 file_name = sprintf('test_%d.meg.mat', test_no);
0436 meg_file = [proj_root '/' file_name];
0437
0438 new_meg = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0439
0440
0441
0442
0443 load_spec.ChannelType = 'ALL';
0444 load_spec.Trigger = 1000;
0445 load_spec.Pretrigger = 449;
0446 load_spec.Posttrigger = 2000;
0447 load_spec.TrialNumber = [1;10;13;26;110];
0448 load_spec.ChannelName = {'50';'51';'103';'284';'335';'400';'410';'440'};
0449
0450 [meg_data, ch_info] = vb_load_meg_data(meg_file, load_spec, new_meg);
0451
0452 fprintf('size of ''meg_data'' is [%d x %d x %d]\n', ...
0453 size(meg_data,1), size(meg_data,2), size(meg_data,3));
0454 vb_util_show_struct(ch_info);
0455
0456 case 3005
0457
0458
0459
0460 base_no = 3003;
0461 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, base_no);
0462 tmp_file = sprintf('%s/tmp_%d.meg.mat', proj_root, tut_code);
0463
0464 active_ch = ones(400,1);
0465 active_ch([1:190 200:370 381 383 385]) = 0;
0466
0467 active_tr = ones(120,1);
0468 active_tr([1:70 80:110]) = 0;
0469
0470 vb_msrmnt_update_active_flag(meg_file, active_ch, active_tr, tmp_file);
0471
0472
0473
0474
0475 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0476 [meg_data, ch_info] = vb_load_meg_data(tmp_file, [], new_file);
0477
0478 fprintf('size of ''meg_data'' is [%d x %d x %d]\n', ...
0479 size(meg_data,1), size(meg_data,2), size(meg_data,3));
0480 vb_util_show_struct(ch_info);
0481
0482 case 3006
0483
0484 base_no = 1001;
0485 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, base_no);
0486 trig_code = 3001;
0487 trig_type = 'voice';
0488
0489 trig_file = sprintf('%s/filtered_%d_%s.mat', ...
0490 proj_root, trig_code, trig_type);
0491 triginfo = load(trig_file);
0492
0493 proc_spec.trigger = triginfo.trig;
0494 proc_spec.pretrigger_ms = triginfo.parm.Pretrigger_ms;
0495 proc_spec.posttrigger_ms = triginfo.parm.Posttrigger_ms;
0496 proc_spec.sample_freq = triginfo.parm.fsamp;
0497 proc_spec.new_file = sprintf('test_%d.meg.mat', tut_code);
0498
0499 [meg_data, ch_info] = vb_megfile_make_trial_data(meg_file, proc_spec);
0500
0501 fprintf('size of ''meg_data'' is [%d x %d x %d]\n', ...
0502 size(meg_data,1), size(meg_data,2), size(meg_data,3));
0503 vb_util_show_struct(ch_info);
0504
0505 case 3007
0506
0507 base_no = 1001;
0508 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, base_no);
0509
0510 trig_code = 3001;
0511 trig_type = 'voice';
0512
0513 trig_file = sprintf('%s/filtered_%d_%s.mat', ...
0514 proj_root, trig_code, trig_type);
0515 triginfo = load(trig_file);
0516
0517 proc_spec.trigger = triginfo.trig;
0518 proc_spec.pretrigger_ms = triginfo.parm.Pretrigger_ms;
0519 proc_spec.posttrigger_ms = triginfo.parm.Posttrigger_ms;
0520 proc_spec.sample_freq = triginfo.parm.fsamp;
0521 proc_spec.new_file = sprintf('%s/test_%d.meg.mat', ...
0522 proj_root, tut_code);
0523 proc_spec.new_bin_dir = sprintf('binary_data_%d', tut_code);
0524
0525 [meg_data, ch_info] = vb_megfile_make_trial_data(meg_file, proc_spec);
0526
0527 fprintf('size of ''meg_data'' is [%d x %d x %d]\n', ...
0528 size(meg_data,1), size(meg_data,2), size(meg_data,3));
0529 vb_util_show_struct(ch_info);
0530
0531 case 3008
0532
0533 base_no = 20007;
0534 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, base_no);
0535
0536 info = vb_load_measurement_info(meg_file);
0537
0538 trial_id = [10:20];
0539
0540
0541 field_name = 'number';
0542 [trial, id_list] = vb_info_get_trial_data(info, trial_id, field_name);
0543
0544
0545
0546
0547 fprintf('size of trial is [%d x %d]\n', size(trial,1), size(trial,2));
0548 fprintf('size of id_list is [%d x %d]\n', size(id_list,1), size(id_list,2));
0549
0550 case 3009
0551
0552 base_no = 20007;
0553 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, base_no);
0554 [Measurement, Device] = vb_load_device(meg_file);
0555
0556 case 10001
0557
0558 file_name = 'test_00.act.mat';
0559 act_file = [proj_root '/' file_name];
0560
0561 key1 = 'Uniform';
0562 key2 = 'Tvalue4MI001';
0563 key3 = 'New_Key';
0564 mode = '';
0565 vb_actfile_combine_key(act_file, key1, key2, key3, mode);
0566
0567 case 10002
0568
0569 test_data_no = 10000;
0570 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0571 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0572 vb_megfile_remove_noisysensor(meg_file, new_file);
0573
0574 case 10003
0575
0576 test_data_no = 10000;
0577 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0578 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0579 vb_megfile_remove_noisytrial(meg_file, new_file);
0580
0581 case 10004
0582
0583 test_data_no = 10000;
0584 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0585 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0586 vb_megfile_remove_offset(meg_file, new_file);
0587
0588 case 10005
0589
0590 test_data_no = 10000;
0591 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0592 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0593 ix_trial_remove = (2);
0594 vb_megfile_remove_trial(meg_file, new_file, ix_trial_remove);
0595
0596 case 10006
0597
0598 test_data_no = 10000;
0599 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0600 new_file = sprintf('%s/test_%d.meg.mat', proj_root, tut_code);
0601 vb_megfile_remove_trial_ext(meg_file, new_file);
0602
0603 case 10007
0604
0605 test_data_no = 10000;
0606 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0607 pretrigger = 200;
0608 vb_megfile_write_pretrigger(meg_file, pretrigger);
0609
0610 case 10008
0611
0612 test_data_no = 10000;
0613 meg_file = sprintf('%s/test_%d.meg.mat', proj_root, test_data_no);
0614
0615 bexp = vb_load_meg_data(meg_file);
0616 loadspec.ChannelType = 'EXTRA';
0617 extra = vb_load_meg_data(meg_file, loadspec);
0618 loadspec.ChannelType = 'REFERENCE';
0619 refmg = vb_load_meg_data(meg_file, loadspec);
0620 bexp_ext = [extra; refmg];
0621 ejectedTrials = vb_test_meg_rejection(bexp, bexp_ext);
0622
0623 case 20001
0624
0625 sample_mat = sprintf('%s/test_%d.meg.mat', proj_root, 1001);
0626 hot_var = 'CoordType';
0627
0628 [state, const] = vb_util_check_variable_in_matfile(sample_mat, hot_var);
0629 fprintf('%s in %s is ', hot_var, sample_mat);
0630 if state == const.VALID
0631 fprintf('VALID\n');
0632 elseif state == const.VACANT
0633 fprintf('VACANT\n');
0634 elseif state == const.NONEXISTENT
0635 fprintf('NONEXISTENT\n');
0636 else
0637 fprintf('SOMETHING BAD STATE (%d)\n', state);
0638 end
0639
0640 case 20002
0641
0642 meg_mat = sprintf('%s/test_%d.meg.mat', proj_root, 1121);
0643 load_spec.ChannelType = 'ALL';
0644 tic
0645 [data, ch_info] = vb_load_meg_data(meg_mat, load_spec);
0646 fprintf('data[%d x %d x %d]\n', size(data,1), size(data,2), size(data,3));
0647 vb_util_show_struct(ch_info, 0);
0648 fprintf('%f[sec]\n', toc);
0649
0650 otherwise
0651 error('(%s) unknown test_code : %d', mfilename, test_code);
0652 end
0653
0654
0655
0656
0657
0658
0659 function [tut_code, data_root] = inner_solve_env(tut_code)
0660
0661
0662
0663
0664 data_root = '\\Cbi-data1\cbi-data1\sakot\sample_data\meg';
0665
0666 if isempty(tut_code)
0667 tut_code = 1001;
0668 end
0669 return;
0670
0671
0672
0673
0674
0675