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

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003