0001 function reref_bimastoidEEG(mastoid_id,ignore)
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
0030
0031
0032
0033
0034
0035
0036
0037
0038 global EEG
0039
0040 if nargin<2,
0041 ignore=[];
0042 end
0043
0044 if ~strcmpi(EEG.ref,'not specified')
0045 disp('******************************WARNING****************************');
0046 disp('According to EEG.ref, data are already have a specified reference');
0047 disp('Exiting reref_bimastoidEEG.m without modifying EEG.data.');
0048 else
0049 s=size(EEG.data);
0050 nelecs=s(1);
0051 if length(s==3)
0052 EEG.data=reshape(EEG.data,size(EEG.data,1),size(EEG.data,2)*size(EEG.data,3));
0053 elseif length(s~=2)
0054 error('Error: EEG.data should be a 2d or 3d array.');
0055 end
0056
0057 ig=[];
0058 if isempty(ignore)
0059 EEG.ref='bimastoid(mostly)';
0060 else
0061 EEG.ref='bimastoid(partially)';
0062 for dg=1:length(ignore),
0063 fnd=0;
0064 for c=1:nelecs,
0065 if strcmpi(ignore{dg},EEG.chanlocs(c).labels)
0066 ig=[ig c];
0067 fnd=1;
0068 c=nelecs;
0069 end
0070 end
0071 if ~fnd
0072 disp('******************************WARNING****************************');
0073 fprintf('I was supposed to ignore a channel labeled: %s\n', ...
0074 ignore{dg});
0075 disp('However, no such channel is listed.');
0076 end
0077 end
0078 end
0079
0080 ig=unique([ig mastoid_id]);
0081 fprintf('*NOT* re-referencing the following electrode(s):\n');
0082 if isempty(EEG.chanlocs)
0083 disp(ig);
0084 else
0085 for dg=ig,
0086 fprintf('Channel %d: %s\n',dg,EEG.chanlocs(dg).labels);
0087 EEG.chanlocs(dg).ref='left mastoid';
0088 end
0089 end
0090
0091 use=setdiff([1:nelecs],[ig]);
0092 if ~isempty(EEG.chanlocs)
0093 for dg=use,
0094 EEG.chanlocs(dg).ref='bimastoid';
0095 end
0096 end
0097 EEG.data(use,:)=EEG.data(use,:)-repmat(EEG.data(mastoid_id,:),length(use),1)/2;
0098
0099 if length(s)==3,
0100 EEG.data=reshape(EEG.data,s(1),s(2),s(3));
0101 end
0102 end
0103
0104
0105
0106
0107
0108
0109