Home > classes > @pole > pole.m

pole

PURPOSE ^

POLE construct a pole object.

SYNOPSIS ^

function p = pole(varargin)

DESCRIPTION ^

 POLE construct a pole object.

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

 DESCRIPTION:  POLE construct a pole object.

 CONSTRUCTORS: p = pole(f);
               p = pole(f,q);

 VERSION:      $Id: pole.m,v 1.9 2007/08/31 17:40:08 hewitson Exp $

 HISTORY:      02-04-2007 M Hewitson
                  Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function p = pole(varargin)
0002 % POLE construct a pole object.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION:  POLE construct a pole object.
0007 %
0008 % CONSTRUCTORS: p = pole(f);
0009 %               p = pole(f,q);
0010 %
0011 % VERSION:      $Id: pole.m,v 1.9 2007/08/31 17:40:08 hewitson Exp $
0012 %
0013 % HISTORY:      02-04-2007 M Hewitson
0014 %                  Creation
0015 %
0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0017 
0018 VERSION  = '$Id: pole.m,v 1.9 2007/08/31 17:40:08 hewitson Exp $';
0019 
0020 %%%%%%%%%%%%%%%%%%%%%%%%   define pole properties   %%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022   function p = init()
0023     p.name    = 'not defined';
0024     p.f       = NaN;
0025     p.q       = NaN;
0026     p.ri      = NaN;
0027     p.version = VERSION;
0028     p         = class(p, 'pole');
0029   end
0030 
0031 %%%%%%%%%%%%%%%%%%%%%%%%%%   Create pole object   %%%%%%%%%%%%%%%%%%%%%%%%%%%
0032 
0033 %%%%%%%%%%   p = pole()   %%%%%%%%%%
0034 if nargin == 0
0035 
0036   p = init();
0037 
0038 elseif nargin == 1
0039 
0040   %%%%%%%%%% Create from XML fragment %%%%%%%%%%%
0041   if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl')
0042     p = fromxml(varargin{1});
0043   
0044   %%%%%%%%% From File %%%%%%%%%%%%
0045   elseif ischar(varargin{1})
0046     
0047     filename = varargin{1};
0048     [path, name, ext, vers] = fileparts(filename);
0049     switch ext
0050       case '.mat'
0051         p = load(filename);
0052       case '.xml'
0053         p = xmlparse(pole, filename);
0054       otherwise
0055         error('### Unknown file type.');
0056     end
0057     
0058   %%%%%%%%%%   p = pole(number)           %%%%%%%%%%
0059   %%%%%%%%%%   p = pole(complex number)   %%%%%%%%%%
0060   elseif isnumeric(varargin{1})
0061 
0062     p = init();
0063 
0064     if isreal(varargin{1})
0065       p.name    = 'real pole';
0066       p.f       = varargin{1};
0067       p.q       = NaN;
0068       p.ri      = pfq2ri(p.f);
0069     else
0070       p.name     = 'complex pole';
0071       [p.f, p.q] = pri2fq(varargin{1});
0072       p.ri      = [varargin{1} conj(varargin{1})];
0073     end
0074 
0075   %%%%%%%%%%   p = pole(struct)   %%%%%%%%%%
0076   elseif isstruct(varargin{1})
0077 
0078     p = init();
0079 
0080     fields = fieldnames(varargin{1});
0081     for ii = 1:length(fields)
0082       field = fields{ii};
0083       try
0084         p.(field) = varargin{1}.(field);
0085       catch
0086           error('### The field ''%s'' in the struct is not a pole property.', field)
0087       end
0088     end
0089 
0090   %%%%%%%%%%   p = pole(struct)   %%%%%%%%%%
0091   elseif isa(varargin{1}, 'plist')
0092 
0093     p = init();
0094     p = poleFromPlist(p, varargin{1});
0095 
0096   %%%%%%%%%%   p = pole(pole)   %%%%%%%%%%
0097   elseif isa(varargin{1}, 'pole')
0098     p = varargin{1};
0099   else
0100     error('### unknown constructor method for pole class.');
0101   end
0102 
0103 elseif nargin == 2
0104   %%%%%%%%%%% From DATABASE
0105   if isa(varargin{1}, 'database')        
0106     p = retrieve(varargin{1}, varargin{2:end});
0107   %%%%%%%%%%   p = pole(f, q)   %%%%%%%%%%
0108   elseif isnumeric(varargin{1}) && isnumeric(varargin{2})
0109 
0110     p      =  init();
0111     p.name = 'complex pole';
0112     p.f    =  varargin{1};
0113     p.q    =  varargin{2};
0114     p.ri   =  pfq2ri(p.f, p.q);
0115 
0116   else
0117     error('### unknown constructor method for pole class.');
0118   end
0119 
0120 end
0121 
0122 %--------------------------------------------------------------------------
0123 % construct a pole from plist
0124 %
0125 function p = poleFromPlist(p, pl)
0126 
0127   f  = find(pl, 'f');
0128   q  = find(pl, 'q');
0129   ri = find(pl, 'ri');
0130 
0131   if ~isempty(f)
0132     if ~isempty(q)
0133       % complex pole
0134       p.name    = 'complex pole';
0135       p.f       = f;
0136       p.q       = q;
0137       p.ri      = pfq2ri(p.f, p.q);
0138 
0139     else
0140       % real pole
0141       p.name    = 'real pole';
0142       p.f       = f;
0143       p.q       = -1;
0144       p.ri      = pfq2ri(p.f);
0145 
0146     end
0147   elseif ~isempty(ri)
0148     % complex pole
0149     p.name    = 'complex pole';
0150     [p.f, p.q] = pri2fq(ri);
0151     p.ri      = ri;
0152 
0153   else
0154     error('### unknown constructor method for pole class.');
0155   end
0156 end
0157 
0158 end % function p = pole(varargin)
0159 
0160 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003