Home > vbmeg > demo > tutorial_for_vbmeg2 > advanced > make_trial_meg.m

make_trial_meg

PURPOSE ^

Make trial data

SYNOPSIS ^

function make_trial_meg(p)

DESCRIPTION ^

 Make trial data

 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:

SOURCE CODE ^

0001 function make_trial_meg(p)
0002 % Make trial data
0003 %
0004 % Copyright (C) 2011, ATR All Rights Reserved.
0005 % License : New BSD License(see VBMEG_LICENSE.txt)
0006 
0007 disp(mfilename);
0008 
0009 % Set parameters
0010 parm.Pretrigger_ms  = p.Pretrigger_ms; % before trigger [msec]
0011 parm.Posttrigger_ms = p.Posttrigger_ms; % after trigger [msec]
0012 parm.condition={'stim'};
0013 parm.status_ch={'432'};
0014 parm.trig_type='analog';
0015 parm.slope='low_to_high';
0016 parm.status_level=0.5;
0017 
0018 plot_parm.mode  = 1; % = 1: plot all trial
0019 plot_parm.NXmax = 25; % # of trial in X-axis
0020 plot_parm.NYmax = 5; % # of subplot in Y-axis
0021 
0022 Nfile = length(p.file_list);
0023 
0024 % Extract stimulus onsets
0025 for file = 1:Nfile
0026     % Set input file
0027     parm.data_file = fullfile(p.meg_dirname, p.filter_dirname, [p.file_list{file} '.meg.mat']);
0028     
0029     % Set output file
0030     parm.trig_file = fullfile(p.meg_dirname, p.filter_dirname, [p.file_list{file} '.trig.mat']);
0031     
0032     % Get time index for each trial by checking status channel
0033     vb_job_trial_onset(p.proj_root,parm);
0034     vb_plot_status(fullfile(p.proj_root, parm.trig_file), plot_parm);
0035 end
0036 
0037 % Remove first trigger for visual task
0038 % because it does not represent stimulus onset
0039 for run = 1:2
0040     % Load trigger data
0041     trig_file = fullfile(p.proj_root, p.meg_dirname, p.filter_dirname, ['v' num2str(run) '.trig.mat']);
0042     load(trig_file, 'cond_id', 'ix_trial', 'trig')
0043     
0044     % Remove first trigger
0045     cond_id = cond_id(2:end);
0046     ix_trial = ix_trial(:,2:end);
0047     trig = trig(2:end);
0048     
0049     % Save modified trigger
0050     vb_save(trig_file, 'cond_id', 'ix_trial', 'trig');
0051 end
0052 
0053 % Check consistency of inter-stimulu intervals (ITIs) between EEG and MEG data
0054 data_file = fullfile(p.proj_root, p.meg_dirname, p.filter_dirname, 'a1.meg.mat');
0055 meg_info = vb_load_measurement_info(data_file);
0056 samplingrate = meg_info.SampleFreq;
0057 for file = 1:Nfile
0058     % Load trigger data of MEG
0059     trig_file = fullfile(p.proj_root, p.meg_dirname, p.filter_dirname, [p.file_list{file} '.trig.mat']);
0060     load(trig_file, 'trig')
0061     iti_meg = diff(trig);
0062     
0063     % Load trigger data of EEG
0064     trig_file = fullfile(p.proj_root, p.eeg_dirname, p.filter_dirname, [p.file_list{file} '.trig.mat']);
0065     load(trig_file,'trig')
0066     iti_eeg = diff(trig);
0067     
0068     % Calculate difference of ITI
0069     dif = abs(iti_meg-iti_eeg);
0070     disp(['Max difference of ITI is ' num2str(max(dif)/samplingrate*1000) ' ms for ' p.file_list{file}])
0071 end
0072 
0073 % Make trial data
0074 for file = 1:Nfile
0075     % Set input file
0076     filtered_file = fullfile(p.proj_root, p.meg_dirname, p.filter_dirname, [p.file_list{file} '.meg.mat']);
0077     proc_spec.trig_file = fullfile(p.proj_root, p.meg_dirname, p.filter_dirname, [p.file_list{file} '.trig.mat']);
0078     
0079     % Set output file
0080     trial_file = fullfile(p.proj_root, p.meg_dirname, p.trial_dirname, [p.file_list{file} '.meg.mat']);
0081     
0082     % Make trial data
0083     vb_msrmnt_make_trial_data(filtered_file, proc_spec, trial_file);
0084 end
0085 
0086 
0087 
0088

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