0001 function varargout = ltpda_noisegen(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
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
0060
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
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
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
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
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
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
0135 y = nginit(Tinit);
0136 else
0137 disp('State vector from input parameter list is used as input state.');
0138
0139 y = state;
0140 end
0141
0142
0143 [x, yo] = ngprop(Tprop, E, num, y, fs*nsecs);
0144 state = yo;
0145 else
0146
0147 disp('Filter coefficients are calculated from input pzmodel.');
0148 [num, den] = ngconv(pzmodel);
0149
0150 disp('Matrices are calculated from evaluated denominator coefficients.');
0151 [Tinit, Tprop, E] = ngsetup(den, fs);
0152
0153
0154 if isempty(state)
0155 disp('Since there is no given state vector it will be calculated.');
0156
0157 y = nginit(Tinit);
0158 else
0159 disp('Since there is a state vector given it is used for further calculations.');
0160
0161 y = state;
0162 end
0163
0164 [x, yo] = ngprop(Tprop, E, num, y, fs*nsecs);
0165 state = yo;
0166 end
0167
0168
0169
0170 h = history(ALGONAME, VERSION, pl);
0171 h = set(h, 'invars', invars);
0172
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
0185 pl1 = plist('state', state);
0186 end
0187
0188 if nargout == 3
0189
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
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
0213
0214
0215
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
0225
0226
0227