Mercurial > hg > ltpda
comparison m-toolbox/classes/@miir/redesign.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 % REDESIGN redesign the input filter to work for the given sample rate. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: REDESIGN redesign the input filter to work for the given sample | |
5 % rate. | |
6 % | |
7 % CALL: filt = redesign(filt, fs) | |
8 % filt = redesign(filt, plist-object) | |
9 % | |
10 % INPUT: filt - input (miir) filter | |
11 % fs - new sample rate | |
12 % | |
13 % OUTPUT: filt - new output filter | |
14 % | |
15 % <a href="matlab:utils.helper.displayMethodInfo('miir', 'redesign')">Parameters Description</a> | |
16 % | |
17 % VERSION: $Id: redesign.m,v 1.28 2011/04/08 08:56:33 hewitson Exp $ | |
18 % | |
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
20 | |
21 function varargout = redesign(varargin) | |
22 | |
23 %%% Check if this is a call for parameters | |
24 if utils.helper.isinfocall(varargin{:}) | |
25 varargout{1} = getInfo(varargin{3}); | |
26 return | |
27 end | |
28 | |
29 import utils.const.* | |
30 utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename); | |
31 | |
32 %%% check numer of outputs | |
33 if nargout == 0 | |
34 error('### cat cannot be used as a modifier. Please give an output variable.'); | |
35 end | |
36 | |
37 % Collect input variable names | |
38 in_names = cell(size(varargin)); | |
39 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
40 | |
41 %%% Get miir objects | |
42 [filt, filt_invars, rest] = utils.helper.collect_objects(varargin(:), 'miir', in_names); | |
43 pls = utils.helper.collect_objects(rest(:), 'plist'); | |
44 | |
45 %%% Combine input plists | |
46 pls = combine(pls, plist()); | |
47 | |
48 %%% Get 'fs' from the second input or from the input plist | |
49 if numel(rest) == 1 && isnumeric(rest{1}) | |
50 fs = rest{1}; | |
51 pls.pset('fs', fs); | |
52 elseif pls.nparams == 1 && pls.isparam('fs') | |
53 fs = pls.find('fs'); | |
54 else | |
55 error('### Please specify the new sample rate.'); | |
56 end | |
57 | |
58 %%% Redesing all filters | |
59 for kk = 1:numel(filt) | |
60 utils.helper.msg(msg.OPROC1, 're-designing filter for fs=%2.2f Hz...', fs); | |
61 | |
62 % Get the plistUsed from the constructor block (not from a copy constructor). | |
63 h = filt(kk).hist; | |
64 lc = 1; | |
65 while lc<100 | |
66 if ~strcmp(h.methodInfo.mcategory, utils.const.categories.constructor) | |
67 % Not a constructor block | |
68 else | |
69 % Copy constructor or a 'normal' constructor | |
70 if ~isempty(h.plistUsed) && (h.plistUsed.nparams > 0) | |
71 % Leave the loop if 'plistUsed' is filled -> Not a copy constructor | |
72 break; | |
73 end | |
74 end | |
75 if ~isempty(h.inhists) | |
76 h = h.inhists(1); | |
77 end | |
78 lc = lc + 1; | |
79 end | |
80 % Throw an error if no constructor block is found. | |
81 if ~strcmp(h.methodInfo.mcategory, utils.const.categories.constructor) | |
82 error('### Found no constructor block to get the plistUsed.'); | |
83 end | |
84 | |
85 fpl = h.plistUsed; | |
86 type = find(fpl, 'type'); | |
87 pzm = find(fpl, 'pzmodel'); | |
88 pf = find(fpl, 'parfrac'); | |
89 | |
90 % retain the following properties of the miir object and set them at the end | |
91 % of the method. | |
92 name = filt(kk).name; | |
93 iunits = filt(kk).iunits; | |
94 ounits = filt(kk).ounits; | |
95 hist = filt(kk).hist; | |
96 | |
97 if strcmpi(type, 'highpass') ||... | |
98 strcmpi(type, 'lowpass') ||... | |
99 strcmpi(type, 'bandpass') ||... | |
100 strcmpi(type, 'bandreject') | |
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
102 %%%%%%%%%% From Standard types %%%%%%%%%% | |
103 | |
104 utils.helper.msg(msg.OPROC2, 're-designing standard filter.'); | |
105 try | |
106 fpl = pset(fpl, 'fs', fs); | |
107 utils.helper.msg(msg.OPROC2, 'setting new fs.'); | |
108 catch | |
109 fpl = append(fpl, 'fs', fs); | |
110 utils.helper.msg(msg.OPROC2, 'appending parameter fs.'); | |
111 end | |
112 filt(kk) = miir(fpl); | |
113 | |
114 elseif ~isempty(pzm) | |
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
116 %%%%%%%%%% From pole/zero model %%%%%%%%% | |
117 | |
118 % REMARK: Only the history of ltpda_uoh objects are stroed in a plist and | |
119 % not the object itself. | |
120 % We have to rebuild the object to get the object back. | |
121 if isa(pzm, 'history') | |
122 pzm = rebuild(pzm); | |
123 end | |
124 | |
125 utils.helper.msg(msg.OPROC2, 're-designing pzmodel filter.'); | |
126 fpl = pset(fpl, 'pzmodel', pzm, 'fs', fs); | |
127 filt(kk) = miir(fpl); | |
128 | |
129 elseif ~isempty(pf) | |
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
131 %%%%%%%%%% From partial fraction model %%%%%%%%%% | |
132 | |
133 % REMARK: Only the history of ltpda_uoh objects are stroed in a plist and | |
134 % not the object itself. | |
135 % We have to rebuild the object to get the object back. | |
136 if isa(pf, 'history') | |
137 pf = rebuild(pf); | |
138 end | |
139 | |
140 utils.helper.msg(msg.OPROC2, 're-designing parfrac filter.'); | |
141 fpl = pset(fpl, 'parfrac', pf, 'fs', fs); | |
142 | |
143 out_filt = miir(fpl); | |
144 | |
145 if numel(filt) ~= numel(out_filt) | |
146 error('### Can redesign only one filter from a parfrac object.'); | |
147 end | |
148 | |
149 filt = out_filt; | |
150 | |
151 else | |
152 warning('!!! un-recognised input filter type. Can''t redesign.'); | |
153 continue; | |
154 end | |
155 | |
156 % Set the retained properties | |
157 filt(kk).name = name; | |
158 filt(kk).iunits = iunits; | |
159 filt(kk).ounits = ounits; | |
160 | |
161 % Add history | |
162 | |
163 filt(kk).addHistory(getInfo('None'), pls, filt_invars(kk), hist); | |
164 | |
165 end | |
166 | |
167 %%% Set output. | |
168 varargout{1} = filt; | |
169 | |
170 end | |
171 | |
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
173 % Local Functions % | |
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
175 | |
176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
177 % | |
178 % FUNCTION: getInfo | |
179 % | |
180 % DESCRIPTION: Get Info Object | |
181 % | |
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
183 | |
184 function ii = getInfo(varargin) | |
185 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
186 sets = {}; | |
187 pl = []; | |
188 else | |
189 sets = {'Default'}; | |
190 pl = getDefaultPlist; | |
191 end | |
192 % Build info object | |
193 ii = minfo(mfilename, 'miir', 'ltpda', utils.const.categories.helper, '$Id: redesign.m,v 1.28 2011/04/08 08:56:33 hewitson Exp $', sets, pl); | |
194 ii.setModifier(false); | |
195 end | |
196 | |
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
198 % | |
199 % FUNCTION: getDefaultPlist | |
200 % | |
201 % DESCRIPTION: Get Default Plist | |
202 % | |
203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
204 | |
205 function plout = getDefaultPlist() | |
206 persistent pl; | |
207 if exist('pl', 'var')==0 || isempty(pl) | |
208 pl = buildplist(); | |
209 end | |
210 plout = pl; | |
211 end | |
212 | |
213 function pl = buildplist() | |
214 pl = plist.EMPTY_PLIST; | |
215 end | |
216 |