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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: LTPDA_NOISEGEN uses pzm2ab and franklin to generate a time-series
 from a given pzmodel

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003