0001 function avref_trialdata= average_reference(trialdata,mask)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 [npoints NChan] = size(trialdata);
0016
0017 trialdata(:,NChan+1) = zeros(npoints,1);
0018
0019 temptrialdata = zeros(npoints,NChan+1);
0020 temptrialdata =trialdata.* repmat(mask,npoints,1);
0021 divisor=sum(mask);
0022 average=sum(temptrialdata')/divisor;
0023 channel=-average';
0024
0025 avref_trialdata = temptrialdata + repmat(channel,1,NChan+1);
0026 avref_trialdata=avref_trialdata .* repmat(mask,npoints,1);
0027
0028