Home > matlabmk > reref_bimastoidEEG.m

reref_bimastoidEEG

PURPOSE ^

crw2set() - Re-references data to algebraic mean of mastoids

SYNOPSIS ^

function reref_bimastoidEEG(mastoid_id,ignore)

DESCRIPTION ^

 crw2set() - Re-references data to algebraic mean of mastoids
  

 Usage:
  >> reref_bimastoidEEG(mastoid_id,ignore);


Required Global Variable:
 EEG      - An EEGLAB EEG struct containing the data set to be re-referenced.


Inputs:
 mastoid_id   - [integer] If data were recorded with a left mastoid reference,
                the index number of the the right mastoid channel.  If data 
                were recorded with a right mastoid reference, the index
                number of the left mastoid channel.  The first channel
                starts with an index number of 1 (i.e., NOT 0).
 ignore       - Identifies channels that should not be rereferenced
                (e.g. an outer canthus montage). If no channels
                are to be ignored, use the empty set [] or leave blank.


EXAMPLE: 
  >> global EEG
  >> reref_bimastoid(29,[])
  >> %A2 is electrode #29, no channels are to be ignored


Notes:
-The right or left mastoid channel values are not re-referenced.


 Author:
 David Groppe
 Kutaslab, 8/2009

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function reref_bimastoidEEG(mastoid_id,ignore)
0002 % crw2set() - Re-references data to algebraic mean of mastoids
0003 %
0004 %
0005 % Usage:
0006 %  >> reref_bimastoidEEG(mastoid_id,ignore);
0007 %
0008 %
0009 %Required Global Variable:
0010 % EEG      - An EEGLAB EEG struct containing the data set to be re-referenced.
0011 %
0012 %
0013 %Inputs:
0014 % mastoid_id   - [integer] If data were recorded with a left mastoid reference,
0015 %                the index number of the the right mastoid channel.  If data
0016 %                were recorded with a right mastoid reference, the index
0017 %                number of the left mastoid channel.  The first channel
0018 %                starts with an index number of 1 (i.e., NOT 0).
0019 % ignore       - Identifies channels that should not be rereferenced
0020 %                (e.g. an outer canthus montage). If no channels
0021 %                are to be ignored, use the empty set [] or leave blank.
0022 %
0023 %
0024 %EXAMPLE:
0025 %  >> global EEG
0026 %  >> reref_bimastoid(29,[])
0027 %  >> %A2 is electrode #29, no channels are to be ignored
0028 %
0029 %
0030 %Notes:
0031 %-The right or left mastoid channel values are not re-referenced.
0032 %
0033 %
0034 % Author:
0035 % David Groppe
0036 % Kutaslab, 8/2009
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; %break out of loop
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

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005