comparison m-toolbox/classes/@mfir/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 (mfir) filter
11 % fs - new sample rate
12 %
13 % OUTPUT: filt - new output filter
14 %
15 % <a href="matlab:utils.helper.displayMethodInfo('mfir', 'redesign')">Parameters Description</a>
16 %
17 % VERSION: $Id: redesign.m,v 1.21 2011/04/08 08:56:20 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 [filt, filt_invars, rest] = utils.helper.collect_objects(varargin(:), 'mfir', in_names);
42 pls = utils.helper.collect_objects(rest(:), 'plist');
43
44 %%% Combine input plists
45 pls = combine(pls, getDefaultPlist());
46
47 %%% Get 'fs' from the second input or from the input plist
48 if numel(rest) == 1 && isnumeric(rest{1})
49 fs = rest{1};
50 pls.pset('fs', fs);
51 elseif pls.nparams == 1 && pls.isparam('fs')
52 fs = pls.find('fs');
53 else
54 error('### Please specify the new sample rate.');
55 end
56
57 %%% Redesing all filters
58 for kk = 1:numel(filt)
59 utils.helper.msg(msg.OPROC1, 're-designing filter for fs=%2.2f Hz...', fs);
60
61 % Get the plistUsed from the constructor block (not from a copy constructor).
62 h = filt(kk).hist;
63 lc = 1;
64 while lc<100
65 if ~strcmp(h.methodInfo.mcategory, utils.const.categories.constructor)
66 % Not a constructor block
67 else
68 % Copy constructor or a 'normal' constructor
69 if ~isempty(h.plistUsed) && (h.plistUsed.nparams > 0)
70 % Leave the loop if 'plistUsed' is filled -> Not a copy constructor
71 break;
72 end
73 end
74 if ~isempty(h.inhists)
75 h = h.inhists(1);
76 end
77 lc = lc + 1;
78 end
79 % Throw an error if no constructor block is found.
80 if ~strcmp(h.methodInfo.mcategory, utils.const.categories.constructor)
81 error('### Found no constructor block to get the plistUsed.');
82 end
83
84 fpl = h.plistUsed;
85 type = find(fpl, 'type');
86 pzm = find(fpl, 'pzmodel');
87
88 % retain the following properties of the miir object and set them at the end
89 % of the method.
90 name = filt(kk).name;
91 iunits = filt(kk).iunits;
92 ounits = filt(kk).ounits;
93 hist = filt(kk).hist;
94
95 if strcmpi(type, 'highpass') ||...
96 strcmpi(type, 'lowpass') ||...
97 strcmpi(type, 'bandpass') ||...
98 strcmpi(type, 'bandreject')
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 %%%%%%%%%% From Standard types %%%%%%%%%%
101
102 utils.helper.msg(msg.OPROC2, 're-designing standard filter.');
103 try
104 fpl = pset(fpl, 'fs', fs);
105 utils.helper.msg(msg.OPROC2, 'setting new fs.');
106 catch
107 fpl = append(fpl, 'fs', fs);
108 utils.helper.msg(msg.OPROC2, 'appending parameter fs.');
109 end
110 filt(kk) = mfir(fpl);
111
112 elseif ~isempty(pzm)
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 %%%%%%%%%% From pole/zero model %%%%%%%%%
115
116 % REMARK: Only the history of ltpda_uoh objects are stroed in a plist and
117 % not the object itself.
118 % We have to rebuild the object to get the object back.
119 if isa(pzm, 'history')
120 pzm = rebuild(pzm);
121 end
122 utils.helper.msg(msg.OPROC2, 're-designing pzmodel filter.');
123 filt(kk) = mfir(plist([param('pzmodel', pzm) param('fs', fs)]));
124
125 else
126 warning('!!! un-recognised input filter type. Can''t redesign.');
127 continue;
128 end
129
130 % Set the retained properties
131 filt(kk).name = name;
132 filt(kk).iunits = iunits;
133 filt(kk).ounits = ounits;
134
135 % Add history
136 filt(kk).addHistory(getInfo('None'), pls, filt_invars(kk), hist);
137
138 end
139
140 %%% Set output.
141 varargout{1} = filt;
142 end
143
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 % Local Functions %
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147
148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 %
150 % FUNCTION: getInfo
151 %
152 % DESCRIPTION: Get Info Object
153 %
154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155
156 function ii = getInfo(varargin)
157 if nargin == 1 && strcmpi(varargin{1}, 'None')
158 sets = {};
159 pl = [];
160 else
161 sets = {'Default'};
162 pl = getDefaultPlist;
163 end
164 % Build info object
165 ii = minfo(mfilename, 'mfir', 'ltpda', utils.const.categories.helper, '$Id: redesign.m,v 1.21 2011/04/08 08:56:20 hewitson Exp $', sets, pl);
166 ii.setModifier(false);
167 end
168
169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 %
171 % FUNCTION: getDefaultPlist
172 %
173 % DESCRIPTION: Get Default Plist
174 %
175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176
177 function plout = getDefaultPlist()
178 persistent pl;
179 if exist('pl', 'var')==0 || isempty(pl)
180 pl = buildplist();
181 end
182 plout = pl;
183 end
184
185 function pl = buildplist()
186 pl = plist.EMPTY_PLIST;
187 end
188