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);

 PARAMETERS:   'f'  - frequency
               'q'  - Q
               'ri' - complex value (column vector)

 VERSION:      $Id: pole.html,v 1.14 2008/03/31 10:27:38 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 % PARAMETERS:   'f'  - frequency
0012 %               'q'  - Q
0013 %               'ri' - complex value (column vector)
0014 %
0015 % VERSION:      $Id: pole.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $
0016 %
0017 % HISTORY:      02-04-2007 M Hewitson
0018 %                  Creation
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 VERSION  = '$Id: pole.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $';
0023 CATEGORY = 'Constructor';
0024 
0025 %%%%%   Check if this is a call for parameters   %%%%%
0026 if nargin == 2
0027   if isa(varargin{1}, 'pole') && ischar(varargin{2})
0028     in = char(varargin{2});
0029     if strcmp(in, 'Params')
0030       p = plist;
0031       return
0032     elseif strcmp(in, 'Version')
0033       p = VERSION;
0034       return
0035     elseif strcmp(in, 'Category')
0036       p = CATEGORY;
0037       return
0038     end
0039   end
0040 end
0041 
0042 %%%%%%%%%%%%%%%%%%%%%%%%   define pole properties   %%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044   function p = init(version)
0045     p.name    = 'None';
0046     p.f       = NaN;
0047     p.q       = NaN;
0048     p.ri      = NaN;
0049     p.version = version;
0050     p.created = time;
0051     p.plist   = plist;
0052     p         = class(p, 'pole');
0053   end
0054 
0055 %%%%%%%%%%%%%%%%%%%%%%%%%%   Create pole object   %%%%%%%%%%%%%%%%%%%%%%%%%%%
0056 
0057 %%%%%%%%%%   p = pole()   %%%%%%%%%%
0058 if nargin == 0
0059 
0060   p = init(VERSION);
0061 
0062 elseif nargin == 1
0063 
0064   %%%%%%%%% From File %%%%%%%%%%%%
0065   if ischar(varargin{1})
0066 
0067     filename = varargin{1};
0068     [path, name, ext, vers] = fileparts(filename);
0069     switch ext
0070       case '.mat'
0071         p = load(filename);
0072         p = p.a;
0073       case '.xml'
0074         root_node = xmlread(filename);
0075         p = ltpda_xmlread(root_node, 'pole');
0076       otherwise
0077         error('### Unknown file type.');
0078     end
0079 
0080   %%%%%%%%%%   p = pole(number)           %%%%%%%%%%
0081   %%%%%%%%%%   p = pole(complex number)   %%%%%%%%%%
0082   elseif isnumeric(varargin{1})
0083 
0084     p = init(VERSION);
0085 
0086     if isreal(varargin{1})
0087       p.name    = 'real pole';
0088       p.f       = varargin{1};
0089       p.q       = NaN;
0090       p.ri      = pfq2ri(p.f);
0091     else
0092       p.name     = 'complex pole';
0093       [p.f, p.q] = pri2fq(varargin{1});
0094       if length(varargin{1}) == 1
0095         p.ri      = [varargin{1}; conj(varargin{1})];
0096       elseif length(varargin{1}) == 2
0097         p.ri      = varargin{1};
0098       else
0099         error('### Unknown constructor method. Please specify a complex number or a complex conjugate pair.');
0100       end
0101     end
0102 
0103   %%%%%%%%%%   p = pole(struct)   %%%%%%%%%%
0104   elseif isstruct(varargin{1})
0105 
0106     p = init(VERSION);
0107 
0108     fields = fieldnames(varargin{1});
0109     for ii = 1:length(fields)
0110       field = fields{ii};
0111       try
0112         p.(field) = varargin{1}.(field);
0113       catch
0114           error('### The field ''%s'' in the struct is not a pole property.', field)
0115       end
0116     end
0117 
0118   %%%%%%%%%%   p = pole(plist)   %%%%%%%%%%
0119   elseif isa(varargin{1}, 'plist')
0120 
0121     %% is the plist is empty then return an empty pole object
0122     if nparams(varargin{1}) == 0
0123       p = init(VERSION);
0124       p.plist = varargin{1};
0125     else
0126 
0127       p = init(VERSION);
0128       p = poleFromPlist(p, varargin{1});
0129       p.plist = varargin{1};
0130     end
0131 
0132   %%%%%%%%%%   p = pole(pole)   %%%%%%%%%%
0133   elseif isa(varargin{1}, 'pole')
0134     p = varargin{1};
0135   else
0136     error('### unknown constructor method for pole class.');
0137   end
0138 
0139 elseif nargin == 2
0140   %%%%%%%%%%% From DATABASE
0141   if isa(varargin{1}, 'database')
0142     p = retrieve(varargin{1}, varargin{2:end});
0143   %%%%%%%%%%   p = pole(f, q)   %%%%%%%%%%
0144   elseif isnumeric(varargin{1}) && isnumeric(varargin{2})
0145 
0146     ri   =  pfq2ri(varargin{1}, varargin{2});
0147 
0148     if length(ri) == 2 && isreal(ri(1)) && ri(1) == ri(2)
0149       disp('- splitting to two real poles');
0150       p      =  init(VERSION);
0151       if isnan(varargin{2})
0152         p.name = 'real pole';
0153       else
0154         p.name = 'complex pole';
0155       end
0156       p.f    =  varargin{1};
0157       p.q    =  varargin{2};
0158       p.ri   = ri;
0159       p      = [p p];
0160     else
0161       p      =  init(VERSION);
0162       if isnan(varargin{2})
0163         p.name = 'real pole';
0164       else
0165         p.name = 'complex pole';
0166       end
0167       p.f    =  varargin{1};
0168       p.q    =  varargin{2};
0169       p.ri   = ri;
0170     end
0171   else
0172     error('### unknown constructor method for pole class.');
0173   end
0174 
0175 end
0176 
0177 %--------------------------------------------------------------------------
0178 % construct a pole from plist
0179 %
0180 function p = poleFromPlist(p, pl)
0181 
0182   f  = find(pl, 'f');
0183   q  = find(pl, 'q');
0184   ri = find(pl, 'ri');
0185 
0186   name    = find(pl, 'name');
0187   version = find(pl, 'version');
0188   created = find(pl, 'created');
0189 
0190   if ~isempty(f)
0191     if ~isempty(q)
0192       % complex pole
0193       if isnan(q)
0194         p.name    = 'real pole';
0195       else
0196         p.name    = 'complex pole';
0197       end
0198       p.f       = f;
0199       p.q       = q;
0200       p.ri      = pfq2ri(p.f, p.q);
0201 
0202     else
0203       % real pole
0204       p.name    = 'real pole';
0205       p.f       = f;
0206       p.q       = NaN;
0207       p.ri      = pfq2ri(p.f);
0208 
0209     end
0210   elseif ~isempty(ri)
0211     % complex pole
0212     p.name    = 'complex pole';
0213     [p.f, p.q] = pri2fq(ri);
0214     p.ri      = [ri; conj(ri)];
0215 
0216   else
0217     error('### unknown constructor method for pole class.');
0218   end
0219 
0220   % Set other the properties in the plist
0221   if ~isempty(name)
0222     p.name = name;
0223   end
0224   if ~isempty(version)
0225     p.version = version;
0226   end
0227   if ~isempty(created)
0228     p.created = created;
0229   end
0230 
0231 
0232 end
0233 
0234 end % function p = pole(varargin)
0235 
0236 % END

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003