# 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:

- CrossSpecMat
- CrossSpecMatc Multi-taper cross-spectral matrix - another routine, allows for multiple trials and channels
- coherencyc Multi-taper coherency,cross-spectrum and individual spectra - continuous process
- coherencyc_unequal_length_trials This routine computes the average multi-taper coherence for a given set of unequal length segments. It is
- coherencysegc Multi-taper coherency, cross-spectrum and individual spectra with segmenting - continuous process
- cohgramc Multi-taper time-frequency coherence,cross-spectrum and individual spectra - continuous processes
- cohmatrixc Multi-taper coherency,cross-spectral matrix - continuous process
- fitlinesc fits significant sine waves to data (continuous data).
- ftestc computes the F-statistic for sine wave in locally-white noise (continuous data).
- mtdspecgramc Multi-taper derivative of the time-frequency spectrum - continuous process
- mtdspectrumc Multi-taper frequency derivative of the spectrum - continuous process
- mtpowerandfstatc Multi-taper computation of the power and the fstatistic for a particular frequency - continuous process
- mtspecgramc Multi-taper time-frequency spectrum - continuous process
- mtspecgramtrigc Multi-taper event triggered time-frequency spectrum - continuous process
- mtspectrum_of_spectrumc Multi-taper segmented, second spectrum (spectrum of the log spectrum) for a continuous process
- mtspectrumc Multi-taper spectrum - continuous process
- mtspectrumc_unequal_length_trials This routine computes the multi-taper spectrum for a given set of unequal length segments. It is
- mtspectrumsegc Multi-taper segmented spectrum for a univariate continuous process
- mtspectrumtrigc Multi-taper event triggered time-frequency spectrum - continuous process
- nonst_stat Nonstationarity test - continuous process
- rmlinesc removes significant sine waves from data (continuous data).
- rmlinesmovingwinc fits significant sine waves to data (continuous data) using overlapping windows.
- spsvd Space frequency SVD of input data - continuous processes
- coherencycpb Multi-taper coherency,cross-spectrum and individual spectra - continuous and binned point process data
- coherencycpt Multi-taper coherency,cross-spectrum and individual spectra -continuous data and point process as times
- coherencysegcpb Multi-taper coherency,cross-spectrum and individual spectra with segmenting
- coherencysegcpt Multi-taper coherency,cross-spectrum and individual spectra computed by segmenting
- cohgramcpb Multi-taper time-frequency coherence,cross-spectrum and individual spectra
- cohgramcpt Multi-taper time-frequency coherence,cross-spectrum and individual spectra
- CrossSpecMatpb
- coherencypb Multi-taper coherency,cross-spectrum and individual spectra - binned point process
- coherencysegpb Multi-taper coherency,cross-spectrum and individual spectra computed by segmenting
- cohgrampb Multi-taper time-frequency coherence,cross-spectrum and individual spectra - two binned point processes
- cohmatrixpb Multi-taper coherency matrix - binned point process
- mtdspecgrampb Multi-taper derivatives of time-frequency spectrum - binned point process
- mtdspectrumpb Multi-taper spectral derivative - binned point process
- mtspecgrampb Multi-taper time-frequency spectrum - binned point process
- mtspecgramtrigpb Multi-taper event triggered time-frequency spectrum - binned point process
- mtspectrumpb Multi-taper spectrum - binned point process
- mtspectrumsegpb Multi-taper segmented spectrum for a univariate binned point process
- mtspectrumtrigpb Multi-taper event triggered time-frequency spectrum - binned point process
- CrossSpecMatpt
- coherencypt Multi-taper coherency - point process times
- coherencysegpt Multi-taper coherency computed by segmenting two univariate point processes into chunks
- cohgrampt Multi-taper time-frequency coherence - two point processes given as times
- cohmatrixpt Multi-taper coherency matrix - point process times
- mtdspecgrampt Multi-taper derivative time-frequency spectrum - point process times
- mtdspectrumpt Multi-taper spectral derivative - point process times
- mtspecgrampt Multi-taper time-frequency spectrum - point process times
- mtspecgramtrigpt Multi-taper event triggered time-frequency spectrum - point process times
- mtspectrumpt Multi-taper spectrum - point process times
- mtspectrumsegpt Multi-taper segmented spectrum for a univariate binned point process
- mtspectrumtrigpt Multi-taper time-frequency spectrum - point process times
- mtspecgramc_fast Multi-taper time-frequency spectrum - continuous process
- mtspecgramc_slow Multi-taper time-frequency spectrum - continuous process

## 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;