Home > classes > @pzmodel > fromLISO.m

fromLISO

PURPOSE ^

FROMLISO Construct a pzmodel from a LISO file

SYNOPSIS ^

function pzm = fromLISO(pzm, pli)

DESCRIPTION ^

 FROMLISO Construct a pzmodel from a LISO file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 FUNCTION:    fromLISO

 DESCRIPTION: Construct a pzmodel from a LISO file

 CALL:        pzm = fromLISO(pzm, pli)

 PARAMETER:   pzm: Empty pole/zero model
              pli: input plist (must contain the filename)

 VERSION:     $Id: fromLISO.m,v 1.3 2008/08/22 14:17:27 ingo Exp $

 HISTORY:     22-03-2008 M Hewitson
              Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % FROMLISO Construct a pzmodel from a LISO file
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % FUNCTION:    fromLISO
0005 %
0006 % DESCRIPTION: Construct a pzmodel from a LISO file
0007 %
0008 % CALL:        pzm = fromLISO(pzm, pli)
0009 %
0010 % PARAMETER:   pzm: Empty pole/zero model
0011 %              pli: input plist (must contain the filename)
0012 %
0013 % VERSION:     $Id: fromLISO.m,v 1.3 2008/08/22 14:17:27 ingo Exp $
0014 %
0015 % HISTORY:     22-03-2008 M Hewitson
0016 %              Creation
0017 %
0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 
0020 function pzm = fromLISO(pzm, pli)
0021 
0022   import utils.const.*
0023 
0024   VERSION = '$Id: fromLISO.m,v 1.3 2008/08/22 14:17:27 ingo Exp $';
0025 
0026   ii = pzm.getInfo(class(pzm), 'From LISO File');
0027 
0028   % Set the method version string in the minfo object
0029   ii.setMversion([VERSION '-->' ii.mversion]);
0030 
0031   filename = find(pli, 'filename');
0032 
0033   poles = [];
0034   zeros = [];
0035   gain  = [];
0036   % Open the file for reading
0037   fd = fopen(filename, 'r');
0038   utils.helper.msg(msg.OPROC2, ['reading ' filename]);
0039   while ~feof(fd)
0040     line = fgetl(fd);
0041     % get first token
0042     [s,r] = strtok(line);
0043     if strcmp(s, 'pole')
0044       % get next token as frequency
0045       [s,r] = strtok(r);
0046       pf    = lisoStr2Num(s);
0047       % does this pole have a Q?
0048       pq = NaN;
0049       if ~isempty(r)
0050         [s,r] = strtok(r);
0051         if isnumeric(lisoStr2Num(s))
0052           pq = lisoStr2Num(s);
0053         end
0054       end
0055       % make pole
0056       if isnan(pq)
0057         p = pz(pf);
0058         utils.helper.msg(msg.OPROC2, 'found pole: %g', pf);
0059       else
0060         p = pz(pf, pq);
0061         utils.helper.msg(msg.OPROC2, 'found pole: %g, %g', pf, pq);
0062       end
0063       poles = [poles p];
0064     elseif strcmp(s, 'zero')
0065       % get next token as frequency
0066       [s,r] = strtok(r);
0067       zf    = lisoStr2Num(s);
0068       % does this pole have a Q?
0069       zq = NaN;
0070       if ~isempty(r)
0071         [s,r] = strtok(r);
0072         if isnumeric(lisoStr2Num(s))
0073           zq = lisoStr2Num(s);
0074         end
0075       end
0076       % make zero
0077       if isnan(zq)
0078         z = pz(zf);
0079         utils.helper.msg(msg.OPROC2, 'found zero: %g', zf);
0080       else
0081         z = pz(zf, zq);
0082         utils.helper.msg(msg.OPROC2, 'found zero: %g, %g', zf, zq);
0083       end
0084       zeros = [zeros z];
0085     elseif strcmp(s, 'factor')
0086       % get next token as gain
0087       [s, r] = strtok(r);
0088       gain   = lisoStr2Num(s);
0089       utils.helper.msg(msg.OPROC2, 'found factor: %g', gain);
0090     end
0091   end
0092   % Close file
0093   fclose(fd);
0094   % get model name
0095   [path, name, ext, vers] = fileparts(filename);
0096   % set object
0097   pzm.gain  = gain;
0098   pzm.poles = poles;
0099   pzm.zeros = zeros;
0100   pzm.name  = name;
0101 
0102   pzm.addHistory(ii, pli, [], []);
0103 
0104 end
0105 
0106 %%%%%%%%%%% A function to convert LISO number strings to doubles %%%%%%%%%%
0107 
0108 function d = lisoStr2Num(s)
0109 
0110   s = strrep(s, 'm', 'e-3');
0111   s = strrep(s, 'u', 'e-6');
0112   s = strrep(s, 'n', 'e-9');
0113   s = strrep(s, 'p', 'e-12');
0114   s = strrep(s, 'f', 'e-15');
0115   s = strrep(s, 'k', 'e3');
0116   s = strrep(s, 'M', 'e6');
0117   s = strrep(s, 'G', 'e9');
0118 
0119   d = str2double(s);
0120 
0121 end % function d = lisoStr2Num(s)

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003