Home > vbmeg > demo > tutorial > EEG > vb_eeg_tutorial.m

vb_eeg_tutorial

PURPOSE ^

tutorial to try to use VBMEG by EEG data

SYNOPSIS ^

function vb_eeg_tutorial(tut_code)

DESCRIPTION ^

 tutorial to try to use VBMEG by EEG data
 [usage]
   vb_eeg_tutorial(tut_code)
 [input]
   tut_code : <required> <<integer>> tutorial code
            :  1001) import .bdf file and make .eeg.mat file
            :  1002) read trigger information and make trigger file
            :  1003) filter data and make filtered data file
            :  1004) make epoch file (3 dimensions data file)
            :  1005) calculate leadfield
            :  1006) calculate vb
            :  1007) calculate current
            :  1008) plot current
 [output]
   none
 [note]
   
 [history]
   2010-02-02 (Sako) draft version

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_eeg_tutorial(tut_code)
0002 % tutorial to try to use VBMEG by EEG data
0003 % [usage]
0004 %   vb_eeg_tutorial(tut_code)
0005 % [input]
0006 %   tut_code : <required> <<integer>> tutorial code
0007 %            :  1001) import .bdf file and make .eeg.mat file
0008 %            :  1002) read trigger information and make trigger file
0009 %            :  1003) filter data and make filtered data file
0010 %            :  1004) make epoch file (3 dimensions data file)
0011 %            :  1005) calculate leadfield
0012 %            :  1006) calculate vb
0013 %            :  1007) calculate current
0014 %            :  1008) plot current
0015 % [output]
0016 %   none
0017 % [note]
0018 %
0019 % [history]
0020 %   2010-02-02 (Sako) draft version
0021 %
0022 % Copyright (C) 2011, ATR All Rights Reserved.
0023 % License : New BSD License(see VBMEG_LICENSE.txt)
0024 
0025 % --- CHECK ENVIRONMENT
0026 if ~exist('tut_code', 'var'), tut_code = []; end
0027 [tut_code, data_root] = inner_solve_env(tut_code);
0028 
0029 % if isempty(tut_code)
0030 %   test_code = 1001;
0031 % end
0032 
0033 proj_root = './tutorial/EEG/vbmeg_data';
0034 
0035 % root directry
0036 FILE_BASE = 'sample_sako';
0037 EEG_EXT   = '.eeg.mat';
0038 
0039 switch tut_code
0040   case 1001
0041     % --- vb_job_meg
0042     meg_parm.Measurement = 'EEG';
0043     meg_parm.device = 'BIOSEMI';
0044     
0045     eeg_data_root = data_root;
0046     pos_data_root = data_root;
0047     meg_parm.measurement_file = [eeg_data_root '/' FILE_BASE '.bdf'];
0048     meg_parm.pos_file = [pos_data_root '/Takao_Sako.pos.mat'];
0049 
0050     meg_parm.output_file = [FILE_BASE EEG_EXT];
0051     meg_parm.bin_data_dir = ''; % directory name of binary data
0052 
0053     vb_job_meg(proj_root, meg_parm);
0054 
0055   case 1002
0056     % --- read trigger information from 'Status' channel and make trigger file
0057     
0058     % --- data file names (base name without extension)
0059     data_file = {FILE_BASE};
0060     % data file extension
0061     % onset file sufix
0062     onset_name = 'bit';
0063 
0064     % --- Set condition list
0065     parm.trig_type   = 'bit';
0066     parm.slope       = 'low_to_high';
0067     parm.condition   = { 'bit'};
0068     parm.status_level = 2^4; % check 4-th bit
0069 
0070     parm.status_ch   = {'Status'};
0071     parm.status_mask = '11111111';
0072       % (high->low) bit mask pattern to get status
0073       % = '0000000011111111' : get lower 8 bit
0074     parm.status_offset = - 6751232;
0075       % biosemi offset value
0076 
0077     parm.Pretrigger_ms  = 1000; % before trigger [msec]
0078     parm.Posttrigger_ms = 9000; % after trigger [msec]
0079 
0080     Nfile = length(data_file);
0081 
0082     % --- Trial onset extraction start
0083     for n=1:Nfile
0084         % MEG mat file
0085         parm.data_file  = [data_file{n} EEG_EXT];
0086     
0087         % Trial onset  file
0088         parm.trig_file  = [data_file{n} '_' onset_name '.trig.mat'];
0089     
0090         % Get time index for each trial by checking status channel
0091         vb_job_trial_onset(proj_root, parm);
0092     end
0093     return;
0094     
0095   case 1003
0096     % --- filter data
0097 
0098     % --- EEG file names (base name without extension)
0099       data_file = {FILE_BASE};
0100 
0101     % --- preprocess parameter
0102     parm.filt_suffix = '_filt'; % suffix of filtered data
0103     parm.bias_flg = 10; % Bias correction (=0/1/2: OFF/Bias/Linear)
0104     parm.highpass = 1; % Highpass filter cutoff frequency [Hz]
0105     parm.lowpass  = 100; % Lowpass  filter cutoff frequency [Hz]
0106     parm.fsamp    = [];% down sampling frequency [Hz]
0107 
0108     parm.highpass_online = 5; % order of online highpass filter
0109     parm.lowpass_online  = 5; % order of online lowpass filter
0110 
0111     % Common reference should be done after bad channel removal
0112     parm.common_flg = [];% Common reference flag (=1/0 : ON/OFF)
0113 
0114     vb_fprint_filter_parm(parm);
0115 
0116     proc_spec.parm = parm;
0117 
0118     Nfile = length(data_file);
0119 
0120     for n=1:Nfile
0121         tic
0122            eeg_file = [proj_root '/' data_file{n} EEG_EXT];
0123            proc_spec.new_eeg = [data_file{n} parm.filt_suffix EEG_EXT];
0124         
0125            result = vb_eegfile_filter_ch_data(eeg_file, proc_spec);
0126 
0127         vb_ptime(toc)
0128     end
0129     return;
0130     
0131   case 1004
0132     % --- make epoch data (3 dimensions)
0133 
0134     % --- EEG file names (base name without extension)
0135       data_base = {FILE_BASE};
0136     
0137       % --- Set of onset condition list
0138       onset = {'_bit'};
0139 
0140     % Filtered data file suffix (if it is empty. original data is used)
0141     filt_suffix = '_filt';
0142     % Trial data file suffix
0143     epoch_suffix = '_epoch';
0144 
0145     % --- Length of trials
0146     parm.Pretrigger_ms  = 0; % [msec]
0147     parm.Posttrigger_ms = 10000; % [msec]
0148 
0149     proc_spec.proc_parm = parm;
0150     proc_spec.root_dir  = proj_root;
0151 
0152     Nfile = length(data_base);
0153     Ncond = length(onset);
0154 
0155     for n=1:Nfile
0156         for m=1:Ncond
0157             % Trial onset file
0158             proc_spec.trig_file = [data_base{n} onset{m} '.trig.mat'];
0159         
0160             % When filtered data file is used
0161             if ~isempty(filt_suffix)
0162                 data_file = [data_base{n} filt_suffix EEG_EXT];
0163                 proc_spec.proc_parm.data_file = data_file;
0164         end
0165         
0166             % Trial file
0167             proc_spec.new_file  = ...
0168                 [proj_root '/' data_base{n} onset{m} epoch_suffix EEG_EXT];
0169     
0170             tic
0171             [data, ch_info] = vb_msrmnt_make_trial_data(proc_spec);
0172             vb_ptime(toc)
0173       end
0174     end
0175     return;
0176 
0177   case 1005
0178     % --- vb_job_leadfield
0179     eeg_file  = [FILE_BASE '_bit_epoch.eeg.mat'];
0180     basis_parm = make_basis_parm(0, eeg_file);
0181 
0182     vb_job_leadfield(proj_root, basis_parm);
0183 
0184   case 1006
0185     % --- vb_job_vb
0186     bayes_parm = make_bayes_parm(proj_root);
0187 
0188     vb_job_vb(proj_root, bayes_parm);
0189 
0190   case 1007
0191     % --- vb_job_current
0192     curr_parm = make_curr_parm;
0193     vb_job_current(proj_root, curr_parm);
0194     
0195   case 1008
0196     % --- plot current
0197     data_dir = proj_root;
0198     currfile = [data_dir '/' FILE_BASE '.curr.mat'];
0199     brainfile = [data_dir '/SKbrain.brain.mat'];
0200     job_plot_currentmap(currfile, brainfile);
0201 
0202   case 2001
0203     % --- vb_load_meg_data - load data
0204     eeg_file  = [proj_root '/' FILE_BASE '_bit_epoch.eeg.mat'];
0205     [eeg_data, ch_info] = vb_load_meg_data(eeg_file);
0206     fprintf('sizeof(eeg_data) = [%d x %d x %d]\n', ...
0207       size(eeg_data,1), size(eeg_data,2), size(eeg_data,3));
0208     n_ch = size(ch_info.Name);
0209     for i_ch = 1:n_ch
0210       fprintf('[%02d] %s\n', i_ch, ch_info.Name{i_ch});
0211     end
0212 end
0213 
0214 
0215 % --- INNER FUNCTIONS -------------------------------------------------------- %
0216 %
0217 % --- inner_solve_env()
0218 %
0219 function [tut_code, data_root] = inner_solve_env(tut_code)
0220 % --- Linux
0221 % data_root = '/home/cbi-data1/sakot/sample_data/eeg';
0222 
0223 % --- Windows
0224 data_root = '\\Cbi-data1\cbi-data1\sakot\sample_data\eeg';
0225   
0226 if isempty(tut_code)
0227   tut_code = 1001;
0228 end
0229 return;
0230 %
0231 % --- end of inner_solve_env()

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005