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