Home > vbmeg > functions > device > meg > vb_megfile_remove_bias.m

vb_megfile_remove_bias

PURPOSE ^

remove bias from MEG data

SYNOPSIS ^

function [data] = vb_megfile_remove_bias(megfile, procspec)

DESCRIPTION ^

 remove bias from MEG data
 [usage]
   [data] = vb_megfile_remove_bias(megfile)
 [input]
   megfile : <required> <<file>> MEG-MAT file
   procspec : <optional> <<struct>> specification of removing
            :  <<fields>>
            :   .channel_type : channel type
            :     :  [1]) MEG
            :     :   2 ) EXTRA
            :     :   3 ) REFFERENCE
            :   .method   : how to remove (defined in vb_define_mode)
            :     :  [0]) REMOVE_BIAS_OFF
            :     :   1 ) REMOVE_BIAS_PRETRIGGER
            :     :   2 ) REMOVE_BIAS_LINEAR
 [output]
      data : processed data
 [note]
   if specified REMOVE_BIAS_OFF, only returns loaded data
 [history]
   2007-07-13 (Sako) separated from Yoshioka-san's program
   2008-06-06 (Sako) modified using new vb_load_meg_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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [data] = vb_megfile_remove_bias(megfile, procspec)
0002 % remove bias from MEG data
0003 % [usage]
0004 %   [data] = vb_megfile_remove_bias(megfile)
0005 % [input]
0006 %   megfile : <required> <<file>> MEG-MAT file
0007 %   procspec : <optional> <<struct>> specification of removing
0008 %            :  <<fields>>
0009 %            :   .channel_type : channel type
0010 %            :     :  [1]) MEG
0011 %            :     :   2 ) EXTRA
0012 %            :     :   3 ) REFFERENCE
0013 %            :   .method   : how to remove (defined in vb_define_mode)
0014 %            :     :  [0]) REMOVE_BIAS_OFF
0015 %            :     :   1 ) REMOVE_BIAS_PRETRIGGER
0016 %            :     :   2 ) REMOVE_BIAS_LINEAR
0017 % [output]
0018 %      data : processed data
0019 % [note]
0020 %   if specified REMOVE_BIAS_OFF, only returns loaded data
0021 % [history]
0022 %   2007-07-13 (Sako) separated from Yoshioka-san's program
0023 %   2008-06-06 (Sako) modified using new vb_load_meg_data
0024 %
0025 % Copyright (C) 2011, ATR All Rights Reserved.
0026 % License : New BSD License(see VBMEG_LICENSE.txt)
0027 
0028 %  --- CHECK ARGUMENTS --- %
0029 if ~exist('megfile', 'var'), megfile = []; end
0030 if ~exist('procspec', 'var'), procspec = []; end
0031 [megfile, procspec] = inner_check_arguments(megfile, procspec);
0032 
0033 % --- MAIN PROCEDURE --------------------------------------------------------- %
0034 %
0035 const_def = vb_define_mode;
0036 func_ = mfilename;
0037 
0038 const = vb_define_const;
0039 switch procspec.channel_type
0040   case  1  % MEG
0041     loadspec.ChannelType = const.DATA_TYPE_MAIN;
0042     data = vb_load_meg_data(megfile, loadspec);
0043   case  2  % EXTRA
0044     loadspec.ChannelType = const.DATA_TYPE_EXTRA;
0045     data = vb_load_meg_data(megfile, loadspec);
0046   case  3  % REFFERENCE
0047     loadspec.ChannelType = const.DATA_TYPE_REFERENCE;
0048     data = vb_load_meg_data(megfile, loadspec);
0049   otherwise
0050     error('(%s)unexpected channel_type in procspec : %d', ...
0051       func_, procspec.channel_type);
0052 end
0053 
0054 if procspec.method == const_def.REMOVE_BIAS_OFF
0055   % do nothing
0056   return;
0057 end
0058 
0059 meginfo = vb_megfile_load_meginfo(megfile);
0060 
0061 % every trial - data [Nchannel x Nsample x Ntrial]
0062 for i=1:size(data,3)
0063   switch procspec.method
0064     
0065     case const_def.REMOVE_BIAS_PRETRIGGER
0066       pre = vb_meginfo_get_pre_trigger(meginfo);
0067 
0068       if ~isempty(pre) && pre > 0, 
0069         tmp = mean(data(:, 1:pre ,i )')';
0070         data(:, :, i) = data(:, :, i) - repmat(tmp, [1 size(data, 2)]);
0071       else
0072         warning('(%s)there is not pretrigger in MEG-MAT file: %s\n', ...
0073           func_, megfile);
0074         % need to confirmation whether it can be returned here or not
0075         return;
0076       end
0077       
0078     case const_def.REMOVE_BIAS_LINEAR
0079       % not be implemented yet
0080   end
0081 end
0082 return;
0083 %
0084 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0085 
0086 % --- INNER FUNCTIONS -------------------------------------------------------- %
0087 %
0088 % --- inner_check_arguments()
0089 %
0090 function [megfile, procspec] = inner_check_arguments(megfile, procspec)
0091 func_ = mfilename;
0092 
0093 if isempty(megfile)
0094   error('(%s)megfile is a required parameter', func_);
0095 end
0096 
0097 if exist(megfile, 'file') ~= 2
0098   error('(%s)cannot find MEG-MAT file : %s', func_, megfile);
0099 end
0100 
0101 if isempty(procspec)
0102   procspec.channel_type = 1;  % MEG
0103   procspec.method = 0;        % OFF
0104 else
0105   if  ~isfield(procspec, 'channel_type')
0106     procspec.channel_type = 1;  % MEG
0107   end
0108   if  ~isfield(procspec, 'method')
0109     procspec.method = 0;        % OFF
0110   end
0111 end
0112 
0113 return;
0114 %
0115 % --- end of inner_check_arguments()
0116 %
0117 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0118 
0119 %%% END OF FILE %%%

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