Home > chronux > spectral_analysis > helper > getparams.m

getparams

PURPOSE ^

Helper function to convert structure params to variables used by the

SYNOPSIS ^

function [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params)

DESCRIPTION ^

 Helper function to convert structure params to variables used by the
 various routines - also performs checks to ensure that parameters are
 defined; returns default values if they are not defined.

 Usage: [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params)

 Inputs:
       params: structure with fields tapers, pad, Fs, fpass, err, trialave
           - optional
             tapers : precalculated tapers from dpss or in the one of the following
                       forms:  
                       (1) A numeric vector [TW K] where TW is the
                           time-bandwidth product and K is the number of
                           tapers to be used (less than or equal to
                           2TW-1). 
                       (2) A numeric vector [W T p] where W is the
                           bandwidth, T is the duration of the data and p 
                           is an integer such that 2TW-p tapers are used. In
                           this form there is no default i.e. to specify
                           the bandwidth, you have to specify T and p as
                           well. Note that the units of W and T have to be
                            consistent: if W is in Hz, T must be in seconds
                             and vice versa. Note that these units must also
                            be consistent with the units of params.Fs: W can
                            be in Hz if and only if params.Fs is in Hz.
                           The default is to use form 1 with TW=3 and K=5

            pad            (padding factor for the FFT) - optional (can take values -1,0,1,2...). 
                    -1 corresponds to no padding, 0 corresponds to padding
                    to the next highest power of 2 etc.
                       e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT
                       to 512 points, if pad=1, we pad to 1024 points etc.
                       Defaults to 0.
           Fs   (sampling frequency) - optional. Default 1.
           fpass    (frequency band to be used in the calculation in the form
                                   [fmin fmax])- optional. 
                                   Default all frequencies between 0 and Fs/2
           err  (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
                                   [0 p] or 0 - no error bars) - optional. Default 0.
           trialave (average over trials when 1, don't average when 0) - optional. Default 0
 Outputs: 
 The fields listed above as well as the struct params. The fields are used
 by some routines and the struct is used by others. Though returning both
 involves overhead, it is a safer, simpler thing to do.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params)
0002 % Helper function to convert structure params to variables used by the
0003 % various routines - also performs checks to ensure that parameters are
0004 % defined; returns default values if they are not defined.
0005 %
0006 % Usage: [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params)
0007 %
0008 % Inputs:
0009 %       params: structure with fields tapers, pad, Fs, fpass, err, trialave
0010 %           - optional
0011 %             tapers : precalculated tapers from dpss or in the one of the following
0012 %                       forms:
0013 %                       (1) A numeric vector [TW K] where TW is the
0014 %                           time-bandwidth product and K is the number of
0015 %                           tapers to be used (less than or equal to
0016 %                           2TW-1).
0017 %                       (2) A numeric vector [W T p] where W is the
0018 %                           bandwidth, T is the duration of the data and p
0019 %                           is an integer such that 2TW-p tapers are used. In
0020 %                           this form there is no default i.e. to specify
0021 %                           the bandwidth, you have to specify T and p as
0022 %                           well. Note that the units of W and T have to be
0023 %                            consistent: if W is in Hz, T must be in seconds
0024 %                             and vice versa. Note that these units must also
0025 %                            be consistent with the units of params.Fs: W can
0026 %                            be in Hz if and only if params.Fs is in Hz.
0027 %                           The default is to use form 1 with TW=3 and K=5
0028 %
0029 %            pad            (padding factor for the FFT) - optional (can take values -1,0,1,2...).
0030 %                    -1 corresponds to no padding, 0 corresponds to padding
0031 %                    to the next highest power of 2 etc.
0032 %                       e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT
0033 %                       to 512 points, if pad=1, we pad to 1024 points etc.
0034 %                       Defaults to 0.
0035 %           Fs   (sampling frequency) - optional. Default 1.
0036 %           fpass    (frequency band to be used in the calculation in the form
0037 %                                   [fmin fmax])- optional.
0038 %                                   Default all frequencies between 0 and Fs/2
0039 %           err  (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
0040 %                                   [0 p] or 0 - no error bars) - optional. Default 0.
0041 %           trialave (average over trials when 1, don't average when 0) - optional. Default 0
0042 % Outputs:
0043 % The fields listed above as well as the struct params. The fields are used
0044 % by some routines and the struct is used by others. Though returning both
0045 % involves overhead, it is a safer, simpler thing to do.
0046 
0047 if ~isfield(params,'tapers') || isempty(params.tapers);  %If the tapers don't exist
0048      display('tapers unspecified, defaulting to params.tapers=[3 5]');
0049      params.tapers=[3 5];
0050 end;
0051 if ~isempty(params) && length(params.tapers)==3 
0052     % Compute timebandwidth product
0053     TW = params.tapers(2)*params.tapers(1);
0054     % Compute number of tapers
0055     K  = floor(2*TW - params.tapers(3));
0056     params.tapers = [TW  K];
0057 end
0058 
0059 if ~isfield(params,'pad') || isempty(params.pad);
0060     params.pad=0;
0061 end;
0062 if ~isfield(params,'Fs') || isempty(params.Fs);
0063     params.Fs=1;
0064 end;
0065 if ~isfield(params,'fpass') || isempty(params.fpass);
0066     params.fpass=[0 params.Fs/2];
0067 end;
0068 if ~isfield(params,'err') || isempty(params.err);
0069     params.err=0;
0070 end;
0071 if ~isfield(params,'trialave') || isempty(params.trialave);
0072     params.trialave=0;
0073 end;
0074 
0075 tapers=params.tapers;
0076 pad=params.pad;
0077 Fs=params.Fs;
0078 fpass=params.fpass;
0079 err=params.err;
0080 trialave=params.trialave;

Generated on Fri 28-Sep-2012 12:34:30 by m2html © 2005