Home > matlabmk > bin_dif_spec.m

bin_dif_spec

PURPOSE ^

bin_dif_spec() - Computes the difference between the spectra from two bins

SYNOPSIS ^

function specGND=bin_dif_spec(specGND,binA,binB,dif_bindesc)

DESCRIPTION ^

 bin_dif_spec() - Computes the difference between the spectra from two bins 
                  and stores the difference as a new bin in a specGND 
                  variable. The difference will be binA-binB.
             
 Usage:
  >> specGND=bin_dif_spec(specGND,binA,binB,dif_bindesc);

 Required Inputs:
   specGND - A specGND structure variable.  To create a specGND variable 
             from EEGLAB *.set files use sets2specGND.m. 
   binA    - [integer] A bin index. Use the function headinfo.m to see what 
             bins are available.
   binB    - [integer] A bin index. The difference wave will be binA-binB.

 Optional Inputs:
   dif_bindesc - [string] The bin descriptor for the new bin being
                 created. {default: 'Bin #-Bin ##', where # is the value
                 binA and ## is the value of binB}

 Notes:
 -binA and binB should index bins starting at 1 (i.e., Bin 0 is assumed to
 contain cal pulses and is stored apart from bins in specGND variables)

 Example:
 >>specGND=bin_dif_spec(specGND,1,2,'Targets-Standards');

 Author:
 David Groppe
 Kutaslab, 12/2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % bin_dif_spec() - Computes the difference between the spectra from two bins
0002 %                  and stores the difference as a new bin in a specGND
0003 %                  variable. The difference will be binA-binB.
0004 %
0005 % Usage:
0006 %  >> specGND=bin_dif_spec(specGND,binA,binB,dif_bindesc);
0007 %
0008 % Required Inputs:
0009 %   specGND - A specGND structure variable.  To create a specGND variable
0010 %             from EEGLAB *.set files use sets2specGND.m.
0011 %   binA    - [integer] A bin index. Use the function headinfo.m to see what
0012 %             bins are available.
0013 %   binB    - [integer] A bin index. The difference wave will be binA-binB.
0014 %
0015 % Optional Inputs:
0016 %   dif_bindesc - [string] The bin descriptor for the new bin being
0017 %                 created. {default: 'Bin #-Bin ##', where # is the value
0018 %                 binA and ## is the value of binB}
0019 %
0020 % Notes:
0021 % -binA and binB should index bins starting at 1 (i.e., Bin 0 is assumed to
0022 % contain cal pulses and is stored apart from bins in specGND variables)
0023 %
0024 % Example:
0025 % >>specGND=bin_dif_spec(specGND,1,2,'Targets-Standards');
0026 %
0027 % Author:
0028 % David Groppe
0029 % Kutaslab, 12/2010
0030 
0031 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0032 % 3/15/2010-??
0033 
0034 %%%%%%%%%%%%%%%% FUTURE WORK %%%%%%%%%%%%%%%%%
0035 % - add verblevel?
0036 
0037 function specGND=bin_dif_spec(specGND,binA,binB,dif_bindesc)
0038 
0039 if nargin<4,
0040    dif_bindesc=sprintf('Bin %d-Bin %d',binA,binB); 
0041 end
0042 
0043 specGND_copy=specGND; %copy original variable in case something fails
0044 
0045 [n_chans, n_freqs, n_bins, n_subs]=size(specGND.indiv_pow_dB);
0046 neo_bin=n_bins+1;
0047 specGND.dif(neo_bin)=1;
0048 specGND.indiv_pow_dB(:,:,neo_bin,:)=zeros(n_chans,n_freqs,1,n_subs);
0049 use_subs=[];
0050 for sub=1:n_subs,
0051     if sum(sum(isnan(specGND.indiv_pow_dB(:,:,binA,sub))))
0052         fprintf('Sub %d does not have spectra for Bin %. and will be ignored',sub,binA);
0053         specGND.indiv_erps(:,:,neo_bin,sub)=NaN;
0054         specGND.indiv_bin_ct(sub,neo_bin)=0;
0055         specGND.indiv_bin_raw_ct(sub,neo_bin)=0;
0056     else
0057         if sum(sum(isnan(specGND.indiv_pow_dB(:,:,binB,sub))))
0058             fprintf('Sub %d does not have spectra for Bin %. and will be ignored',sub,binB);
0059             specGND.indiv_erps(:,:,neo_bin,sub)=NaN;
0060             specGND.indiv_bin_ct(sub,neo_bin)=0;
0061             specGND.indiv_bin_raw_ct(sub,neo_bin)=0;
0062         else
0063             specGND.indiv_pow_dB(:,:,neo_bin,sub)=specGND.indiv_pow_dB(:,:,binA,sub)- ...
0064                 specGND.indiv_pow_dB(:,:,binB,sub);
0065             specGND.indiv_bin_ct(sub,neo_bin)=-1;
0066             specGND.indiv_bin_raw_ct(sub,neo_bin)=-1;
0067             use_subs=[use_subs sub];
0068         end
0069     end
0070 end
0071 if isempty(use_subs),
0072     specGND=specGND_copy;
0073     error('No subjects have spectra in both Bin %d and Bin %d.  No changes were made to specGND variable.\n',binA,binB);
0074 else
0075     specGND.sub_ct(neo_bin)=length(use_subs);
0076     specGND.grands_pow_dB(:,:,neo_bin)=mean(specGND.indiv_pow_dB(:,:,neo_bin,use_subs),4);
0077     specGND.grands_pow_dB_stder(:,:,neo_bin)=std(specGND.indiv_pow_dB(:,:,neo_bin,use_subs),0,4)/sqrt(specGND.sub_ct(neo_bin));
0078     specGND.grands_pow_dB_t(:,:,neo_bin)=specGND.grands_pow_dB(:,:,neo_bin)./specGND.grands_pow_dB_stder(:,:,neo_bin);
0079     specGND.bindesc{neo_bin}=dif_bindesc;
0080 end
0081 
0082 fprintf('<<New bin successfully created>>\n');
0083 fprintf('Bin %d: %s\n',neo_bin,specGND.bindesc{neo_bin});
0084 hist_cmd=sprintf('specGND=bin_dif_spec(specGND,%d,%d,''%s'');',binA,binB, ...
0085     specGND.bindesc{neo_bin});
0086 specGND.history{length(specGND.history)+1}=hist_cmd;
0087 specGND.saved='no';
0088

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