0001 function [ref_trialdata,mask] = new_reference(trialdata,mask,reference);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 if ~(nargin == 2|nargin == 3)
0017 error('incorrect number of input arguments')
0018 end
0019
0020 if nargin == 2
0021 reference = 'average';
0022 end;
0023
0024 if size(trialdata,2)+1 ~= size(mask,2)
0025 error('mismatch between trialdata and mask');
0026 end;
0027
0028 if strcmp(reference,'average')
0029 ref_trialdata = average_reference(trialdata,mask);
0030 end;
0031
0032 if strcmp(reference,'vertex')
0033 ref_trialdata = zeros(size(trialdata,1),size(trialdata,2)+1);
0034 ref_trialdata(1:size(trialdata,1),1:size(trialdata,2)) = trialdata;
0035 end
0036 if strcmp(reference,'avgmast')
0037 channel_list = [57 101];
0038 elseif strcmp(reference,'perimeter')
0039 channel_list = [14 8 1 121 115 101 96 90 83 75 70 64 57 45 39 33 26 22];
0040 end;
0041
0042 if ~(strcmp(reference,'average')|strcmp(reference,'vertex'))
0043 if size(channel_list,2) > 1
0044 cmask = zeros(1,size(mask,2));
0045 cmask(channel_list) = ones(1,size(channel_list,2));
0046 cmask = mask.*cmask;
0047 chan_list = find(cmask);
0048 ref_trialdata = zeros(size(trialdata,1),size(mask,2));
0049 ref_trialdata(:,1:size(trialdata,2)) = trialdata;
0050 if size(chan_list,2) > 1
0051 ref_sig = (mean(trialdata(:,chan_list)'))';
0052 ref_trialdata = ref_trialdata - ref_sig*ones(1,size(ref_trialdata,2));
0053 else
0054 mask == zeros(1,size(cmask,2));
0055 end;
0056 else
0057 cmask = zeros(1,size(mask,2));
0058 cmask(channel_list) = ones(1,size(channel_list,2));
0059 cmask = mask.*cmask;
0060 chan_list = find(cmask);
0061 ref_trialdata = zeros(size(trialdata,1),size(mask,2));
0062 if chan_list == []
0063 mask = zeros(1,size(mask,2))
0064 else
0065 ref_sig = trialdata(:,chan_list);
0066 ref_trialdata = ref_trialdata - ref_sig*ones(1,size(ref_trialdata,2));
0067 end;
0068 end
0069 end;
0070
0071
0072
0073
0074
0075
0076