Home > matlabmk > scroll_extreme_epochs.m

scroll_extreme_epochs

PURPOSE ^

function scroll_extreme_epochs(ic,plot_hist,fig_id);

SYNOPSIS ^

function scroll_extreme_epochs(ic,plot_hist,fig_id)

DESCRIPTION ^

function scroll_extreme_epochs(ic,plot_hist,fig_id);

 Identifies an independent component's (IC's) most extreme epochs
 and displays them in a scrolling GUI (similar to that produced by eegplot).
 Epochs can be manually rejected or un-rejected via the GUI.

 Note, EEGLAB needs to be running to use this function.

 Required Global Variable:
  EEG = An EEGLAB "EEG" struct  

 Required Input:
  ic  = the number of the IC of interest

 Optional Input:
  plot_hist = [0 | 1] If 1, a histogram of the root mean squared (RMS)
              activation of the selected IC will be created to help you
              determine the RMS level of epochs you wish to view.  If 0,
              no histogram is created. {default: 1}
  fig_id    = [positive integer] The figure index number of the window in 
              which the RMS histogram will be presented.  Useful for
              over-writing previous histograms so that you don't end up
              with a desktop cluttered by histogram windows. If not
              specified a new figure window will be created for the
              histogram. {smallest un-used figure ID}

 Outputs:
  none

 Example:
 >>scroll_extreme_epochs(1);


 Author:
 David Groppe (based on code written by Joe Schilz)
 Kutaslab, 1/2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function scroll_extreme_epochs(ic,plot_hist,fig_id)
0002 %function scroll_extreme_epochs(ic,plot_hist,fig_id);
0003 %
0004 % Identifies an independent component's (IC's) most extreme epochs
0005 % and displays them in a scrolling GUI (similar to that produced by eegplot).
0006 % Epochs can be manually rejected or un-rejected via the GUI.
0007 %
0008 % Note, EEGLAB needs to be running to use this function.
0009 %
0010 % Required Global Variable:
0011 %  EEG = An EEGLAB "EEG" struct
0012 %
0013 % Required Input:
0014 %  ic  = the number of the IC of interest
0015 %
0016 % Optional Input:
0017 %  plot_hist = [0 | 1] If 1, a histogram of the root mean squared (RMS)
0018 %              activation of the selected IC will be created to help you
0019 %              determine the RMS level of epochs you wish to view.  If 0,
0020 %              no histogram is created. {default: 1}
0021 %  fig_id    = [positive integer] The figure index number of the window in
0022 %              which the RMS histogram will be presented.  Useful for
0023 %              over-writing previous histograms so that you don't end up
0024 %              with a desktop cluttered by histogram windows. If not
0025 %              specified a new figure window will be created for the
0026 %              histogram. {smallest un-used figure ID}
0027 %
0028 % Outputs:
0029 %  none
0030 %
0031 % Example:
0032 % >>scroll_extreme_epochs(1);
0033 %
0034 %
0035 % Author:
0036 % David Groppe (based on code written by Joe Schilz)
0037 % Kutaslab, 1/2010
0038 
0039 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0040 %
0041 % 5/11/10 Updated comments
0042 
0043 global EEG;
0044 if isempty(EEG),
0045    error('The data to be visualized need to be in a global variable called EEG.'); 
0046 end
0047 
0048 if nargin<2,
0049    plot_hist=1; 
0050 end
0051 
0052 rms=extreme_epochs(EEG.icaact,ic,plot_hist);
0053 rms_cutoff=input('I will show you epochs with an RMS greater than: ');
0054 
0055 showepochs=find(rms>=rms_cutoff);
0056 if isempty(showepochs),
0057     fprintf('No epochs have an RMS of %f or greater. Exiting.\n',rms_cutoff);
0058 else
0059     fprintf('%d epoch(s) have an RMS of %f or greater.\n',length(showepochs),rms_cutoff);
0060     winlength=min([length(showepochs) 3]);
0061     actplot('initialize','winlength',winlength,'srate',EEG.srate,'limits', ...
0062         [EEG.times(1) EEG.times(end)],'showepochs',showepochs);
0063 end
0064 
0065 
0066 
0067 function [rms, flagged_epochs]=extreme_epochs(acts,ic,plt)
0068 %function [rms, flagged_epochs]=extreme_epochs(acts,ic,plt)
0069 %
0070 % Flags an independent component's (IC's) extreme epochs.
0071 %
0072 %Inputs:
0073 % acts - a 3D matrix of IC activations (i.e., component x time x epoch)
0074 % ic   - [integer] the index number of the IC of interest
0075 % plt  - [1 | 0] plot a histogram of epoch rms values (0="no", any other
0076 %        value="yes")
0077 %
0078 %Outputs:
0079 % rms            - root mean squared activity of each epoch
0080 % flagged_epochs - potential outlier epochs (i.e., rms>75th
0081 %                  percentile+2.5*IQR)
0082 %
0083 %Example:
0084 % [rms, flagged_epochs]=extreme_epochs(EEG.icaact,23,1);
0085 %
0086 %
0087 % Author:
0088 % David Groppe
0089 % Kutaslab, 2009
0090 
0091 s=size(acts);
0092 
0093 for epoch=1:s(3),
0094   rms(epoch)=sqrt(mean(acts(ic,:,epoch).^2));  
0095 end
0096 
0097 if plt,
0098   figure;hist(rms,s(3)/10);
0099   h=xlabel('Root Mean Squared Activation (RMS)');
0100   h=ylabel('Number of Epochs');
0101   h=title(['Raw Frequency Histogram for IC ' num2str(ic)]);
0102 end
0103 
0104 iq=iqr(rms);
0105 %thresh=prctile(rms,75)+1.5*iq;
0106 thresh=prctile(rms,75)+2.5*iq;
0107 flagged_epochs=find(rms>thresh);

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