Home > m > noisegenerator > ltpda_noisegen.m

ltpda_noisegen

PURPOSE ^

LTPDA_NOISEGEN uses pzm2ab and franklin to generate a time-series

SYNOPSIS ^

function varargout = ltpda_noisegen(varargin)

DESCRIPTION ^

 LTPDA_NOISEGEN uses pzm2ab and franklin to generate a time-series
 from a given pzmodel
 
 calls: 
 >> [b, pl1, pl2] = ltpda_noisegen(pl) 
 >> [b, pl1] = ltpda_noisegen(pl)
 >>  b = ltpda_noisegen(pl1, pl2)
 
 Inputs:      
      for the first function call the parameter list has to contain:
        - nsecs
        - fs
        - pzmodel with gain
  
 b   - analysis object containing the resulting timeseries
 pl1 - parameter list containing the last state vector y.
 pl2 - parameter list containing the following parameters:

            - Tinit - matrix to calculate initial state vector
            - Tprop - matrix to calculate propagation vector
            - E     - matrix to calculate propagation vector
            - num   - numerator coefficients
            - den   - denominator coefficients
            - gain  
            - fs    - sampling frequency
            - nsecs - number of seconds

 The following call returns a parameter list object that contains the
 default parameter values:
 >> pl = ltpda_noisegen('Params')

 A Monsky 24-07-07
 
 $Id: ltpda_noisegen.m,v 1.7 2007/08/01 14:54:35 anneke Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = ltpda_noisegen(varargin) 
0002 
0003 % LTPDA_NOISEGEN uses pzm2ab and franklin to generate a time-series
0004 % from a given pzmodel
0005 %
0006 % calls:
0007 % >> [b, pl1, pl2] = ltpda_noisegen(pl)
0008 % >> [b, pl1] = ltpda_noisegen(pl)
0009 % >>  b = ltpda_noisegen(pl1, pl2)
0010 %
0011 % Inputs:
0012 %      for the first function call the parameter list has to contain:
0013 %        - nsecs
0014 %        - fs
0015 %        - pzmodel with gain
0016 %
0017 % b   - analysis object containing the resulting timeseries
0018 % pl1 - parameter list containing the last state vector y.
0019 % pl2 - parameter list containing the following parameters:
0020 %
0021 %            - Tinit - matrix to calculate initial state vector
0022 %            - Tprop - matrix to calculate propagation vector
0023 %            - E     - matrix to calculate propagation vector
0024 %            - num   - numerator coefficients
0025 %            - den   - denominator coefficients
0026 %            - gain
0027 %            - fs    - sampling frequency
0028 %            - nsecs - number of seconds
0029 %
0030 % The following call returns a parameter list object that contains the
0031 % default parameter values:
0032 % >> pl = ltpda_noisegen('Params')
0033 %
0034 % A Monsky 24-07-07
0035 %
0036 % $Id: ltpda_noisegen.m,v 1.7 2007/08/01 14:54:35 anneke Exp $
0037 %
0038 
0039 ALGONAME = mfilename;
0040 VERSION  = '$Id: ltpda_noisegen.m,v 1.7 2007/08/01 14:54:35 anneke Exp $';
0041 
0042 % Check if this is a call for parameters
0043 if nargin == 1
0044   in = char(varargin{1});
0045   if strcmp(in, 'Params')
0046     varargout{1} = getDefaultPL();
0047     return
0048   end
0049 end
0050 
0051 % capture input variable names
0052 invars = {};
0053 ps   = [];
0054 for j=1:nargin
0055   invars = [invars cellstr(inputname(j))];
0056   if isa(varargin{j}, 'plist')
0057     ps = [ps varargin{j}];
0058   end
0059 end
0060 
0061 pl = combine(ps);
0062 
0063 % look for all parameters
0064 pzmodel = find(pl, 'pzmodel');
0065 gain    = get(pzmodel, 'gain');
0066 fs      = find(pl, 'fs');
0067 nsecs   = find(pl, 'nsecs');
0068 state   = find(pl, 'state');
0069 Tinit   = find(pl, 'Tinit');
0070 Tprop   = find(pl, 'Tprop');
0071 E       = find(pl, 'E');
0072 num     = find(pl, 'num');
0073 den     = find(pl, 'den');
0074 % get data out of aos
0075 if ~isempty(state)
0076     d     = state.data;
0077     state = d.vals;
0078 end
0079 if ~isempty(Tinit)
0080     d     = Tinit.data;
0081     Tinit = d.vals;
0082 end
0083 if ~isempty(Tprop)
0084     d     = Tprop.data;
0085     Tprop = d.vals;
0086 end
0087 if ~isempty(E)
0088     d     = E.data;
0089     E = d.vals;
0090 end
0091 if ~isempty(num)
0092     d     = num.data;
0093     num = d.vals;
0094 end
0095 if ~isempty(den)
0096     d     = den.data;
0097     den = d.vals;
0098 end
0099 lengden = length(den);
0100 % check calling state
0101 if isempty(pzmodel) 
0102    if isempty(Tinit)
0103         error('### There is no Tinit matrix defined plist.');
0104     end 
0105    gain = find(pl, 'gain');  
0106   % set state vector
0107   if isempty(state)      
0108     disp('There is no pzmodel and no initial state vector given, so the initial state vector will be calculated by using the given matrices.\\');
0109     % make initial state vector
0110     y = nginit(Tinit);
0111   else
0112     disp('State vector from input parameter list is used as input state.');
0113     % use input state
0114     y = state;
0115   end
0116   
0117   % propogate to make noise vector
0118   [x, yo] = ngprop(Tprop, E, num, y, fs*nsecs, lengden);  
0119   state = yo;
0120 else
0121   % conversion
0122   disp('Filter coefficients are calculated from input pzmodel.');
0123   [num, den] = ngconv(pzmodel);
0124   % create matrices
0125   disp('Matrices are calculated from evaluated denominator coefficients.');
0126   [Tinit, Tprop, E] = ngsetup(den, fs); 
0127   lengden = length(den);
0128   % set state vector
0129   if isempty(state)
0130     disp('Since there is no given state vector it will be calculated.');  
0131     % make initial state vector
0132     y = nginit(Tinit);    
0133   else
0134     disp('Since there is a state vector given it is used for further calculations.');
0135     % use input state
0136     y = state;
0137   end  
0138   % propogate to make noise vector
0139   [x, yo] = ngprop(Tprop, E, num, y, fs*nsecs, lengden);
0140   state = yo;  
0141 end
0142 
0143 %------------------ Build outputs
0144 % make a new history object
0145 h = history(ALGONAME, VERSION, pl);
0146 h = set(h, 'invars', invars);
0147 % build variables into data object
0148 t = x*gain;
0149 b = ao(tsdata(t,fs),h);
0150 b = set(b, 'name', sprintf('noisegen(%s)', b.name));
0151 
0152 state  = ao(cdata(state),h);
0153 Tinit  = ao(cdata(Tinit),h);
0154 Tprop  = ao(cdata(Tprop),h);
0155 E      = ao(cdata(E),h);
0156 num    = ao(cdata(num),h);
0157 den    = ao(cdata(den),h);
0158 
0159 if nargout == 2
0160   % build pl with 'state'
0161   pl1 = plist('state', state);
0162 end
0163 
0164 if nargout == 3
0165   % build another pl with 'Tinit', 'Tprop', 'E', 'num', 'den'
0166   pl1 = plist('state',state);
0167   pl2 = plist('Tinit',Tinit,'Tprop',Tprop,'E',E,'num',num,'den',den,'gain',gain,'fs',fs,'nsecs',nsecs);
0168 end
0169 
0170 %------------------ Pass outputs
0171 
0172 if nargout == 1
0173   varargout{1} = b;
0174 end
0175 
0176 if nargout == 2
0177   varargout{1} = b;
0178   varargout{2} = pl1;
0179 end
0180 
0181 if nargout == 3
0182   varargout{1} = b;
0183   varargout{2} = pl1;
0184   varargout{3} = pl2;
0185 end
0186 
0187 
0188 % END
0189 
0190 %--------------------------------------------------------------------------
0191 % Get default params
0192 function plo = getDefaultPL()
0193 
0194 disp('* creating default plist...');
0195 plo = plist();
0196 plo = append(plo,param('nsecs',1000));
0197 disp('* done.');
0198 
0199 
0200 % END
0201

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003