0001 function p = pole(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 VERSION = '$Id: pole.m,v 1.9 2007/08/31 17:40:08 hewitson Exp $';
0019
0020
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
0032
0033
0034 if nargin == 0
0035
0036 p = init();
0037
0038 elseif nargin == 1
0039
0040
0041 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl')
0042 p = fromxml(varargin{1});
0043
0044
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
0059
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
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
0091 elseif isa(varargin{1}, 'plist')
0092
0093 p = init();
0094 p = poleFromPlist(p, varargin{1});
0095
0096
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
0105 if isa(varargin{1}, 'database')
0106 p = retrieve(varargin{1}, varargin{2:end});
0107
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
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
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
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
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
0159
0160