comparison m-toolbox/html_help/help/ug/constructor_examples_mfir_content.html @ 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 <!-- $Id: constructor_examples_mfir_content.html,v 1.4 2009/02/27 16:51:57 ingo Exp $ -->
2
3 <!-- -------------------------------------------------- -->
4 <!-- --------------- BEGIN CONTENT FILE --------------- -->
5 <!-- -------------------------------------------------- -->
6
7 <!-- --------------- Link box: begin --------------- -->
8 <table border="0" summary="Simple list" class="simplelist_nottable_last">
9 <tr>
10 <td>
11 <a href="constructor_examples_mfir.html#copy">Copy an MFIR object</a>
12 </td>
13 </tr>
14 <tr>
15 <td>
16 <a href="constructor_examples_mfir.html#xml_file">Construct a MFIR object by loading the object from a file</a>
17 </td>
18 </tr>
19 <tr>
20 <td>
21 <a href="constructor_examples_mfir.html#ao">Construct a MFIR object from an Analysis Object <tt>(AO)</tt></a>
22 </td>
23 </tr>
24 <tr>
25 <td>
26 <a href="constructor_examples_rational.html#pzmodel">Construct a MFIR object from a pole/zero model <tt>(PZMODEL)</tt></a>
27 </td>
28 </tr>
29 <tr>
30 <td>
31 <a href="constructor_examples_mfir.html#std_type">Construct a MFIR object from a standard type</a>
32 </td>
33 </tr>
34 <tr>
35 <td>
36 <a href="constructor_examples_mfir.html#exist_model">Construct a MFIR object from an existing filter model</a>
37 </td>
38 </tr>
39 <tr>
40 <td>
41 <a href="constructor_examples_mfir.html#equation">Construct a MFIR object from a difference equation</a>
42 </td>
43 </tr>
44 </table>
45 <!-- --------------- Link box: end --------------- -->
46
47 <!-- --------------- NEXT EXAMPLE --------------- -->
48
49 <hr>
50 <h2 class="title"><a name="copy"></a>Copy an FIR filter object</h2>
51 <p>The following example creates a copy of an FIR filter object (blue command).</p>
52 <div class="fragment"><pre class="programlisting">
53 >> fir1 = mfir(plist(<span class="string">'type'</span>, <span class="string">'lowpass'</span>));
54 <span class="blue">>> fir2 = mfir(fir2)</span>
55 ------ mfir/1 -------
56 gd: 32.5
57 version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp
58 ntaps: 65
59 fs: 1
60 infile:
61 a: [0.0007 0.0004 -6.9093e-19 -0.0006 -0.0012 -0.0014 -0.0011 1.4147e-18 ...
62 histout: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
63 iunits: [] [1x1 unit]
64 ounits: [] [1x1 unit]
65 hist: mfir.hist [1x1 history]
66 name: lowpass
67 ---------------------
68 </pre></div>
69 <br></br>
70 <p>REMARK: The following command copies only the handle of an object and doesn't create a copy of the object (as above). This means that everything that happens to the copy or original happens to the other object.</p>
71 <div class="fragment"><pre class="programlisting">
72 >> fir1 = mfir()
73 ------ mfir/1 -------
74 gd: []
75 version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp
76 ntaps: 0
77 fs: []
78 infile:
79 a: []
80 histout: []
81 iunits: [] [1x1 unit]
82 ounits: [] [1x1 unit]
83 hist: mfir.hist [1x1 history]
84 name: none
85 ---------------------
86 >> fir2 = fir1;
87 >> fir2.setName(<span class="string">'my new name'</span>)
88 ------ mfir/1 -------
89 gd: []
90 version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp
91 ntaps: 0
92 fs: []
93 infile:
94 a: []
95 histout: []
96 iunits: [] [1x1 unit]
97 ounits: [] [1x1 unit]
98 hist: mfir.hist [1x1 history]
99 name: <span class="string">my new name</span>
100 ---------------------
101 </pre></div>
102 <br></br>
103 <p>If we display fir1 again then we see that the property 'name' was changed although we only have changed fir2.</p>
104 <div class="fragment"><pre class="programlisting">
105 >> fir1
106 ------ mfir/1 -------
107 gd: []
108 version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp
109 ntaps: 0
110 fs: []
111 infile:
112 a: []
113 histout: []
114 iunits: [] [1x1 unit]
115 ounits: [] [1x1 unit]
116 hist: mfir.hist [1x1 history]
117 name: <span class="string">my new name</span>
118 ---------------------</pre></div>
119
120
121 <!-- --------------- NEXT EXAMPLE --------------- -->
122
123 <hr>
124 <h2 class="title"><a name="xml_file"></a>Construct a MFIR object by loading the object from a file</h2>
125 <p>The following example creates a new mfir object by loading the mfir object from disk.</p>
126 <div class="fragment"><pre class="programlisting">
127 fir = mfir(<span class="string">'fir.mat'</span>)
128 fir = mfir(<span class="string">'fir.xml'</span>)
129 </pre></div>
130 <p>or in a <tt>PLIST</tt></p>
131 <div class="fragment"><pre class="programlisting">
132 pl = plist(<span class="string">'filename'</span>, <span class="string">'fir.xml'</span>);
133 fir = mfir(pl)
134 </pre></div>
135
136 <!-- --------------- NEXT EXAMPLE --------------- -->
137
138 <hr>
139 <h2 class="title"><a name="ao"></a>Construct a MFIR object from an Analysis Object</h2>
140 <p> An FIR filter object can be generated based on the magnitude of the input AO/fsdata object.
141 In the following example an AO/fsdata object is first generated and then passed to the mfir constructor
142 to obtain the equivalent FIR filter.</p>
143 <div class="fragment"><pre class="programlisting">
144 a1 = ao(plist(<span class="string">'fsfcn'</span>, <span class="string">'1./(50+f)'</span>, <span class="string">'fs'</span>, 1000, <span class="string">'f'</span>, linspace(0, 500, 1000)));
145 fir = mfir(a1);
146 iplot(a1, resp(fir));
147 </pre></div>
148 <p>or in a PLIST with the relevant parameters:</p>
149 <p>
150 <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%">
151 <colgroup>
152 <col width="25%"/>
153 <col width="75%"/>
154 </colgroup>
155 <thead>
156 <tr valign="top">
157 <th class="subcategorylist">Key</th>
158 <th class="subcategorylist">Description</th>
159 </tr>
160 </thead>
161 <tbody>
162 <tr valign="top">
163 <td>
164 <p>'method'</p>
165 </td>
166 <td>
167 <p>the design method:<br></br>
168 'frequency-sampling' - uses fir2()<br></br>
169 'least-squares' - uses firls()<br></br>
170 'Parks-McClellan' - uses firpm()<br></br>
171 [default: 'frequency-sampling']</p>
172 </td>
173 </tr>
174 <tr valign="top">
175 <td>
176 <p>'win'</p>
177 </td>
178 <td>
179 <p>Window function for frequency-sampling method [default: 'Hanning']</p>
180 </td>
181 </tr>
182 <tr valign="top">
183 <td>
184 <p>'N'</p>
185 </td>
186 <td>
187 <p>Filter order [default: 512]</p>
188 </td>
189 </tr>
190 </tbody>
191 </table>
192 </p>
193 <p>The following example creates a mfir object from an analysis object.</p>
194 <div class="fragment"><pre class="programlisting">
195 a1 = ao(plist(<span class="string">'fsfcn'</span>, <span class="string">'1./(50+f)'</span>, <span class="string">'fs'</span>, 1000, <span class="string">'f'</span>, linspace(0, 500, 1000)));
196 pl = plist(<span class="string">'ao'</span>, a1);
197 fir = mfir(pl)
198 </pre></div>
199
200
201 <!-- --------------- NEXT EXAMPLE --------------- -->
202
203 <hr>
204 <h2 class="title"><a name="pzmodel"></a>Construct an FIR filter object from a pole/zero model</h2>
205 <p>The following example creates a new FIR filter object from a pole/zero model.</p>
206 <div class="fragment"><pre class="programlisting">
207 >> pzm = pzmodel(1, {1 2 3}, {4 5}, <span class="string">'my pzmodel'</span>)
208 ---- pzmodel 1 ----
209 name: my pzmodel
210 gain: 1
211 delay: 0
212 iunits: []
213 ounits: []
214 pole 001: (f=1 Hz,Q=NaN)
215 pole 002: (f=2 Hz,Q=NaN)
216 pole 003: (f=3 Hz,Q=NaN)
217 zero 001: (f=4 Hz,Q=NaN)
218 zero 002: (f=5 Hz,Q=NaN)
219 -------------------
220 >> fir = mfir(pzm) <span class="comment">% Use the default sample rate fs=8 * frequency of the highest pole or zero in the model</span>
221 >> fir = mfir(pzm, plist(<span class="string">'fs'</span>, 100))
222 ------ mfir/1 -------
223 gd: 257
224 version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp
225 ntaps: 513
226 fs: 100
227 infile:
228 a: [-0 -3.013e-10 -1.2486e-09 -2.8506e-09 -5.1166e-09 -7.8604e-09 -1.1133e-08 ...
229 histout: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
230 iunits: [] [1x1 unit]
231 ounits: [] [1x1 unit]
232 hist: mfir.hist [1x1 history]
233 name: my pzmodel
234 ---------------------
235 </pre></div>
236 <p>or in a PLIST with the relevant parameters:</p>
237 <p>
238 <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%">
239 <colgroup>
240 <col width="25%"/>
241 <col width="75%"/>
242 </colgroup>
243 <thead>
244 <tr valign="top">
245 <th class="subcategorylist">Key</th>
246 <th class="subcategorylist">Description</th>
247 </tr>
248 </thead>
249 <tbody>
250 <tr valign="top">
251 <td>
252 <p>'pzmodel'</p>
253 </td>
254 <td>
255 <p>A pzmodel object to construct the filter from [default: empty pzmodel]</p>
256 </td>
257 </tr>
258 <tr valign="top">
259 <td>
260 <p>'fs'</p>
261 </td>
262 <td>
263 <p>Sample rate [default: 8 * frequency of the highest pole or zero in the model]</p>
264 </td>
265 </tr>
266 </tbody>
267 </table>
268 </p>
269 <div class="fragment"><pre class="programlisting">
270 >> pzm = pzmodel(1, {1 2 3}, {4 5}, <span class="string">'my pzmodel'</span>)
271 >> pl = plist(<span class="string">'pzmodel'</span>, pzm, <span class="string">'fs'</span>, 100)
272 >> fir = mfir(pl)
273 </pre></div>
274
275
276 <!-- --------------- NEXT EXAMPLE --------------- -->
277
278 <hr></hr>
279 <h2 class="title"><a name="std_type"></a>Construct a MFIR object from a standard type</h2>
280 <p>Construct an FIR filter object from a standard type: 'lowpass', 'highpass', 'bandpass' or 'bandreject'</p>
281 <p>The relevant parameters are:</p>
282 <p>
283 <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%">
284 <colgroup>
285 <col width="25%"/>
286 <col width="75%"/>
287 </colgroup>
288 <thead>
289 <tr valign="top">
290 <th class="subcategorylist">Key</th>
291 <th class="subcategorylist">Description</th>
292 </tr>
293 </thead>
294 <tbody>
295 <tr valign="top">
296 <td>
297 <p>'type'</p>
298 </td>
299 <td>
300 <p>one of the types: 'highpass', 'lowpass', 'bandpass', 'bandreject'<br></br>
301 [default 'lowpass']</p>
302 </td>
303 </tr>
304 </tbody>
305 </table>
306 </p>
307 <p>You can also specify optional parameters:</p>
308 <p>
309 <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%">
310 <colgroup>
311 <col width="25%"/>
312 <col width="75%"/>
313 </colgroup>
314 <thead>
315 <tr valign="top">
316 <th class="subcategorylist">Key</th>
317 <th class="subcategorylist">Description</th>
318 </tr>
319 </thead>
320 <tbody>
321 <tr valign="top">
322 <td>
323 <p>'gain'</p>
324 </td>
325 <td>
326 <p>The gain of the filter [default: 1]</p>
327 </td>
328 </tr>
329 <tr valign="top">
330 <td>
331 <p>'fc'</p>
332 </td>
333 <td>
334 <p>The roll-off frequency [default: 0.1 Hz]</p>
335 </td>
336 </tr>
337 <tr valign="top">
338 <td>
339 <p>'fs'</p>
340 </td>
341 <td>
342 <p>The sampling frequency to design for [default: 1 Hz]</p>
343 </td>
344 </tr>
345 <tr valign="top">
346 <td>
347 <p>'order'</p>
348 </td>
349 <td>
350 <p>The filter order [default: 64]</p>
351 </td>
352 </tr>
353 <tr valign="top">
354 <td>
355 <p>'win'</p>
356 </td>
357 <td>
358 <p>Specify window function used in filter design [default: 'Hamming']</p>
359 </td>
360 </tr>
361 <tr valign="top">
362 <td>
363 <p>'iunits'</p>
364 </td>
365 <td>
366 <p>the input unit of the filter</p>
367 </td>
368 </tr>
369 <tr valign="top">
370 <td>
371 <p>'ounits'</p>
372 </td>
373 <td>
374 <p>the output unit of the filter</p>
375 </td>
376 </tr>
377 </tbody>
378 </table>
379 </p>
380 <p>The following example creates an order 64 highpass filter with high frequency gain 2. Filter is designed for 1 Hz sampled data and has a cut-off frequency of 0.2 Hz.</p>
381 <div class="fragment"><pre class="programlisting">
382 pl = plist(<span class="string">'type'</span>, <span class="string">'highpass'</span>, ...
383 <span class="string">'order'</span>, 64, ...
384 <span class="string">'gain'</span>, 2.0, ...
385 <span class="string">'fs'</span>, 1, ...
386 <span class="string">'fc'</span>, 0.2);
387 f = mfir(pl)
388 </pre></div>
389 <p>Furthermore it is possible to specify a spectral window.</p>
390 <div class="fragment"><pre class="programlisting">
391 win = specwin(<span class="string">'Kaiser'</span>, 11, 150);
392 pl = plist(<span class="string">'type'</span>, <span class="string">'lowpass'</span>, ...
393 <span class="string">'Win'</span>, win, ...
394 <span class="string">'fs'</span>, 100, ...
395 <span class="string">'fc'</span>, 20, ...
396 <span class="string">'order'</span>, 10);
397 f = mfir(pl)
398 </pre></div>
399
400 <!-- --------------- NEXT EXAMPLE --------------- -->
401
402 <hr>
403 <h2 class="title"><a name="exist_model"></a>Construct a MFIR object from an existing filter</h2>
404 <p>The mfir constructor also accepts as an input existing filters stored in different formats:</p>
405 <p>LISO files</p>
406 <div class="fragment"><pre class="programlisting">
407 f = mfir(<span class="string">'foo_fir.fil'</span>)
408 </pre></div>
409 <p>XML files</p>
410 <div class="fragment"><pre class="programlisting">
411 f = mfir(<span class="string">'foo_fir.xml'</span>)
412 </pre></div>
413 <p>MAT files</p>
414 <div class="fragment"><pre class="programlisting">
415 f = mfir(<span class="string">'foo_fir.mat'</span>)
416 </pre></div>
417 <p>From an LTPDA repository</p>
418 <p>The relevant parameters for retrieving a FIR filter from a LTPDA repository are:</p>
419 <p>
420 <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%">
421 <colgroup>
422 <col width="25%"/>
423 <col width="75%"/>
424 </colgroup>
425 <thead>
426 <tr valign="top">
427 <th class="subcategorylist">Key</th>
428 <th class="subcategorylist">Description</th>
429 </tr>
430 </thead>
431 <tbody>
432 <tr valign="top">
433 <td>
434 <p>'hostname'</p>
435 </td>
436 <td>
437 <p>the repository hostname. [default: 'localhost']</p>
438 </td>
439 </tr>
440 <tr valign="top">
441 <td>
442 <p>'database'</p>
443 </td>
444 <td>
445 <p>The database name [default: 'ltpda']</p>
446 </td>
447 </tr>
448 <tr valign="top">
449 <td>
450 <p>'id'</p>
451 </td>
452 <td>
453 <p>A vector of object IDs. [default: []]</p>
454 </td>
455 </tr>
456 <tr valign="top">
457 <td>
458 <p>'cid'</p>
459 </td>
460 <td>
461 <p>Retrieve all rational objects from a particular collection</p>
462 </td>
463 </tr>
464 <tr valign="top">
465 <td>
466 <p>'binary'</p>
467 </td>
468 <td>
469 <p>Set to 'yes' to retrieve from stored binary representation (not always available). [default: yes]</p>
470 </td>
471 </tr>
472 </tbody>
473 </table>
474 </p>
475 <div class="fragment"><pre class="programlisting">
476 f = mfir(plist(<span class="string">'hostname'</span>, <span class="string">'localhost'</span>, <span class="string">'database'</span>, <span class="string">'ltpda'</span>, <span class="string">'ID'</span>, []))
477 </pre></div>
478
479
480 <!-- --------------- NEXT EXAMPLE --------------- -->
481
482 <hr>
483 <h2 class="title"><a name="equation"></a>Construct a MFIR object from a difference equation</h2>
484 <p>The filter can be defined in terms of two vectors specifying the coefficients of the filter and the sampling frequency. The following example creates a FIR filter with sampling frequency 1 Hz and the following recursive equation:</p>
485 <div align="center">
486 <IMG src="images/sigproc_10.png" width="202" height="28" align="middle" border="0">
487 </div>
488 <div class="fragment"><pre class="programlisting">
489 a = [-0.8 10];
490 fs = 1;
491
492 f = mfir(a,fs)
493 </pre></div>
494 <p>or in a <tt>PLIST</tt></p>
495 <p>The relevant parameters are:</p>
496 <p>
497 <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%">
498 <colgroup>
499 <col width="25%"/>
500 <col width="75%"/>
501 </colgroup>
502 <thead>
503 <tr valign="top">
504 <th class="subcategorylist">Key</th>
505 <th class="subcategorylist">Description</th>
506 </tr>
507 </thead>
508 <tbody>
509 <tr valign="top">
510 <td>
511 <p>'a'</p>
512 </td>
513 <td>
514 <p>vector of A coefficients. (see note ** below) [default: empty]</p>
515 </td>
516 </tr>
517 <tr valign="top">
518 <td>
519 <p>'fs'</p>
520 </td>
521 <td>
522 <p>sampling frequency of the filter [default: empty]</p>
523 </td>
524 </tr>
525 <tr valign="top">
526 <td>
527 <p>'name'</p>
528 </td>
529 <td>
530 <p>name of filter [default: 'None']</p>
531 </td>
532 </tr>
533 </tbody>
534 </table>
535 </p>
536 <div class="fragment"><pre class="programlisting">
537 a = [-0.8 10];
538 fs = 1;
539 pl = plist(<span class="string">'a'</span>, a, <span class="string">'fs'</span>, fs);
540
541 fir = mfir(pl)
542 </pre></div>
543 <br></br>
544 <div class="fragment">
545 NOTES:<br></br>
546 ** The convention used here for naming the filter coefficients is the opposite to MATLAB's convention. The recursion formula for this convention is<br></br>
547 y(n) = a(1)*x(n) + a(2)*x(n-1) + ... + a(na+1)*x(n-na).
548 </div>
549
550
551 <!-- ------------------------------------------------ -->
552 <!-- --------------- END CONTENT FILE --------------- -->
553 <!-- ------------------------------------------------ -->