Home > classes > @pzmodel > pzmodel.m

pzmodel

PURPOSE ^

PZMODEL constructor for pzmodel class.

SYNOPSIS ^

function pzm = pzmodel(varargin)

DESCRIPTION ^

 PZMODEL constructor for pzmodel class.

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

 DESCRIPTION: PZMODEL constructor for pzmodel class.

 CONSTRUCTOR: pzm = pzmodel(g, p, z) % construct from gain, poles, zeros
              pzm = pzmodel(g, p, z, 'name')
              pzm = pzmodel(pl);     % construct from plist

 PARAMETERS:  'gain'  - model gain
              'poles' - vector of pole objects
              'zeros' - vector of zero objects
              'name'  - name of model

 VERSION:     $Id: pzmodel.m,v 1.11 2008/01/07 18:13:10 ingo Exp $

 HISTORY:     03-04-2007 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function pzm = pzmodel(varargin)
0002 % PZMODEL constructor for pzmodel class.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: PZMODEL constructor for pzmodel class.
0007 %
0008 % CONSTRUCTOR: pzm = pzmodel(g, p, z) % construct from gain, poles, zeros
0009 %              pzm = pzmodel(g, p, z, 'name')
0010 %              pzm = pzmodel(pl);     % construct from plist
0011 %
0012 % PARAMETERS:  'gain'  - model gain
0013 %              'poles' - vector of pole objects
0014 %              'zeros' - vector of zero objects
0015 %              'name'  - name of model
0016 %
0017 % VERSION:     $Id: pzmodel.m,v 1.11 2008/01/07 18:13:10 ingo Exp $
0018 %
0019 % HISTORY:     03-04-2007 M Hewitson
0020 %                 Creation
0021 %
0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 
0024 VERSION  = '$Id: pzmodel.m,v 1.11 2008/01/07 18:13:10 ingo Exp $';
0025 
0026 %%%%%   Check if this is a call for parameters   %%%%%
0027 if nargin == 2
0028   if isa(varargin{1}, 'pzmodel') && ischar(varargin{2})
0029     in = char(varargin{2});
0030     if strcmp(in, 'Params')
0031       pzm = plist;
0032       return
0033     elseif strcmp(in, 'Version')
0034       pzm = VERSION;
0035       return
0036     end
0037   end
0038 end
0039 
0040 %%%%%%%%%%%%%%%%%%%%%%%%   define pzmodel properties   %%%%%%%%%%%%%%%%%%%%%%%%%
0041 
0042   function pz = init()
0043     pz.name    = 'pzmodel object';
0044     pz.gain    = 0;
0045     pz.poles   = pole;
0046     pz.zeros   = zero;
0047     pz.created = time;
0048     pz.version = VERSION;
0049     pz         = class(pz, 'pzmodel');
0050   end
0051 
0052 %%%%%%%%%%%%%%%%%%%%%%%%%%   Create pzmodel object   %%%%%%%%%%%%%%%%%%%%%%%%%%%
0053 
0054 %%%%%%%%%%   pzm = pzmodel()   %%%%%%%%%%
0055 if nargin == 0
0056 
0057  pzm = init();
0058 
0059 elseif nargin == 1
0060 
0061   %%%%%%%%%% Create from XML fragment %%%%%%%%%%%
0062   if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl')
0063     pzm = fromxml(varargin{1});
0064 
0065   %%%%%%%%%%   p = pzmodel(pzmodel)   %%%%%%%%%%
0066   elseif isa(varargin{1}, 'pzmodel')
0067     pzm = varargin{1};
0068 
0069   %%%%%%%%%% From File  %%%%%%%%%%%%
0070   elseif ischar(varargin{1})
0071 
0072     filename = varargin{1};
0073     [path, name, ext, vers] = fileparts(filename);
0074     switch ext
0075       case '.mat'
0076         pzm = load(filename);
0077         pzm = pzm.a;
0078       case '.xml'
0079         pzm = xmlparse(pzmodel, filename);
0080       otherwise
0081         error('### Unknown file type.');
0082     end
0083 
0084   %%%%%%%%%%   pzm = pzmodel(struct)   %%%%%%%%%%
0085   elseif isstruct(varargin{1})
0086 
0087     pzm = init();
0088 
0089     fields = fieldnames(varargin{1});
0090     for ii = 1:length(fields)
0091       field = fields{ii};
0092 
0093       %%% pole -> pole-object
0094       if strcmp(field, 'poles')
0095 
0096         ps = varargin{1}.poles;
0097         poles = [];
0098         for jj = 1:length(ps)
0099           if isstruct(ps(jj))
0100             poles = [poles pole(ps(jj))];
0101           else
0102             poles = [poles ps(jj)];
0103           end
0104         end
0105         pzm.poles = poles;
0106 
0107       %%% zero -> pole-object
0108       elseif strcmp(field, 'zeros')
0109 
0110         zs = varargin{1}.zeros;
0111         zeros = [];
0112         for jj = 1:length(zs)
0113           if isstruct(zs(jj))
0114             zeros = [zeros zero(zs(jj))];
0115           else
0116             zeros = [zeros zs(jj)];
0117           end
0118         end
0119         pzm.zeros = zeros;
0120 
0121       %%% created -> time-object
0122       elseif strcmp(field, 'created')
0123         if isstruct(varargin{1}.created)
0124           pzm.created = time(varargin{1}.created);
0125         else
0126           pzm.created = varargin{1}.created;
0127         end
0128       %%% All other
0129       else
0130         try
0131           pzm.(field) = varargin{1}.(field);
0132         catch
0133           error('### The field ''%s'' in the struct is not a pole property.', field)
0134         end
0135       end
0136     end
0137 
0138   %%%%%%%%%%   pzm = pzmodel(plist)   %%%%%%%%%%
0139   else
0140 
0141     pzm = init();
0142     pl  = varargin{1};
0143 
0144     pzm.gain    = find(pl, 'gain');
0145     pzm.poles   = find(pl, 'poles');
0146     pzm.zeros   = find(pl, 'zeros');
0147 
0148     % If the following properties are not set in the plist then use the default
0149     % values
0150     if ~isempty(find(pl, 'version'))
0151       pzm.version = find(pl, 'version');
0152     end
0153     if ~isempty(find(pl, 'created'))
0154       pzm.created = find(pl, 'created');
0155     end
0156     if ~isempty(find(pl, 'name'))
0157       pzm.name = find(pl, 'name');
0158     end
0159 
0160   end
0161 
0162 elseif nargin == 2
0163   %%%%%%%%%%%   From DATABASE   %%%%%%%%%%%
0164   if isa(varargin{1}, 'database')
0165     pzm = retrieve(varargin{1}, varargin{2:end});
0166   else
0167     error('### incorrect pzmodel constructor.');
0168   end
0169 
0170 
0171 %%%%%%%%%%%   3 or 4 inputs                             %%%%%%%%%%%
0172 %%%%%%%%%%%   pzm = pzmodel(gain, poles, zeros)         %%%%%%%%%%%
0173 %%%%%%%%%%%   pzm = pzmodel(gain, poles, zeros, name)   %%%%%%%%%%%
0174 %%%%%%%%%%%   pzm = pzmodel(ao, poles, zeros)           %%%%%%%%%%%
0175 %%%%%%%%%%%   pzm = pzmodel(ao, poles, zeros, name)     %%%%%%%%%%%
0176 elseif nargin >= 3
0177 
0178   pzm = init();
0179 
0180   a  = varargin{1};
0181   if isa(a, 'ao')
0182     gain = a.data.y(1);
0183   else
0184     gain = a;
0185   end
0186   poles = varargin{2};
0187   zeros = varargin{3};
0188   if nargin == 4
0189     name = char(varargin{4});
0190   else
0191     name = 'pzmodel';
0192   end
0193 
0194   % construct pz model object
0195   pzm.name  = name;
0196   pzm.gain  = gain;
0197   pzm.poles = poles;
0198   pzm.zeros = zeros;
0199 
0200 else
0201   error('### incorrect number of inputs.');
0202 end
0203 
0204 end
0205 
0206 % END

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003