PZMODEL constructor for pzmodel class. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: PZMODEL constructor for pzmodel class. CONSTRUCTOR: pzm = pzmodel() creates an empty pzmodel object. pzm = pzmodel(g, p, z) construct from gain, poles, zeros pzm = pzmodel(g, p, z, 'name') construct including name pzm = pzmodel('foo.fil'); construct from LISO .fil file pzm = pzmodel('foo.xml'); construct by loading the pzmodel from disk pzm = pzmodel('foo.mat'); construct by loading the pzmodel from disk pzm = pzmodel(pl) create a pzmodel object from the description given in the parameter list. Parameter sets for plist constructor (in order of priority): From XML File ------------- Construct a PZMODEL by loading it from an XML file. 'filename' - construct a PZMODEL from a filename. Example: plist('filename', 'pzm1.xml') [default: empty string] From MAT File ------------- Construct a PZMODEL by loading it from a MAT file. 'filename' - construct a PZMODEL from a filename. Example: plist('filename', 'pzm1.mat') [default: empty string] From LISO File -------------- Construct a PZMODEL by loading it from a LISO file. 'filename' - construct a PZMODEL from a filename. Example: plist('filename', 'pzm1.fil') [default: empty string] From Repository --------------- Construct a PZMODEL by retrieving it from an LTPDA repository. 'Hostname' - the repository hostname. Only those objects which are PZMODELs are returned. [default: 'localhost']; Additional parameters: 'Database' - The database name [default: 'ltpda'] 'ID' - A vector of object IDs. [default: []] From Poles/Zeros ---------------- Construct a PZMODEL from poles and zeros. 'Gain' - model gain [default: 1] 'Poles' - vector of pole objects [default: empty pole] 'Zeros' - vector of zero objects [default: empty zero] 'name' - name of model [default: 'None'] Example: plist('name', 'lp_filter', 'poles', [pole(0.1) pole(1,100)], ... 'gain', 2); From Plist ---------- 'Plist' - construct from a plist. The value passed should be a plist object. [default: empty plist] EXAMPLE 1: Still to be written ... VERSION: $Id: pzmodel.m,v 1.31 2008/03/24 23:51:38 mauro Exp $ HISTORY: 03-04-2007 M Hewitson Creation The following call returns a parameter list object that contains the default parameter values: >> pl = pzmodel(pzmodel,'Params') The following call returns a string that contains the routine CVS version: >> version = pzmodel(pzmodel,'Version') The following call returns a string that contains the routine category: >> category = pzmodel(pzmodel,'Category') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function pzm = pzmodel(varargin) 0002 % PZMODEL constructor for pzmodel class. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: PZMODEL constructor for pzmodel class. 0007 % 0008 % CONSTRUCTOR: 0009 % pzm = pzmodel() 0010 % creates an empty pzmodel object. 0011 % 0012 % pzm = pzmodel(g, p, z) 0013 % construct from gain, poles, zeros 0014 % 0015 % pzm = pzmodel(g, p, z, 'name') 0016 % construct including name 0017 % 0018 % pzm = pzmodel('foo.fil'); 0019 % construct from LISO .fil file 0020 % 0021 % pzm = pzmodel('foo.xml'); 0022 % construct by loading the pzmodel from disk 0023 % 0024 % pzm = pzmodel('foo.mat'); 0025 % construct by loading the pzmodel from disk 0026 % 0027 % pzm = pzmodel(pl) 0028 % create a pzmodel object from the description 0029 % given in the parameter list. 0030 % 0031 % Parameter sets for plist constructor (in order of priority): 0032 % 0033 % From XML File 0034 % ------------- 0035 % 0036 % Construct a PZMODEL by loading it from an XML file. 0037 % 0038 % 'filename' - construct a PZMODEL from a filename. 0039 % Example: plist('filename', 'pzm1.xml') 0040 % [default: empty string] 0041 % 0042 % 0043 % From MAT File 0044 % ------------- 0045 % 0046 % Construct a PZMODEL by loading it from a MAT file. 0047 % 0048 % 'filename' - construct a PZMODEL from a filename. 0049 % Example: plist('filename', 'pzm1.mat') 0050 % [default: empty string] 0051 % 0052 % 0053 % From LISO File 0054 % -------------- 0055 % 0056 % Construct a PZMODEL by loading it from a LISO file. 0057 % 0058 % 'filename' - construct a PZMODEL from a filename. 0059 % Example: plist('filename', 'pzm1.fil') 0060 % [default: empty string] 0061 % 0062 % 0063 % From Repository 0064 % --------------- 0065 % 0066 % Construct a PZMODEL by retrieving it from an LTPDA repository. 0067 % 0068 % 'Hostname' - the repository hostname. Only those objects which 0069 % are PZMODELs are returned. 0070 % [default: 'localhost']; 0071 % 0072 % Additional parameters: 0073 % 0074 % 'Database' - The database name [default: 'ltpda'] 0075 % 'ID' - A vector of object IDs. [default: []] 0076 % 0077 % 0078 % From Poles/Zeros 0079 % ---------------- 0080 % 0081 % Construct a PZMODEL from poles and zeros. 0082 % 0083 % 'Gain' - model gain [default: 1] 0084 % 'Poles' - vector of pole objects [default: empty pole] 0085 % 'Zeros' - vector of zero objects [default: empty zero] 0086 % 'name' - name of model [default: 'None'] 0087 % 0088 % Example: plist('name', 'lp_filter', 'poles', [pole(0.1) pole(1,100)], ... 0089 % 'gain', 2); 0090 % 0091 % 0092 % From Plist 0093 % ---------- 0094 % 0095 % 'Plist' - construct from a plist. The value passed should be a plist 0096 % object. 0097 % [default: empty plist] 0098 % 0099 % 0100 % EXAMPLE 1: Still to be written ... 0101 % 0102 % 0103 % VERSION: $Id: pzmodel.m,v 1.31 2008/03/24 23:51:38 mauro Exp $ 0104 % 0105 % HISTORY: 03-04-2007 M Hewitson 0106 % Creation 0107 % 0108 % The following call returns a parameter list object that contains the 0109 % default parameter values: 0110 % 0111 % >> pl = pzmodel(pzmodel,'Params') 0112 % 0113 % The following call returns a string that contains the routine CVS version: 0114 % 0115 % >> version = pzmodel(pzmodel,'Version') 0116 % 0117 % The following call returns a string that contains the routine category: 0118 % 0119 % >> category = pzmodel(pzmodel,'Category') 0120 % 0121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0122 0123 ALGONAME = mfilename; 0124 VERSION = '$Id: pzmodel.m,v 1.31 2008/03/24 23:51:38 mauro Exp $'; 0125 CATEGORY = 'Constructor'; 0126 0127 %% Check if this is a special call: 0128 % default parameter list, cvs-version, category 0129 if (nargin == 2 || nargin == 3) && isa(varargin{1}, 'pzmodel') && ischar(varargin{2}) 0130 in = char(varargin{2}); 0131 if strcmpi(in, 'Params') 0132 if nargin == 2 0133 pzm = getDefaultPlist(); 0134 else 0135 pzm = getDefaultPlist(varargin{3}); 0136 end 0137 return 0138 elseif strcmpi(in, 'Version') 0139 pzm = VERSION; 0140 return 0141 elseif strcmpi(in, 'Category') 0142 pzm = CATEGORY; 0143 return 0144 end 0145 end 0146 0147 0148 %% process input arguments 0149 args = []; 0150 k = 0; 0151 pls = []; 0152 for j=1:nargin 0153 if ~isempty(varargin{j}) 0154 k = k + 1; 0155 if isa(varargin{j}, 'plist') 0156 pls = [pls varargin{j}]; 0157 else 0158 args(k).val = varargin{j}; 0159 args(k).n = j; 0160 end 0161 end 0162 end 0163 0164 %% We could have multiple input plist objects. Combine them here. 0165 if isa(pls, 'plist') 0166 pl = combine(pls); 0167 else 0168 pl = []; 0169 end 0170 0171 Nargs = length(args); 0172 if ~isempty(pl) 0173 args(Nargs+1).val = pl; 0174 args(Nargs+1).n = j+1; 0175 Nargs = length(args); 0176 end 0177 0178 0179 %% %%%%%%%%%%%%%%%%%%%%%%%% Create pzmodel object %%%%%%%%%%%%%%%%%%%%%%%%%%% 0180 0181 switch nargin 0182 0183 case 0 0184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0185 %%% No Parameters %%% 0186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0187 0188 %%%%%%%%%% pzm = pzmodel() %%%%%%%%%% 0189 % create empty pzmodel object 0190 0191 pzm = init(VERSION); 0192 0193 case 1 0194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0195 %%% One Parameter %%% 0196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0197 0198 if isa(varargin{1}, 'pzmodel') 0199 %%%%%%%%%% pzm = pzmodel(pzmodel) %%%%%%%%%% 0200 % copy existing pzmodel 0201 0202 pzm = varargin{1}; 0203 pzm.version = VERSION; 0204 0205 elseif ischar(varargin{1}) 0206 %%%%%%%%%% pzm = pzmodel('foo.xml') %%%%%%%%%% 0207 %%%%%%%%%% pzm = pzmodel('foo.mat') %%%%%%%%%% 0208 %%%%%%%%%% pzm = pzmodel('foo.fil') %%%%%%%%%% 0209 % from filename: XML, MAT, LISO 0210 0211 filename = varargin{1}; 0212 [path, name, ext, vers] = fileparts(filename); 0213 switch ext 0214 case '.fil' 0215 pzm = pzmFromLISO(filename, VERSION, ALGONAME); 0216 case '.mat' 0217 pzm = load(filename); 0218 pzm = pzm.a; 0219 case '.xml' 0220 root_node = xmlread(filename); 0221 pzm = ltpda_xmlread(root_node, 'pzmodel'); 0222 otherwise 0223 error('### Unknown file type.'); 0224 end 0225 0226 elseif isstruct(varargin{1}) 0227 %%%%%%%%%% pzm = pzmodel(struct) %%%%%%%%%% 0228 0229 pzm = init(VERSION); 0230 0231 fields = fieldnames(varargin{1}); 0232 for ii = 1:length(fields) 0233 field = fields{ii}; 0234 0235 %%% pole -> pole-object 0236 if strcmp(field, 'poles') 0237 0238 ps = varargin{1}.poles; 0239 poles = []; 0240 for jj = 1:length(ps) 0241 if isstruct(ps(jj)) 0242 poles = [poles pole(ps(jj))]; 0243 else 0244 poles = [poles ps(jj)]; 0245 end 0246 end 0247 pzm.poles = poles; 0248 0249 %%% zero -> pole-object 0250 elseif strcmp(field, 'zeros') 0251 0252 zs = varargin{1}.zeros; 0253 zeros = []; 0254 for jj = 1:length(zs) 0255 if isstruct(zs(jj)) 0256 zeros = [zeros zero(zs(jj))]; 0257 else 0258 zeros = [zeros zs(jj)]; 0259 end 0260 end 0261 pzm.zeros = zeros; 0262 0263 %%% created -> time-object 0264 elseif strcmp(field, 'created') 0265 if isstruct(varargin{1}.created) 0266 pzm.created = time(varargin{1}.created); 0267 else 0268 pzm.created = varargin{1}.created; 0269 end 0270 %%% All other 0271 else 0272 try 0273 pzm.(field) = varargin{1}.(field); 0274 catch 0275 error('### The field ''%s'' in the struct is not a pole property.', field) 0276 end 0277 end 0278 end 0279 0280 elseif isa(varargin{1}, 'plist') 0281 %%%%%%%%%% pzm = pzmodel(plist) %%%%%%%%%% 0282 % Parameter list 0283 0284 pl = varargin{1}; 0285 0286 filename = find(pl, 'filename'); 0287 hostname = find(pl, 'hostname'); 0288 gain = find(pl, 'gain'); 0289 ipl = find(pl, 'plist'); 0290 0291 % Selection of construction method 0292 if ~isempty(filename) 0293 0294 %----------------------------------------------------- 0295 %--- Construct from file 0296 %----------------------------------------------------- 0297 switch ext 0298 case '.mat' 0299 % Do a filename constructor 0300 pzm = load(filename); 0301 pzm = pzm.a; 0302 pzm.plist = pl; 0303 case '.xml' 0304 % Do a filename constructor 0305 root_node = xmlread(filename); 0306 pzm = ltpda_xmlread(root_node, 'pzmodel'); 0307 pzm.plist = pl; 0308 case '.fil' 0309 % Do a filename constructor 0310 pzm = pzmFromLISO(filename, VERSION, ALGONAME); 0311 pzm.plist = pl; 0312 otherwise 0313 error('### Unknown file type.'); 0314 end 0315 0316 elseif ~isempty(hostname) 0317 0318 %----------------------------------------------------- 0319 %--- Construct from repository 0320 %----------------------------------------------------- 0321 0322 % do hostname constructor 0323 pzm = pzmodelFromRepository(pl, VERSION, ALGONAME); 0324 pzm.plist = remove(pl, 'conn'); 0325 0326 elseif ~isempty(gain) 0327 0328 %----------------------------------------------------- 0329 %--- Construct from poles, zeros and gain 0330 %----------------------------------------------------- 0331 0332 % Construct from poles and zeros 0333 pzm = pzmodelFromPolesandZeros(pl, VERSION, ALGONAME); 0334 0335 elseif ~isempty(ipl) 0336 %----------------------------------------------------- 0337 %--- Construct from plist 0338 %----------------------------------------------------- 0339 0340 % if the plist is empty, we return an empty PZMODEL 0341 if nparams(ipl) == 0 0342 pzm = init(VERSION); 0343 else 0344 % do plist constructor 0345 pzm = pzmodel(ipl); 0346 end 0347 0348 else 0349 %----------------------------------------------------- 0350 %--- ERROR 0351 %----------------------------------------------------- 0352 0353 %% is the plist is empty then return an empty PZMODEL 0354 if nparams(pl) == 0 0355 pzm = init(VERSION); 0356 else 0357 error('### Unknown PZMODEL constructor method.'); 0358 end 0359 end 0360 0361 else 0362 error('### Unknown PZMODEL constructor method.'); 0363 end 0364 0365 case 2 0366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0367 %%% Two Parameter %%% 0368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0369 0370 %%%%%%%%%% pzm = pzmodel(database, IDs) %%%%%%%%%% 0371 % From DATABASE 0372 if isa(varargin{1}, 'database') 0373 pzm = retrieve(varargin{1}, varargin{2:end}); 0374 else 0375 error('### incorrect pzmodel constructor.'); 0376 end 0377 0378 case {3,4} 0379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0380 %%% Three/Four Parameter %%% 0381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0382 0383 %%%%%%%%%%% 3 or 4 inputs %%%%%%%%%%% 0384 %%%%%%%%%%% pzm = pzmodel(gain, poles, zeros) %%%%%%%%%%% 0385 %%%%%%%%%%% pzm = pzmodel(gain, poles, zeros, name) %%%%%%%%%%% 0386 %%%%%%%%%%% pzm = pzmodel(ao, poles, zeros) %%%%%%%%%%% 0387 %%%%%%%%%%% pzm = pzmodel(ao, poles, zeros, name) %%%%%%%%%%% 0388 0389 pzm = init(VERSION); 0390 0391 a = varargin{1}; 0392 if isa(a, 'ao') 0393 gain = a.data.y(1); 0394 else 0395 gain = a; 0396 end 0397 poles = varargin{2}; 0398 zeros = varargin{3}; 0399 if nargin == 4 0400 name = char(varargin{4}); 0401 else 0402 name = 'None'; 0403 end 0404 0405 % construct pzmodel object 0406 pzm.name = name; 0407 pzm.gain = gain; 0408 pzm.poles = poles; 0409 pzm.zeros = zeros; 0410 pzm.plist = plist('gain', gain, 'poles', poles, 'zeros', zeros); 0411 0412 otherwise 0413 error('### incorrect number of inputs.'); 0414 end 0415 0416 end % function pzm = pzmodel(varargin) 0417 0418 0419 %% Helper functions 0420 0421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0422 % 0423 % FUNCTION: pzmodelFromRepository 0424 % 0425 % DESCRIPTION: Construct a pzmodel from a repository 0426 % 0427 % CALL: f = pzmodelFromRepository(pli, version, algoname) 0428 % 0429 % PARAMETER: pli: Parameter list object 0430 % VERSION: cvs version string 0431 % ALGONAME: The m-file name (use the mfilename command) 0432 % 0433 % HISTORY: 22-03-2008 M Hewitson 0434 % Creation 0435 % 0436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0437 0438 function aos = pzmodelFromRepository(pli, version, algoname) 0439 0440 % Add default values 0441 pl = combine(pli, getDefaultPlist('From Repository')); 0442 0443 % Get parameters 0444 conn = find(pl, 'conn'); 0445 hostname = find(pl, 'hostname'); 0446 database = find(pl, 'database'); 0447 ids = find(pl, 'id'); 0448 0449 % do we have a connection? 0450 closeConn = 0; 0451 if isempty(conn) 0452 closeConn = 1; 0453 % Connect to repository 0454 conn = mysql_connect(hostname, database); 0455 end 0456 if ~isa(conn, 'database') 0457 error('### connection failed.'); 0458 end 0459 % Get each ID 0460 Nids = length(ids); 0461 aos = []; 0462 for kk=1:Nids 0463 0464 %---- This id 0465 id = ids(kk); 0466 disp(sprintf(' - retrieving ID %d', id)); 0467 0468 %---- check ID object type 0469 tt = mysql_getObjType(conn, id); 0470 %---- If this is an AO 0471 if strcmp(tt, mfilename) 0472 %---- call database constructor 0473 a = ltpda_obj_retrieve(conn, id); 0474 %---- Add history 0475 a.plist = pl; 0476 %---- Add to output array 0477 aos = [aos a]; 0478 else 0479 warning(' !skipping ID %d, type %s', id, tt); 0480 end 0481 0482 end 0483 0484 % close connection 0485 if closeConn 0486 close(conn); 0487 end 0488 0489 end % function aos = pzmodelFromRepository(pli, version, algoname) 0490 0491 0492 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0493 % 0494 % FUNCTION: pzmFromLISO 0495 % 0496 % DESCRIPTION: Construct a pzmodel from a LISO file 0497 % 0498 % CALL: f = pzmFromLISO(filename, version, algoname) 0499 % 0500 % PARAMETER: filename: File name containing the object 0501 % VERSION: cvs version string 0502 % ALGONAME: The m-file name (use the mfilename command) 0503 % 0504 % HISTORY: 22-03-2008 M Hewitson 0505 % Creation 0506 % 0507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0508 0509 function pzm = pzmFromLISO(filename, version, algoname) 0510 0511 pzm = init(version); 0512 0513 poles = []; 0514 zeros = []; 0515 gain = []; 0516 0517 % Open the file for reading 0518 fd = fopen(filename, 'r'); 0519 disp(['--- reading ' filename]); 0520 while ~feof(fd) 0521 0522 line = fgetl(fd); 0523 0524 % get first token 0525 [s,r] = strtok(line); 0526 0527 if strcmp(s, 'pole') 0528 0529 % get next token as frequency 0530 [s,r] = strtok(r); 0531 pf = lisoStr2Num(s); 0532 % does this pole have a Q? 0533 pq = NaN; 0534 if ~isempty(r) 0535 [s,r] = strtok(r); 0536 if isnumeric(lisoStr2Num(s)) 0537 pq = lisoStr2Num(s); 0538 end 0539 end 0540 % make pole 0541 if isnan(pq) 0542 p = pole(pf); 0543 disp(sprintf(' -- found pole: %g', pf)); 0544 else 0545 p = pole(pf, pq); 0546 disp(sprintf(' -- found pole: %g, %g', pf, pq)); 0547 end 0548 poles = [poles p]; 0549 0550 elseif strcmp(s, 'zero') 0551 % get next token as frequency 0552 [s,r] = strtok(r); 0553 zf = lisoStr2Num(s); 0554 % does this pole have a Q? 0555 zq = NaN; 0556 if ~isempty(r) 0557 [s,r] = strtok(r); 0558 if isnumeric(lisoStr2Num(s)) 0559 zq = lisoStr2Num(s); 0560 end 0561 end 0562 % make zero 0563 if isnan(zq) 0564 z = zero(zf); 0565 disp(sprintf(' -- found zero: %g', zf)); 0566 else 0567 z = zero(zf, zq); 0568 disp(sprintf(' -- found zero: %g, %g', zf, zq)); 0569 end 0570 zeros = [zeros z]; 0571 0572 elseif strcmp(s, 'factor') 0573 % get next token as gain 0574 [s, r] = strtok(r); 0575 gain = lisoStr2Num(s); 0576 disp(sprintf(' -- found factor: %g', gain)); 0577 end 0578 0579 end 0580 0581 % Close file 0582 fclose(fd); 0583 0584 % get model name 0585 [path, name, ext, vers] = fileparts(filename); 0586 0587 pzm = pzmodel(gain, poles, zeros, name); 0588 0589 end % pzm = pzmFromLISO(filename, version, algoname) 0590 0591 0592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0593 % 0594 % FUNCTION: pzmodelFromPolesandZeros 0595 % 0596 % DESCRIPTION: Construct a pzmodel from poles and zeros 0597 % 0598 % CALL: f = pzmodelFromPolesandZeros(pli, version, algoname) 0599 % 0600 % PARAMETER: pli: Parameter list object 0601 % version: cvs version string 0602 % algoname: The m-file name (use the mfilename command) 0603 % 0604 % HISTORY: 22-03-2008 M Hewitson 0605 % Creation 0606 % 0607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0608 0609 function pzm = pzmodelFromPolesandZeros(pli, version, algoname) 0610 0611 % Add default values 0612 pl = combine(pli, getDefaultPlist('From Poles/Zeros')); 0613 0614 pzm = init(version); 0615 0616 pzm.gain = find(pl, 'gain'); 0617 ps = find(pl, 'poles'); 0618 pso=[]; 0619 for j=1:length(ps) 0620 if ~isnan(ps(j).f) 0621 pso = [pso ps(j)]; 0622 end 0623 end 0624 pzm.poles = pso; 0625 zs = find(pl, 'zeros'); 0626 zso=[]; 0627 for j=1:length(zs) 0628 if ~isnan(zs(j).f) 0629 zso = [zso zs(j)]; 0630 end 0631 end 0632 pzm.zeros = zso; 0633 0634 % If the following properties are not set in the plist then use the default 0635 % values 0636 if ~isempty(find(pl, 'version')) 0637 pzm.version = find(pl, 'version'); 0638 end 0639 if ~isempty(find(pl, 'created')) 0640 pzm.created = find(pl, 'created'); 0641 end 0642 if ~isempty(find(pl, 'name')) 0643 pzm.name = find(pl, 'name'); 0644 end 0645 0646 pzm.plist = pli; 0647 0648 end % function pzm = pzmodelFromPolesandZeros(pli, version, algoname) 0649 0650 0651 %%%%%%%%%%% A function to convert LISO number strings to doubles %%%%%%%%%% 0652 0653 function d = lisoStr2Num(s) 0654 0655 s = strrep(s, 'm', 'e-3'); 0656 s = strrep(s, 'u', 'e-6'); 0657 s = strrep(s, 'n', 'e-9'); 0658 s = strrep(s, 'p', 'e-12'); 0659 s = strrep(s, 'f', 'e-15'); 0660 s = strrep(s, 'k', 'e3'); 0661 s = strrep(s, 'M', 'e6'); 0662 s = strrep(s, 'G', 'e9'); 0663 0664 d = str2double(s); 0665 0666 end % function d = lisoStr2Num(s) 0667 0668 0669 %%%%%%%%%%%%%%%%%%%%%%%% define pzmodel properties %%%%%%%%%%%%%%%%%%%% 0670 0671 function pz = init(version) 0672 pz.name = 'None'; 0673 pz.gain = 0; 0674 pz.poles = pole; 0675 pz.zeros = zero; 0676 pz.created = time; 0677 pz.version = version; 0678 pz.plist = ''; 0679 pz = class(pz, 'pzmodel'); 0680 end % function pz = init(version) 0681 0682 0683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0684 % 0685 % FUNCTION: getDefaultPlist 0686 % 0687 % DESCRIPTION: Default Parameter Lists 0688 % 0689 % CALL: out = getDefaultPlist(set-string) 0690 % 0691 % PARAMETER: set-string: A string which defines the default parameter list. 0692 % 0693 % HISTORY: 11-02-2008 M Hueller 0694 % Creation 0695 % 0696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0697 function out = getDefaultPlist(varargin) 0698 0699 % list of available parameter sets 0700 sets = {'From XML File', ... 0701 'From MAT File', ... 0702 'From LISO File', ... 0703 'From Repository', ... 0704 'From Poles/Zeros', ... 0705 'From Plist'}; 0706 0707 if nargin == 0 0708 out = sets; 0709 return 0710 end 0711 0712 set = varargin{1}; 0713 switch set 0714 %------------------------------------------ 0715 %--- Pole/zero constructor 0716 %------------------------------------------ 0717 case 'From Poles/Zeros' 0718 out = plist('gain', 1, ... 0719 'poles', pole, ... 0720 'zeros', zero, ... 0721 'name', 'None'); 0722 %------------------------------------------ 0723 %--- Repository constructor 0724 %------------------------------------------ 0725 case 'From Repository' 0726 out = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []); 0727 0728 %------------------------------------------ 0729 %--- Read from XML file 0730 %------------------------------------------ 0731 case 'From XML File' 0732 out = plist('filename', ''); 0733 0734 %------------------------------------------ 0735 %--- Read from MAT file 0736 %------------------------------------------ 0737 case 'From MAT File' 0738 out = plist('filename', ''); 0739 0740 %------------------------------------------ 0741 %--- Create from LISO file 0742 %------------------------------------------ 0743 case 'From LISO File' 0744 out = plist('filename', ''); 0745 0746 %------------------------------------------ 0747 %--- Create from a plist 0748 %------------------------------------------ 0749 case 'From Plist' 0750 out = plist('Plist', []); 0751 0752 otherwise 0753 out = plist(); 0754 0755 end 0756 0757 end % function out = getDefaultPlist(varargin) 0758 0759 0760 0761