baselineGND() - Baseline the ERPs in a Mass Univariate ERP Toolbox GND struct variable by removing the mean amplitude within a specified time window. Usage: >> GND=baselineGND(GND,bsln_wind,verblevel); Required Inputs: GND - A Mass Univariate ERP Toolbox GND structure variable. To create a GND variable from Kutaslab ERP files (e.g., *.mas files) use avgs2GND.m. To do the same from EEGLAB *.set files use sets2GND.m. See Mass Univariate ERP Toolbox documentation for detailed information about the format of a GND variable. Optional Inputs: bsln_wind - [vector or NaN] Two element vector specifying the beginning and end (in ms) of the baseline time window (e.g., [-100 -4]) or NaN. If NaN, nothing is done and GND variable is returned unchanged. The mean amplitude across all time points within and including those times will be removed from each ERP. {default: all time points before 0} verblevel - An integer specifiying the amount of information you want this function to provide about what it is 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} 3 - stuff that might help you debug (show all reports) Outputs: GND - Mass Univariate ERP Toolbox GND structure variable. This is the same as the input GND variable, but individual ERPs (including cal pulses) have been baselined and grand averages have been re-computed. The field GND.bsln_wind will be updated to the new baseline window as well. Notes: -GND variable is NOT saved to disk after baselining -Function will erase any t-test results stored with GND variable since their results may no longer be accurate Author: David Groppe Kutaslab, 3/2010
0001 % baselineGND() - Baseline the ERPs in a Mass Univariate ERP Toolbox GND 0002 % struct variable by removing the mean amplitude within a 0003 % specified time window. 0004 % 0005 % Usage: 0006 % >> GND=baselineGND(GND,bsln_wind,verblevel); 0007 % 0008 % Required Inputs: 0009 % GND - A Mass Univariate ERP Toolbox GND structure variable. To create a 0010 % GND variable from Kutaslab ERP files (e.g., *.mas files) use 0011 % avgs2GND.m. To do the same from EEGLAB *.set files use sets2GND.m. 0012 % See Mass Univariate ERP Toolbox documentation for detailed 0013 % information about the format of a GND variable. 0014 % 0015 % Optional Inputs: 0016 % bsln_wind - [vector or NaN] Two element vector specifying the beginning and 0017 % end (in ms) of the baseline time window (e.g., [-100 -4]) 0018 % or NaN. If NaN, nothing is done and GND variable is returned 0019 % unchanged. The mean amplitude across all time points within and 0020 % including those times will be removed from each ERP. 0021 % {default: all time points before 0} 0022 % verblevel - An integer specifiying the amount of information you want 0023 % this function to provide about what it is doing during runtime. 0024 % Options are: 0025 % 0 - quiet, only show errors, warnings, and EEGLAB reports 0026 % 1 - stuff anyone should probably know 0027 % 2 - stuff you should know the first time you start working 0028 % with a data set {default value} 0029 % 3 - stuff that might help you debug (show all 0030 % reports) 0031 % 0032 % Outputs: 0033 % GND - Mass Univariate ERP Toolbox GND structure variable. 0034 % This is the same as the input GND variable, but individual 0035 % ERPs (including cal pulses) have been baselined and grand 0036 % averages have been re-computed. The field GND.bsln_wind 0037 % will be updated to the new baseline window as well. 0038 % 0039 % Notes: 0040 % -GND variable is NOT saved to disk after baselining 0041 % -Function will erase any t-test results stored with GND 0042 % variable since their results may no longer be accurate 0043 % 0044 % Author: 0045 % David Groppe 0046 % Kutaslab, 3/2010 0047 0048 % Changes: 0049 % 8/23/2012 - NaN now a possible value for bsln_wind to avoid any 0050 % baselining 0051 0052 function GND=baselineGND(GND,bsln_wind,verblevel) 0053 0054 if nargin<2 0055 bsln_wind=[]; 0056 elseif ~isempty(bsln_wind), 0057 if isnan(bsln_wind) 0058 fprintf('Not baselining data.'); 0059 return; 0060 else 0061 if length(bsln_wind)~=2, 0062 error('Argument bsln_wind needs to be a two element vector.'); 0063 end 0064 if bsln_wind(2)<bsln_wind(1), 0065 error('First value of bsln_wind needs to be less than or equal to second value.'); 0066 end 0067 end 0068 end 0069 0070 global VERBLEVEL; 0071 if nargin<3 0072 if isempty(VERBLEVEL), 0073 VERBLEVEL=2; 0074 end 0075 else 0076 VERBLEVEL=verblevel; 0077 end 0078 0079 %Erase any t-results as they may not be valid anymore 0080 if ~isempty(GND.t_tests), 0081 %but ask first 0082 if VERBLEVEL>1, 0083 resp=[]; 0084 while ~strcmpi(resp,'y') && ~strcmpi(resp,'n') && ~strcmpi(resp,'yes') ... 0085 && ~strcmpi(resp,'no'), 0086 fprintf('These data have t-test results stored with them that may not be accurate after the data have been baselined.\nFor this reason, they will be erased.\n'); 0087 resp=input(sprintf('Continue with baselining (t-test results will be erased)? [y or n] '),'s'); 0088 end 0089 if strcmpi('n',resp) || strcmpi('no',resp), 0090 return 0091 end 0092 fprintf('Erasing t-test results stored with these data.\n'); 0093 end 0094 GND.t_tests=[]; 0095 end 0096 0097 %find baseline window time points 0098 if ~isempty(bsln_wind), 0099 bsln_tpt(1)=find_tpt(bsln_wind(1),GND.time_pts); 0100 bsln_tpt(2)=find_tpt(bsln_wind(2),GND.time_pts); 0101 if VERBLEVEL>1, 0102 fprintf('Baselining data from %d to %d ms (that''s time point %d to %d).\n', ... 0103 GND.time_pts(bsln_tpt(1)),GND.time_pts(bsln_tpt(2)),bsln_tpt(1),bsln_tpt(2)); 0104 end 0105 else 0106 bsln_tpt=[]; 0107 if VERBLEVEL, 0108 ids=find(GND.time_pts<0); 0109 if isempty(ids), 0110 error('Attempted to use default baseline of all time points before 0. However, all time points in these data are after 0.'); 0111 else 0112 bsln_tpt(1)=ids(1); 0113 bsln_tpt(2)=ids(end); 0114 if VERBLEVEL>1, 0115 fprintf('Using default baseline of all time points before 0.\n'); 0116 fprintf('That''s from %d to %d ms (time points %d to %d).\n', ... 0117 GND.time_pts(bsln_tpt(1)),GND.time_pts(bsln_tpt(2)), ... 0118 bsln_tpt(1),bsln_tpt(2)); 0119 end 0120 end 0121 end 0122 end 0123 0124 %baseline individual ERPs 0125 [n_chan, n_tpt, n_bin, n_sub]=size(GND.indiv_erps); 0126 bsln_tpts=bsln_tpt(1):bsln_tpt(2); 0127 for s=1:n_sub, 0128 if VERBLEVEL>1, 0129 fprintf('Baselining data from Participant #%d (%s).\n',s,GND.indiv_subnames{s}); 0130 end 0131 for b=1:n_bin, 0132 GND.indiv_erps(:,:,:,s)=reshape(rmbase(GND.indiv_erps(:,:,:,s), ... 0133 n_tpt,bsln_tpts),n_chan,n_tpt,n_bin); 0134 end 0135 if ~isempty(GND.cals), 0136 cal_size=size(GND.cals.indiv_cals); 0137 GND.cals.indiv_cals=reshape(rmbase(GND.cals.indiv_cals, ... 0138 cal_size(2),bsln_tpts),cal_size(1),cal_size(2),n_sub); 0139 end 0140 end 0141 0142 %Recompute grands, stders, & grand t-scores 0143 for b=1:n_bin, 0144 bin_subs=find(GND.indiv_bin_ct(:,b)); 0145 GND.sub_ct(b)=length(bin_subs); 0146 if GND.sub_ct(b), 0147 GND.grands(:,:,b)=mean(GND.indiv_erps(:,:,b,bin_subs),4); 0148 GND.grands_stder(:,:,b)=std(GND.indiv_erps(:,:,b,bin_subs),0,4)/sqrt(GND.sub_ct(b)); 0149 GND.grands_t(:,:,b)=GND.grands(:,:,b)./GND.grands_stder(:,:,b); 0150 else 0151 watchit(sprintf('No average files contribute to bin %d.',b)); 0152 end 0153 end 0154 %Recompute grand cal pulses 0155 if ~isempty(GND.cals), 0156 GND.cals.grand_cals=mean(GND.cals.indiv_cals,3); 0157 end 0158 0159 GND.bsln_wind=[GND.time_pts(bsln_tpt(1)) GND.time_pts(bsln_tpt(2))]; 0160 0161 GND.saved='no'; 0162 0163