0001 function [data] = vb_megfile_remove_bias(megfile, procspec)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 if ~exist('megfile', 'var'), megfile = []; end
0030 if ~exist('procspec', 'var'), procspec = []; end
0031 [megfile, procspec] = inner_check_arguments(megfile, procspec);
0032
0033
0034
0035 const_def = vb_define_mode;
0036 func_ = mfilename;
0037
0038 const = vb_define_const;
0039 switch procspec.channel_type
0040 case 1
0041 loadspec.ChannelType = const.DATA_TYPE_MAIN;
0042 data = vb_load_meg_data(megfile, loadspec);
0043 case 2
0044 loadspec.ChannelType = const.DATA_TYPE_EXTRA;
0045 data = vb_load_meg_data(megfile, loadspec);
0046 case 3
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
0056 return;
0057 end
0058
0059 meginfo = vb_megfile_load_meginfo(megfile);
0060
0061
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
0075 return;
0076 end
0077
0078 case const_def.REMOVE_BIAS_LINEAR
0079
0080 end
0081 end
0082 return;
0083
0084
0085
0086
0087
0088
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;
0103 procspec.method = 0;
0104 else
0105 if ~isfield(procspec, 'channel_type')
0106 procspec.channel_type = 1;
0107 end
0108 if ~isfield(procspec, 'method')
0109 procspec.method = 0;
0110 end
0111 end
0112
0113 return;
0114
0115
0116
0117
0118
0119