comparison m-toolbox/classes/@pzmodel/tomfir.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 % TOMFIR approximates a pole/zero model with an FIR filter.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: TOMFIR approximates a pole/zero model with an FIR filter.
5 % The response of the pzmodel is computed using pzmodel/resp with
6 % the additional input parameter of param('f1', 0). The final
7 % frequency in the response is set automatically from the
8 % pzmodel/resp function if not specified as an input. This upper
9 % frequency is then taken as the Nyquist frequency and the
10 % sample rate of the corresponding fsdata AO is set accordingly.
11 % The function then calls mfir() with the new fsdata AO as input.
12 % The result is an FIR filter designed to have a magnitude response
13 % equal to the magnitude response of the pole/zero model. The filter
14 % has linear phase and the phase of the pzmodel is ignored.
15 %
16 % CALL: f = tomfir(pzm)
17 % f = tomfir(pzm, plist)
18 %
19 % <a href="matlab:utils.helper.displayMethodInfo('pzmodel', 'tomfir')">Parameters Description</a>
20 %
21 % VERSION: $Id: tomfir.m,v 1.18 2011/04/08 08:56:32 hewitson Exp $
22 %
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
25 function varargout = tomfir(varargin)
26
27 %%% Check if this is a call for parameters
28 if utils.helper.isinfocall(varargin{:})
29 varargout{1} = getInfo(varargin{3});
30 return
31 end
32
33 % Check output arguments number
34 if nargout == 0
35 error('### pzmodel/tomfir cannot be used as a modifier. Please give an output variable.');
36 end
37
38 % Collect input variable names
39 in_names = cell(size(varargin));
40 for ii = 1:nargin,in_names{ii} = inputname(ii);end
41
42 % Collect all AOs
43 [pzms, pzm_invars] = utils.helper.collect_objects(varargin(:), 'pzmodel', in_names);
44 pls = utils.helper.collect_objects(varargin(:), 'plist');
45
46 % Store inhists to suppress intermediate history steps
47 inhists = [pzms(:).hist];
48
49 % Get default parameters
50 pl = parse(pls, getDefaultPlist);
51
52 % Decide on a deep copy or a modify
53 pzms = copy(pzms, nargout);
54
55 % check design parameters
56 fs = find(pl, 'fs');
57 f1 = find(pl, 'f1');
58 f2 = find(pl, 'f2');
59 nf = find(pl, 'nf');
60 f2 = fs/2;
61
62 r = resp(pzms, plist('f1', f1, 'f2', f2, 'nf', nf, 'scale', 'lin'));
63
64 % Set fs
65 r.setFs(fs);
66
67 % compute filter
68 for kk = 1:numel(r)
69 % throws a warning if the model has a delay
70 if(pzms(kk).delay~=0)
71 disp('!!! PZmodel delay is not used in the discretization')
72 end
73 % Compute mfir filter
74 f(kk) = mfir(r(kk));
75 f(kk).addHistory(getInfo, pl, pzm_invars(kk), inhists(kk));
76 end
77
78 % Reshape the output to the shape of the input
79 f = reshape(f, size(r));
80
81 % Set output
82 if nargout == numel(f)
83 % List of outputs
84 for ii = 1:numel(f)
85 varargout{ii} = f(ii);
86 end
87 else
88 % Single output
89 varargout{1} = f;
90 end
91
92 end
93
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 % Local Functions %
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 %
100 % FUNCTION: getInfo
101 %
102 % DESCRIPTION: Get Info Object
103 %
104 % HISTORY: 11-07-07 M Hewitson
105 % Creation.
106 %
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109 function ii = getInfo(varargin)
110 if nargin == 1 && strcmpi(varargin{1}, 'None')
111 sets = {};
112 pl = [];
113 else
114 sets = {'Default'};
115 pl = getDefaultPlist;
116 end
117 % Build info object
118 ii = minfo(mfilename, 'pzmodel', 'ltpda', utils.const.categories.op, '$Id: tomfir.m,v 1.18 2011/04/08 08:56:32 hewitson Exp $', sets, pl);
119 ii.setModifier(false);
120 end
121
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 %
124 % FUNCTION: getDefaultPlist
125 %
126 % DESCRIPTION: Get Default Plist
127 %
128 % HISTORY: 11-07-07 M Hewitson
129 % Creation.
130 %
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132
133 function plout = getDefaultPlist()
134 persistent pl;
135 if exist('pl', 'var')==0 || isempty(pl)
136 pl = buildplist();
137 end
138 plout = pl;
139 end
140
141 function plo = buildplist()
142 fs = 10;
143 f2 = fs/2;
144
145 plo = plist();
146
147 % FS
148 p = param({'fs', 'Frequency of the fir filter.'}, paramValue.DOUBLE_VALUE(fs));
149 plo.append(p);
150
151 % F1
152 p = param({'f1','Start frequency.'}, paramValue.DOUBLE_VALUE(0));
153 plo.append(p);
154
155 % F2
156 p = param({'f2','Stop frequency.'}, paramValue.DOUBLE_VALUE(f2));
157 plo.append(p);
158
159 % Nf
160 p = param({'nf','Number of evaluation frequencies.'}, paramValue.DOUBLE_VALUE(1000));
161 plo.append(p);
162
163 % Scale
164 p = param({'scale',['Spacing of frequencies:<ul>', ...
165 '<li>''lin'' - Linear scale.</li>', ...
166 '<li>''log'' - Logarithmic scale.</li></ul>']}, {1, {'lin', 'log'} paramValue.SINGLE});
167 plo.append(p);
168
169 end
170