Home > vbmeg > demo > test_scripts > vb_test_meg_rejection.m

vb_test_meg_rejection

PURPOSE ^

Checks each MEG channel to see if it goes over threshold during any of the trials

SYNOPSIS ^

function rejectedTrials = vb_test_meg_rejection(bexp,bexp_ext,threshold)

DESCRIPTION ^

 Checks each MEG channel to see if it goes over threshold during any of the trials
 Input: 
   bexp is a TxSxC matrix, where T are the trials, S is time, and C are the MEG channels
   bexp_ext is a TxSxC matrix, where T are the trials, S is time, and C are the external trigger channels
   threshold is the threshold in tesla (T) (default is 3000*1e-15 T = 3000 fT)
 Output:
   rejectedTrials is a vector containing the trial numbers of trials in
       which an MEG channel exceeded threshold (the channel that exceeded
       threshold is displayed to the screen while the program is running).

   Example:
      rejectedTrials = meg_rejection(bexp,bexp_ext,3000*1e-15);
   returns a list of rejected trials for threshold at 3000 fT.

 [note]
   sample script
 [history]
   ****-**-** (WHOM) initial version
   2010-01-27 (Sako) registered with CVS

 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 rejectedTrials = vb_test_meg_rejection(bexp,bexp_ext,threshold)
0002 % Checks each MEG channel to see if it goes over threshold during any of the trials
0003 % Input:
0004 %   bexp is a TxSxC matrix, where T are the trials, S is time, and C are the MEG channels
0005 %   bexp_ext is a TxSxC matrix, where T are the trials, S is time, and C are the external trigger channels
0006 %   threshold is the threshold in tesla (T) (default is 3000*1e-15 T = 3000 fT)
0007 % Output:
0008 %   rejectedTrials is a vector containing the trial numbers of trials in
0009 %       which an MEG channel exceeded threshold (the channel that exceeded
0010 %       threshold is displayed to the screen while the program is running).
0011 %
0012 %   Example:
0013 %      rejectedTrials = meg_rejection(bexp,bexp_ext,3000*1e-15);
0014 %   returns a list of rejected trials for threshold at 3000 fT.
0015 %
0016 % [note]
0017 %   sample script
0018 % [history]
0019 %   ****-**-** (WHOM) initial version
0020 %   2010-01-27 (Sako) registered with CVS
0021 %
0022 % Copyright (C) 2011, ATR All Rights Reserved.
0023 % License : New BSD License(see VBMEG_LICENSE.txt)
0024 
0025 if nargin<3
0026     threshold = 3000*1e-15; % default threshold is 3000 fT
0027 end
0028 
0029 endTriggerCh = 31;      % end of trial is marked by trigger on channel 249, which is channel 31 in bexp_ext
0030 waitForResponseCh = 30; % waiting for response trigger on channel 248
0031 LbuttonCh = 22;         % subject left button presses on channel 240
0032 RbuttonCh = 23;         % subject right button presses on channel 241
0033 
0034 triggerThresh = 1; % threshold for testing whether external trigger is on or off
0035 
0036 rejectedTrials = [];
0037 
0038 for trial = 1:size(bexp,3) % cycle through each trial
0039     
0040     trialEndTime = find(bexp_ext(endTriggerCh,:,trial)>triggerThresh,1,'first');  % find the time of the end of the trial
0041     
0042     if isempty(trialEndTime) % make sure the end of the trial was found
0043                 
0044         waitForResponseTime = find(bexp_ext(waitForResponseCh,:,trial)>triggerThresh,1,'first'); % find when subject is cued to respond
0045         
0046         if isempty(waitForResponseTime)
0047             disp(['Warning: Could not find the end of trial trigger for trial ', num2str(trial), '!']);
0048             trialEndTime=size(bexp,2); % could not find the end of trial trigger, so set the trial end time to the maximal possible value
0049         else
0050             % find the first button press after the waitForResponse trigger
0051             buttonPress = find(min(bexp_ext([LbuttonCh, RbuttonCh],waitForResponseTime:size(bexp,2),trial))<triggerThresh,1,'first');
0052             if isempty(buttonPress)
0053                 buttonPress=1;
0054             end
0055             trialEndTime= waitForResponseTime+buttonPress-1;
0056         end        
0057     end
0058     
0059     for channel = 1:size(bexp,1)  % cycle through each meg channel
0060         overbounds = find(abs(bexp(channel,1:trialEndTime,trial))>threshold,1,'first'); % find the first occurence of the absolute value of the channel exceeding threshold
0061         if ~isempty(overbounds)
0062             disp(['Channel ', num2str(channel), ' during Trial ', num2str(trial), ' is noisy']);
0063             rejectedTrials=union(rejectedTrials,trial);  % channel went out of bounds, so reject this trial.
0064         end        
0065     end
0066 end

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