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.15 2008/01/11 13:41:12 ingo Exp $';
0019
0020
0021 if nargin == 2
0022 if isa(varargin{1}, 'pole') && ischar(varargin{2})
0023 in = char(varargin{2});
0024 if strcmp(in, 'Params')
0025 p = plist;
0026 return
0027 elseif strcmp(in, 'Version')
0028 p = VERSION;
0029 return
0030 end
0031 end
0032 end
0033
0034
0035
0036 function p = init()
0037 p.name = 'not defined';
0038 p.f = NaN;
0039 p.q = NaN;
0040 p.ri = NaN;
0041 p.version = VERSION;
0042 p.created = time;
0043 p = class(p, 'pole');
0044 end
0045
0046
0047
0048
0049 if nargin == 0
0050
0051 p = init();
0052
0053 elseif nargin == 1
0054
0055
0056 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl')
0057 p = fromxml(varargin{1});
0058
0059
0060 elseif ischar(varargin{1})
0061
0062 filename = varargin{1};
0063 [path, name, ext, vers] = fileparts(filename);
0064 switch ext
0065 case '.mat'
0066 p = load(filename);
0067 p = p.a;
0068 case '.xml'
0069 p = xmlparse(pole, filename);
0070 otherwise
0071 error('### Unknown file type.');
0072 end
0073
0074
0075
0076 elseif isnumeric(varargin{1})
0077
0078 p = init();
0079
0080 if isreal(varargin{1})
0081 p.name = 'real pole';
0082 p.f = varargin{1};
0083 p.q = NaN;
0084 p.ri = pfq2ri(p.f);
0085 else
0086 p.name = 'complex pole';
0087 [p.f, p.q] = pri2fq(varargin{1});
0088 p.ri = [varargin{1} conj(varargin{1})];
0089 end
0090
0091
0092 elseif isstruct(varargin{1})
0093
0094 p = init();
0095
0096 fields = fieldnames(varargin{1});
0097 for ii = 1:length(fields)
0098 field = fields{ii};
0099 try
0100 p.(field) = varargin{1}.(field);
0101 catch
0102 error('### The field ''%s'' in the struct is not a pole property.', field)
0103 end
0104 end
0105
0106
0107 elseif isa(varargin{1}, 'plist')
0108
0109 p = init();
0110 p = poleFromPlist(p, varargin{1});
0111
0112
0113 elseif isa(varargin{1}, 'pole')
0114 p = varargin{1};
0115 else
0116 error('### unknown constructor method for pole class.');
0117 end
0118
0119 elseif nargin == 2
0120
0121 if isa(varargin{1}, 'database')
0122 p = retrieve(varargin{1}, varargin{2:end});
0123
0124 elseif isnumeric(varargin{1}) && isnumeric(varargin{2})
0125
0126 p = init();
0127 if isnan(varargin{2})
0128 p.name = 'real pole';
0129 else
0130 p.name = 'complex pole';
0131 end
0132 p.f = varargin{1};
0133 p.q = varargin{2};
0134 p.ri = pfq2ri(p.f, p.q);
0135
0136 else
0137 error('### unknown constructor method for pole class.');
0138 end
0139
0140 end
0141
0142
0143
0144
0145 function p = poleFromPlist(p, pl)
0146
0147 f = find(pl, 'f');
0148 q = find(pl, 'q');
0149 ri = find(pl, 'ri');
0150
0151 name = find(pl, 'name');
0152 version = find(pl, 'version');
0153 created = find(pl, 'created');
0154
0155 if ~isempty(f)
0156 if ~isempty(q)
0157
0158 if isnan(q)
0159 p.name = 'real pole';
0160 else
0161 p.name = 'complex pole';
0162 end
0163 p.f = f;
0164 p.q = q;
0165 p.ri = pfq2ri(p.f, p.q);
0166
0167 else
0168
0169 p.name = 'real pole';
0170 p.f = f;
0171 p.q = NaN;
0172 p.ri = pfq2ri(p.f);
0173
0174 end
0175 elseif ~isempty(ri)
0176
0177 p.name = 'complex pole';
0178 [p.f, p.q] = pri2fq(ri);
0179 p.ri = [ri conj(ri)];
0180
0181 else
0182 error('### unknown constructor method for pole class.');
0183 end
0184
0185
0186 if ~isempty(name)
0187 p.name = name;
0188 end
0189 if ~isempty(version)
0190 p.version = version;
0191 end
0192 if ~isempty(created)
0193 p.created = created;
0194 end
0195
0196
0197 end
0198
0199 end
0200
0201