comparison m-toolbox/classes/@pzmodel/simplify.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 % SIMPLIFY simplifies pzmodels by cancelling like poles with like zeros.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SIMPLIFY simplifies pzmodels by cancelling like poles with
5 % like zeros.
6 %
7 % CALL: pzm = simplify(pzm);
8 %
9 % <a href="matlab:utils.helper.displayMethodInfo('pzmodel', 'simplify')">Parameters Description</a>
10 %
11 % VERSION: $Id: simplify.m,v 1.12 2011/04/08 08:56:33 hewitson Exp $
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 function varargout = simplify(varargin)
16
17 import utils.const.*
18
19 %%% Check if this is a call for parameters
20 if utils.helper.isinfocall(varargin{:})
21 varargout{1} = getInfo(varargin{3});
22 return
23 end
24
25 %%% Input objects checks
26 if nargin < 1
27 error('### incorrect number of inputs.')
28 end
29
30 % Collect input pzmodels, plists and input variable names
31 in_names = cell(size(varargin));
32 for ii = 1:nargin
33 in_names{end+1} = inputname(ii);
34 end
35 [pzms, invars, rest] = utils.helper.collect_objects(varargin(:), 'pzmodel', in_names);
36 pl = utils.helper.collect_objects(varargin(:), 'plist');
37
38 % Combine with default plist
39 pl = combine(pl, getDefaultPlist('Default'));
40
41 % Get tolerance
42 tol = find(pl,'tol');
43
44 % Decide on a deep copy or a modify
45 cpzms = copy(pzms, nargout);
46
47 % Loop over pzmodels and modify the first
48 for pp=1:numel(cpzms)
49
50 % process this pzmodel
51 pzm = cpzms(pp);
52
53 % Loop over the poles and zeros
54 cancelPoles = [];
55 for jj=1:numel(pzm.poles)
56 cancel = false;
57 for kk=1:numel(pzm.zeros)
58 if (abs(real(pzm.poles(jj).ri(1))-real(pzm.zeros(kk).ri(1)))<tol...
59 && abs(imag(pzm.poles(jj).ri(1))-imag(pzm.zeros(kk).ri(1)))<tol)
60 utils.helper.msg(msg.PROC1, ...
61 'cancelling pole %s and zero %s', ...
62 char(pzm.poles(jj)), char(pzm.zeros(kk)));
63 cancel = true;
64 break;
65 end
66 end
67 if cancel
68 cancelPoles = [cancelPoles jj];
69 pzm.zeros(kk) = [];
70 end
71 end
72 pzm.poles(cancelPoles) = [];
73
74 % Add history
75 pzm.addHistory(getInfo('None'), pl, invars, pzm.hist);
76 % Set name
77 pzm.setName(sprintf('simplify(%s)', pzm.name));
78 end
79
80 % Outputs
81 varargout{1} = cpzms;
82
83 end
84
85
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 % Local Functions %
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 %
92 % FUNCTION: getInfo
93 %
94 % DESCRIPTION: Get Info Object
95 %
96 % HISTORY: 11-07-07 M Hewitson
97 % Creation.
98 %
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100
101 function ii = getInfo(varargin)
102 if nargin == 1 && strcmpi(varargin{1}, 'None')
103 sets = {};
104 pls = [];
105 elseif nargin == 1&& ~isempty(varargin{1}) && ischar(varargin{1})
106 sets{1} = varargin{1};
107 pls = getDefaultPlist(sets{1});
108 else
109 sets = {'Default'};
110 pls = [];
111 for kk=1:numel(sets)
112 pls = [pls getDefaultPlist(sets{kk})];
113 end
114 end
115 % Build info object
116 ii = minfo(mfilename, 'pzmodel', 'ltpda', utils.const.categories.sigproc, '$Id: simplify.m,v 1.12 2011/04/08 08:56:33 hewitson Exp $', sets, pls);
117 ii.setModifier(false);
118 end
119
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 %
122 % FUNCTION: getDefaultPlist
123 %
124 % DESCRIPTION: Get Default Plist
125 %
126 % HISTORY: 11-07-07 M Hewitson
127 % Creation.
128 %
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130
131 function plout = getDefaultPlist(set)
132 persistent pl;
133 persistent lastset;
134 if exist('pl', 'var')==0 || isempty(pl) || ~strcmp(lastset, set)
135 pl = buildplist(set);
136 lastset = set;
137 end
138 plout = pl;
139 end
140
141 function pl = buildplist(set)
142
143 pl = plist();
144
145 switch lower(set)
146 case 'default'
147 p = param({'tol', 'The tolerance for deciding if two poles/zeros are the same.'}, paramValue.DOUBLE_VALUE(1e-10));
148 pl.append(p);
149
150 otherwise
151 error('### Unknown set [%s]', set);
152 end
153 end
154