Mercurial > hg > ltpda
comparison m-toolbox/classes/@pz/pz.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % PZ is the ltpda class that provides a common definition of poles and zeros. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: PZ is the ltpda class that provides a common definition of | |
5 % poles and zeros. | |
6 % | |
7 % SUPERCLASSES: ltpda_nuo < ltpda_obj | |
8 % | |
9 % CONSTRUCTORS: | |
10 % | |
11 % p = pz(f) % specify frequency | |
12 % p = pz(f,q) % specify frequency and Q | |
13 % p = pz(c) % create with complex representation | |
14 % p = pz({[f,q]}) | |
15 % p = pz({[f1,q1], f2, [f3, q3]}) -> creates three objects | |
16 % | |
17 % VERSION: $Id: pz.m,v 1.48 2011/11/02 06:41:17 hewitson Exp $ | |
18 % | |
19 % SEE ALSO: ltpda_obj, ltpda_nuo, pzmodel | |
20 % | |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22 | |
23 classdef (Hidden = true) pz < ltpda_nuo | |
24 | |
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
26 % Property definition % | |
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
28 | |
29 %---------- Public (read/write) Properties ---------- | |
30 properties | |
31 end | |
32 | |
33 %---------- Protected read-only Properties ---------- | |
34 properties (SetAccess = protected) | |
35 f = NaN; % frequency of pole/zero | |
36 q = NaN; % quality factor of pole/zero | |
37 ri = NaN; % complex representation of pole/zero | |
38 end | |
39 | |
40 %---------- Private Properties ---------- | |
41 properties (GetAccess = protected, SetAccess = protected) | |
42 end | |
43 | |
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
45 % Check property setting % | |
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
47 | |
48 methods | |
49 function set.f(obj, val) | |
50 if ~isnumeric(val) || isempty(val) || ~isreal(val) | |
51 error('### The value for the property ''f'' must be a real positive number'); | |
52 end | |
53 obj.f = val; | |
54 end | |
55 function set.q(obj, val) | |
56 if ~isnumeric(val) || isempty(val) || ~isreal(val) | |
57 error('### The value for the property ''q'' must be a real positive number'); | |
58 end | |
59 obj.q = val; | |
60 end | |
61 function set.ri(obj, val) | |
62 if ~isnumeric(val) || isempty(val) | |
63 error('### The value for the property ''ri'' must be a number'); | |
64 end | |
65 % Have 'ri' always as a column vector | |
66 if size(val,2) ~= 1 | |
67 val = val.'; | |
68 end | |
69 obj.ri = val; | |
70 end | |
71 end | |
72 | |
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
74 % Constructor % | |
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
76 | |
77 methods | |
78 function obj = pz(varargin) | |
79 | |
80 switch nargin | |
81 case 0 | |
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
83 %%%%%%%%%%%%%%%%%%%%%%%%%%% no inputs %%%%%%%%%%%%%%%%%%%%%%%%%%% | |
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
85 | |
86 case 1 | |
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
88 %%%%%%%%%%%%%%%%%%%%%%%%%%% one input %%%%%%%%%%%%%%%%%%%%%%%%%%% | |
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
90 | |
91 if isa(varargin{1}, 'pz') | |
92 %%%%%%%%%% Copy ltpda_obj Object %%%%%%%%%% | |
93 %%%%%%%%%% p1 = pz(pz-object) %%%%%%%%%% | |
94 obj = copy(varargin{1}, 1); | |
95 | |
96 elseif isnumeric(varargin{1}) | |
97 %%%%%%%%%% real or complex pole/zero %%%%%%%%%% | |
98 if isempty(varargin{1}) | |
99 % do nothing | |
100 elseif length(varargin{1}) == 1 | |
101 if isreal(varargin{1}) | |
102 %%%%%%%%%% p1 = pz(3) %%%%%%%%%% | |
103 obj.setF(varargin{1}); | |
104 obj.setQ(NaN); | |
105 else | |
106 %%%%%%%%%% p1 = pz(1+3i) %%%%%%%%%% | |
107 obj.setRI(varargin{1}); | |
108 if (obj.q - 0.5) < 1e-10 | |
109 % if complex vale is Q = 0.5 return two equal real poles | |
110 disp('!!! Q = 0.5! Returning two equal real poles/zeros;') | |
111 obj.setQ(NaN); | |
112 obj = [obj obj]; | |
113 end | |
114 end | |
115 elseif length(varargin{1}) == 2 | |
116 %%%%%%%%%% p1 = pz([1 2]) %%%%%%%%%% | |
117 Q = varargin{1}(2); | |
118 if (Q>0.5) | |
119 obj.setF(varargin{1}(1)); | |
120 obj.setQ(varargin{1}(2)); | |
121 elseif (Q<=0.5 && Q>=0) | |
122 % interpret as 2 real poles | |
123 ffs = pz.fq2ri(varargin{1}(1), varargin{1}(2)); | |
124 obj = [pz(ffs(1)/2/pi) pz(ffs(2)/2/pi)]; | |
125 else | |
126 error('### Q must be a positive value'); | |
127 end | |
128 | |
129 else | |
130 error('### Unknown constructor for the input %s', mat2str(varargin{1})); | |
131 end | |
132 | |
133 elseif isa(varargin{1}, 'plist') | |
134 %%%%%%%%%% p1 = pz(plist-object) %%%%%%%%%% | |
135 pl = varargin{1}; | |
136 pl_f = find(pl, 'f'); | |
137 pl_q = find(pl, 'q'); | |
138 pl_ri = find(pl, 'ri'); | |
139 if ~isempty(pl_f) | |
140 obj.setF(pl_f); | |
141 if ~isempty(pl_q) | |
142 obj.setQ(pl_q); | |
143 end | |
144 elseif ~isempty(pl_ri) | |
145 obj.setRI(pl_ri); | |
146 else | |
147 error('### Unknown plist constructor'); | |
148 end | |
149 | |
150 elseif isstruct(varargin{1}) | |
151 %%%%%%%%%% p1 = pz(structure) %%%%%%%%%% | |
152 obj = fromStruct(obj, varargin{1}); | |
153 | |
154 elseif iscell(varargin{1}) | |
155 %%%%%%%%%% p1 = pz({[1 2], 1+2i, 3}) %%%%%%%%%% | |
156 if isempty(varargin{1}) | |
157 return | |
158 end | |
159 | |
160 obj = pz.initObjectWithSize(size(varargin{1})); | |
161 for kk = 1:numel(varargin{1}) | |
162 obj = [obj pz(varargin{1}{kk})]; | |
163 end | |
164 | |
165 elseif ischar(varargin{1}) | |
166 %%%%%%%%%% p1 = pz('{[1 2], 1+2i, 3}') %%%%%%%%%% | |
167 obj = feval('pz', eval(varargin{1})); | |
168 | |
169 else | |
170 error('### Unknown call of the pz constructor.'); | |
171 end | |
172 | |
173 case 2 | |
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
175 %%%%%%%%%%%%%%%%%%%%%%%%%%% two inputs %%%%%%%%%%%%%%%%%%%%%%%%%% | |
176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
177 | |
178 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') && ... | |
179 isa(varargin{2}, 'history') | |
180 %%%%%%%%%% obj = pz(DOM node, history-objects) %%%%%%%%%% | |
181 obj = fromDom(obj, varargin{1}, varargin{2}); | |
182 | |
183 else | |
184 %%%%%%%%%% obj = pz(f, q) %%%%%%%%%% | |
185 % f,q constructor | |
186 obj.setF(varargin{1}); | |
187 obj.setQ(varargin{2}); | |
188 end | |
189 otherwise | |
190 error('### Unknown number of arguments.'); | |
191 end | |
192 | |
193 end | |
194 | |
195 end | |
196 | |
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
198 % Methods (public) % | |
199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
200 | |
201 methods | |
202 varargout = cp2iir(varargin) | |
203 varargout = cz2iir(varargin) | |
204 varargout = rz2iir(varargin) | |
205 varargout = rp2iir(varargin) | |
206 varargout = copy(varargin) | |
207 varargout = string(varargin) | |
208 [f,r] = resp(varargin) | |
209 end | |
210 | |
211 methods (Hidden = true) | |
212 varargout = attachToDom(varargin) | |
213 end | |
214 | |
215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
216 % Methods (protected) % | |
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
218 | |
219 methods (Access = protected) | |
220 ii = setF(ii, val) | |
221 ii = setQ(ii, val) | |
222 ii = setRI(ii, val) | |
223 | |
224 varargout = fromStruct(varargin) | |
225 varargout = fromDom(varargin) | |
226 end | |
227 | |
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
229 % Methods (private) % | |
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
231 | |
232 methods (Access = private) | |
233 end | |
234 | |
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
236 % Methods (static, protected) % | |
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
238 | |
239 methods (Access = protected, Static) | |
240 [f0, q] = ri2fq(c); | |
241 ri = fq2ri(f0, Q); | |
242 end | |
243 | |
244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
245 % Methods (Static, Private) % | |
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
247 | |
248 methods (Static = true, Access = private) | |
249 end | |
250 | |
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
252 % Methods (static) % | |
253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
254 | |
255 methods (Static) | |
256 | |
257 function out = VEROUT() | |
258 out = '$Id: pz.m,v 1.48 2011/11/02 06:41:17 hewitson Exp $'; | |
259 end | |
260 | |
261 function ii = getInfo(varargin) | |
262 ii = utils.helper.generic_getInfo(varargin{:}, 'pz'); | |
263 end | |
264 | |
265 function out = SETS() | |
266 out = {'Default'}; | |
267 end | |
268 | |
269 function out = getDefaultPlist(set) | |
270 switch lower(set) | |
271 case 'default' | |
272 out = plist(); | |
273 otherwise | |
274 error('### Unknown set [%s]', set); | |
275 end | |
276 end | |
277 | |
278 function obj = initObjectWithSize(n,m) | |
279 if numel(n) > 1 | |
280 obj = pz.newarray([n(1) n(2)]); | |
281 else | |
282 obj = pz.newarray([n m]); | |
283 end | |
284 end | |
285 | |
286 end | |
287 | |
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
289 % Methods (static, hidden) % | |
290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
291 | |
292 methods (Static = true, Hidden = true) | |
293 varargout = loadobj(varargin) | |
294 varargout = update_struct(varargin); | |
295 end | |
296 | |
297 end % End classdef |