0001 function p = pole(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 VERSION = '$Id: pole.m,v 1.20 2008/02/17 11:38:51 hewitson Exp $';
0023 CATEGORY = 'Constructor';
0024
0025
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
0043
0044 function p = init()
0045 p.name = 'not defined';
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
0056
0057
0058 if nargin == 0
0059
0060 p = init();
0061
0062 elseif nargin == 1
0063
0064
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
0081
0082 elseif isnumeric(varargin{1})
0083
0084 p = init();
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
0104 elseif isstruct(varargin{1})
0105
0106 p = init();
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
0119 elseif isa(varargin{1}, 'plist')
0120
0121 p = init();
0122 p = poleFromPlist(p, varargin{1});
0123 p.plist = varargin{1};
0124
0125
0126 elseif isa(varargin{1}, 'pole')
0127 p = varargin{1};
0128 else
0129 error('### unknown constructor method for pole class.');
0130 end
0131
0132 elseif nargin == 2
0133
0134 if isa(varargin{1}, 'database')
0135 p = retrieve(varargin{1}, varargin{2:end});
0136
0137 elseif isnumeric(varargin{1}) && isnumeric(varargin{2})
0138
0139 ri = pfq2ri(varargin{1}, varargin{2});
0140
0141 if length(ri) == 2 && isreal(ri(1)) && ri(1) == ri(2)
0142 disp('- splitting to two real poles');
0143 p = init();
0144 if isnan(varargin{2})
0145 p.name = 'real pole';
0146 else
0147 p.name = 'complex pole';
0148 end
0149 p.f = varargin{1};
0150 p.q = varargin{2};
0151 p.ri = ri;
0152 p = [p p];
0153 else
0154 p = init();
0155 if isnan(varargin{2})
0156 p.name = 'real pole';
0157 else
0158 p.name = 'complex pole';
0159 end
0160 p.f = varargin{1};
0161 p.q = varargin{2};
0162 p.ri = ri;
0163 end
0164 else
0165 error('### unknown constructor method for pole class.');
0166 end
0167
0168 end
0169
0170
0171
0172
0173 function p = poleFromPlist(p, pl)
0174
0175 f = find(pl, 'f');
0176 q = find(pl, 'q');
0177 ri = find(pl, 'ri');
0178
0179 name = find(pl, 'name');
0180 version = find(pl, 'version');
0181 created = find(pl, 'created');
0182
0183 if ~isempty(f)
0184 if ~isempty(q)
0185
0186 if isnan(q)
0187 p.name = 'real pole';
0188 else
0189 p.name = 'complex pole';
0190 end
0191 p.f = f;
0192 p.q = q;
0193 p.ri = pfq2ri(p.f, p.q);
0194
0195 else
0196
0197 p.name = 'real pole';
0198 p.f = f;
0199 p.q = NaN;
0200 p.ri = pfq2ri(p.f);
0201
0202 end
0203 elseif ~isempty(ri)
0204
0205 p.name = 'complex pole';
0206 [p.f, p.q] = pri2fq(ri);
0207 p.ri = [ri; conj(ri)];
0208
0209 else
0210 error('### unknown constructor method for pole class.');
0211 end
0212
0213
0214 if ~isempty(name)
0215 p.name = name;
0216 end
0217 if ~isempty(version)
0218 p.version = version;
0219 end
0220 if ~isempty(created)
0221 p.created = created;
0222 end
0223
0224
0225 end
0226
0227 end
0228
0229