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