Home > matlabmk > norm_ics.m

norm_ics

PURPOSE ^

norm_ics() - Normalizes to the activations or topographies of independent

SYNOPSIS ^

function EEG=norm_ics(EEG,norm_type,verblevel)

DESCRIPTION ^

 norm_ics() - Normalizes to the activations or topographies of independent
              components to one of various conventions.
              
 Usage:
  >> EEG=norm_ics(EEG,norm_type,verblevel);

 Required Input:
   EEG  - EEGLAB "EEG" struct variable     
             

 Optional Inputs:
   norm_type - [string] desired normalization convention
                 Options are:
                    'topo abs max' - IC topographies are scaled such that 
                      the maximum absolute value of each IC's weights is 1. IC
                      activations are then equal to the maximal magnitude of 
                      each IC's contribution to the scalp data. {default}
                    'topo length' - IC topographies are scaled such that 
                      the length (root sum squared) of each IC's weights is 1.
                      IC sum squared activations then equal the sum
                      squared activations of their scalp projected
                      activity.  This convention is useful for comparing
                      the overall magnitude of the contributions of different
                      ICs to the scalp data.
                    'act rms' - IC activations are scaled such that 
                      the square root of their mean squared activations
                      equals 1.  This is the EEGLAB default.
   verblevel - An integer specifiying the amount of information you want 
               functions to provide about what they are doing during runtime.
                 Options are:
                   0 - quiet, only show errors, warnings, and EEGLAB reports
                   1 - stuff anyone should probably know
                   2 - stuff you should know the first time you start working
                       with a data set {default value if not already globally
                       specified}
                   3 - stuff that might help you debug (show all reports)


 Outputs:
   EEG  - Same as EEG input, but the fields EEG.icaact, EEG.icawinv,
          EEG.icaweights, EEG.icspectra, and EEG.saved have been 
          changed.


 Global Variables:
   VERBLEVEL - level of verbosity (i.e., tells functions how much
               how much to report about what they're doing during
               runtime) set by the optional function argument 'verblevel'
    


 Author: 
 David Groppe
 Kutaslab, 12/2009

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function EEG=norm_ics(EEG,norm_type,verblevel)
0002 % norm_ics() - Normalizes to the activations or topographies of independent
0003 %              components to one of various conventions.
0004 %
0005 % Usage:
0006 %  >> EEG=norm_ics(EEG,norm_type,verblevel);
0007 %
0008 % Required Input:
0009 %   EEG  - EEGLAB "EEG" struct variable
0010 %
0011 %
0012 % Optional Inputs:
0013 %   norm_type - [string] desired normalization convention
0014 %                 Options are:
0015 %                    'topo abs max' - IC topographies are scaled such that
0016 %                      the maximum absolute value of each IC's weights is 1. IC
0017 %                      activations are then equal to the maximal magnitude of
0018 %                      each IC's contribution to the scalp data. {default}
0019 %                    'topo length' - IC topographies are scaled such that
0020 %                      the length (root sum squared) of each IC's weights is 1.
0021 %                      IC sum squared activations then equal the sum
0022 %                      squared activations of their scalp projected
0023 %                      activity.  This convention is useful for comparing
0024 %                      the overall magnitude of the contributions of different
0025 %                      ICs to the scalp data.
0026 %                    'act rms' - IC activations are scaled such that
0027 %                      the square root of their mean squared activations
0028 %                      equals 1.  This is the EEGLAB default.
0029 %   verblevel - An integer specifiying the amount of information you want
0030 %               functions to provide about what they are doing during runtime.
0031 %                 Options are:
0032 %                   0 - quiet, only show errors, warnings, and EEGLAB reports
0033 %                   1 - stuff anyone should probably know
0034 %                   2 - stuff you should know the first time you start working
0035 %                       with a data set {default value if not already globally
0036 %                       specified}
0037 %                   3 - stuff that might help you debug (show all reports)
0038 %
0039 %
0040 % Outputs:
0041 %   EEG  - Same as EEG input, but the fields EEG.icaact, EEG.icawinv,
0042 %          EEG.icaweights, EEG.icspectra, and EEG.saved have been
0043 %          changed.
0044 %
0045 %
0046 % Global Variables:
0047 %   VERBLEVEL - level of verbosity (i.e., tells functions how much
0048 %               how much to report about what they're doing during
0049 %               runtime) set by the optional function argument 'verblevel'
0050 %
0051 %
0052 %
0053 % Author:
0054 % David Groppe
0055 % Kutaslab, 12/2009
0056 %
0057 
0058 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0059 %
0060 
0061 
0062 %%%%%%%%%%%%%%%% FUTURE ADDITIONS %%%%%%%%%%%%%%%%%
0063 %
0064 %-The code could be made more memory efficient (e.g., by requiring EEG to be a
0065 %global variable).
0066 %
0067 
0068 %% Check Inputs
0069 global VERBLEVEL
0070 
0071 if nargin<1,
0072    error('norm_ics.m requires at least one input.'); 
0073 end
0074 if isempty(EEG.icaact) || isempty(EEG.icawinv) || isempty(EEG.icasphere) ...
0075         || isempty(EEG.icaweights)
0076    error(['The EEG variable passed as input is missing at least on the following fields: ' ...
0077        'EEG.icaact, EEG.icawinv, EEG.icasphere, and EEG.icaweights.  Run ICA to fix this.']);
0078 end
0079 
0080 if nargin<2,
0081    norm_type='topo abs max';
0082 else
0083    if ~strcmpi(norm_type,'topo abs max') && ~strcmpi(norm_type,'act rms') ...
0084            && ~strcmpi(norm_type,'topo length')
0085       error('Invalid value for input variable "norm_type".'); 
0086    end
0087 end
0088 
0089 if nargin<3,
0090    if isempty(VERBLEVEL),
0091       VERBLEVEL=2; 
0092    end
0093 else
0094     VERBLEVEL=verblevel;
0095 end
0096 
0097 
0098 %% Normalize ICs
0099 if strcmpi(norm_type,'act rms'),
0100     % Normalize IC activations to unit RMS (EEGLAB default)
0101     VerbReport('Normalizing IC activations to unit RMS, rescaling topographies, and re-computing spectra.',1,VERBLEVEL);
0102     s=size(EEG.icaact);
0103     if length(s)==3,
0104         EEG.icaact=reshape(EEG.icaact,s(1),s(2)*s(3));
0105         rms_act=sqrt(mean((EEG.icaact').^2));
0106         EEG.icaact=EEG.icaact./repmat(rms_act',1,s(2)*s(3));
0107         EEG.icaact=reshape(EEG.icaact,s(1),s(2),s(3));
0108     elseif length(s)==2,
0109         rms_act=sqrt(mean((EEG.icaact').^2));
0110         EEG.icaact=EEG.icaact./repmat(rms_act',1,s(2));
0111     else
0112         error('EEG.data needs to be 2 or 3 dimensional.');
0113     end
0114     %scale ICA weights
0115     EEG.icaweights=EEG.icaweights./repmat(rms_act',1,s(1));
0116     
0117     %recompute mixing matrix
0118     EEG.icawinv=inv(EEG.icaweights*EEG.icasphere);
0119 else
0120     if strcmpi(norm_type,'topo length'),
0121         % Normalize IC topographies to unit length (i.e., root sum squared
0122         % weights=1)
0123         VerbReport('Normalizing IC topographies to unit length and re-computing activations and spectra.',1,VERBLEVEL);
0124         n_ic=size(EEG.icawinv,2);
0125         n_chan=size(EEG.icawinv,1);
0126         rms_winv=sqrt(sum(EEG.icawinv.^2));
0127         EEG.icawinv=EEG.icawinv./repmat(rms_winv,n_chan,1);
0128 
0129     else
0130         % Normalize IC topographies to unit absolute max weight
0131         VerbReport('Normalizing IC topographies to unit max absolute weight and re-computing activations and spectra.',1,VERBLEVEL);
0132         n_ic=size(EEG.icawinv,2);
0133         n_chan=size(EEG.icawinv,1);
0134         mx_winv=max(abs(EEG.icawinv));
0135         EEG.icawinv=EEG.icawinv./repmat(mx_winv,n_chan,1);
0136     end
0137 
0138     %Rescale weights, inv(M)=W*S; therfore inv(M)*inv(S)=W;
0139     EEG.icaweights=inv(EEG.icawinv)*inv(EEG.icasphere);
0140     %Recopmute IC activations
0141     s=size(EEG.data);
0142     if length(s)==3,
0143         EEG.icaact=EEG.icaweights*EEG.icasphere*reshape(EEG.data,s(1),s(2)*s(3));
0144         EEG.icaact=reshape(EEG.icaact,s(1),s(2),s(3));
0145     elseif length(s)==2,
0146         EEG.icaact=EEG.icaweights*EEG.icasphere*EEG.data;
0147     else
0148         error('EEG.data needs to be 2 or 3 dimensional.');
0149     end
0150 end
0151 
0152 EEG.saved='no';
0153 %recompute IC spectra
0154 [EEG.icspectra, EEG.icfreqs] = spectopo( EEG.icaact, EEG.pnts, EEG.srate,'plot','off');
0155 
0156

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