Mercurial > hg > ltpda
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/html_help/help/ug/constructor_examples_mfir_content.html Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,553 @@ +<!-- $Id: constructor_examples_mfir_content.html,v 1.4 2009/02/27 16:51:57 ingo Exp $ --> + +<!-- -------------------------------------------------- --> +<!-- --------------- BEGIN CONTENT FILE --------------- --> +<!-- -------------------------------------------------- --> + +<!-- --------------- Link box: begin --------------- --> +<table border="0" summary="Simple list" class="simplelist_nottable_last"> + <tr> + <td> + <a href="constructor_examples_mfir.html#copy">Copy an MFIR object</a> + </td> + </tr> + <tr> + <td> + <a href="constructor_examples_mfir.html#xml_file">Construct a MFIR object by loading the object from a file</a> + </td> + </tr> + <tr> + <td> + <a href="constructor_examples_mfir.html#ao">Construct a MFIR object from an Analysis Object <tt>(AO)</tt></a> + </td> + </tr> + <tr> + <td> + <a href="constructor_examples_rational.html#pzmodel">Construct a MFIR object from a pole/zero model <tt>(PZMODEL)</tt></a> + </td> + </tr> + <tr> + <td> + <a href="constructor_examples_mfir.html#std_type">Construct a MFIR object from a standard type</a> + </td> + </tr> + <tr> + <td> + <a href="constructor_examples_mfir.html#exist_model">Construct a MFIR object from an existing filter model</a> + </td> + </tr> + <tr> + <td> + <a href="constructor_examples_mfir.html#equation">Construct a MFIR object from a difference equation</a> + </td> + </tr> +</table> +<!-- --------------- Link box: end --------------- --> + +<!-- --------------- NEXT EXAMPLE --------------- --> + +<hr> +<h2 class="title"><a name="copy"></a>Copy an FIR filter object</h2> +<p>The following example creates a copy of an FIR filter object (blue command).</p> +<div class="fragment"><pre class="programlisting"> +>> fir1 = mfir(plist(<span class="string">'type'</span>, <span class="string">'lowpass'</span>)); +<span class="blue">>> fir2 = mfir(fir2)</span> +------ mfir/1 ------- + gd: 32.5 +version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp + ntaps: 65 + fs: 1 + infile: + a: [0.0007 0.0004 -6.9093e-19 -0.0006 -0.0012 -0.0014 -0.0011 1.4147e-18 ... +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 ... + iunits: [] [1x1 unit] + ounits: [] [1x1 unit] + hist: mfir.hist [1x1 history] + name: lowpass +--------------------- +</pre></div> +<br></br> +<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> +<div class="fragment"><pre class="programlisting"> +>> fir1 = mfir() +------ mfir/1 ------- + gd: [] +version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp + ntaps: 0 + fs: [] + infile: + a: [] +histout: [] + iunits: [] [1x1 unit] + ounits: [] [1x1 unit] + hist: mfir.hist [1x1 history] + name: none +--------------------- +>> fir2 = fir1; +>> fir2.setName(<span class="string">'my new name'</span>) +------ mfir/1 ------- + gd: [] +version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp + ntaps: 0 + fs: [] + infile: + a: [] +histout: [] + iunits: [] [1x1 unit] + ounits: [] [1x1 unit] + hist: mfir.hist [1x1 history] + name: <span class="string">my new name</span> +--------------------- +</pre></div> +<br></br> +<p>If we display fir1 again then we see that the property 'name' was changed although we only have changed fir2.</p> +<div class="fragment"><pre class="programlisting"> +>> fir1 +------ mfir/1 ------- + gd: [] +version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp + ntaps: 0 + fs: [] + infile: + a: [] +histout: [] + iunits: [] [1x1 unit] + ounits: [] [1x1 unit] + hist: mfir.hist [1x1 history] + name: <span class="string">my new name</span> +---------------------</pre></div> + + +<!-- --------------- NEXT EXAMPLE --------------- --> + +<hr> +<h2 class="title"><a name="xml_file"></a>Construct a MFIR object by loading the object from a file</h2> +<p>The following example creates a new mfir object by loading the mfir object from disk.</p> +<div class="fragment"><pre class="programlisting"> +fir = mfir(<span class="string">'fir.mat'</span>) +fir = mfir(<span class="string">'fir.xml'</span>) +</pre></div> +<p>or in a <tt>PLIST</tt></p> +<div class="fragment"><pre class="programlisting"> +pl = plist(<span class="string">'filename'</span>, <span class="string">'fir.xml'</span>); +fir = mfir(pl) +</pre></div> + +<!-- --------------- NEXT EXAMPLE --------------- --> + +<hr> +<h2 class="title"><a name="ao"></a>Construct a MFIR object from an Analysis Object</h2> +<p> An FIR filter object can be generated based on the magnitude of the input AO/fsdata object. +In the following example an AO/fsdata object is first generated and then passed to the mfir constructor +to obtain the equivalent FIR filter.</p> +<div class="fragment"><pre class="programlisting"> +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))); +fir = mfir(a1); +iplot(a1, resp(fir)); +</pre></div> +<p>or in a PLIST with the relevant parameters:</p> +<p> + <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%"> + <colgroup> + <col width="25%"/> + <col width="75%"/> + </colgroup> + <thead> + <tr valign="top"> + <th class="subcategorylist">Key</th> + <th class="subcategorylist">Description</th> + </tr> + </thead> + <tbody> + <tr valign="top"> + <td> + <p>'method'</p> + </td> + <td> + <p>the design method:<br></br> + 'frequency-sampling' - uses fir2()<br></br> + 'least-squares' - uses firls()<br></br> + 'Parks-McClellan' - uses firpm()<br></br> + [default: 'frequency-sampling']</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'win'</p> + </td> + <td> + <p>Window function for frequency-sampling method [default: 'Hanning']</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'N'</p> + </td> + <td> + <p>Filter order [default: 512]</p> + </td> + </tr> + </tbody> + </table> +</p> +<p>The following example creates a mfir object from an analysis object.</p> +<div class="fragment"><pre class="programlisting"> +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))); +pl = plist(<span class="string">'ao'</span>, a1); +fir = mfir(pl) +</pre></div> + + +<!-- --------------- NEXT EXAMPLE --------------- --> + +<hr> +<h2 class="title"><a name="pzmodel"></a>Construct an FIR filter object from a pole/zero model</h2> +<p>The following example creates a new FIR filter object from a pole/zero model.</p> +<div class="fragment"><pre class="programlisting"> +>> pzm = pzmodel(1, {1 2 3}, {4 5}, <span class="string">'my pzmodel'</span>) +---- pzmodel 1 ---- + name: my pzmodel + gain: 1 + delay: 0 + iunits: [] + ounits: [] +pole 001: (f=1 Hz,Q=NaN) +pole 002: (f=2 Hz,Q=NaN) +pole 003: (f=3 Hz,Q=NaN) +zero 001: (f=4 Hz,Q=NaN) +zero 002: (f=5 Hz,Q=NaN) +------------------- +>> fir = mfir(pzm) <span class="comment">% Use the default sample rate fs=8 * frequency of the highest pole or zero in the model</span> +>> fir = mfir(pzm, plist(<span class="string">'fs'</span>, 100)) +------ mfir/1 ------- + gd: 257 +version: $Id: mfir.m,v 1.84 2009/02/24 17:02:44 ingo Exp + ntaps: 513 + fs: 100 + infile: + a: [-0 -3.013e-10 -1.2486e-09 -2.8506e-09 -5.1166e-09 -7.8604e-09 -1.1133e-08 ... +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 ... + iunits: [] [1x1 unit] + ounits: [] [1x1 unit] + hist: mfir.hist [1x1 history] + name: my pzmodel +--------------------- +</pre></div> +<p>or in a PLIST with the relevant parameters:</p> +<p> + <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%"> + <colgroup> + <col width="25%"/> + <col width="75%"/> + </colgroup> + <thead> + <tr valign="top"> + <th class="subcategorylist">Key</th> + <th class="subcategorylist">Description</th> + </tr> + </thead> + <tbody> + <tr valign="top"> + <td> + <p>'pzmodel'</p> + </td> + <td> + <p>A pzmodel object to construct the filter from [default: empty pzmodel]</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'fs'</p> + </td> + <td> + <p>Sample rate [default: 8 * frequency of the highest pole or zero in the model]</p> + </td> + </tr> + </tbody> + </table> +</p> +<div class="fragment"><pre class="programlisting"> +>> pzm = pzmodel(1, {1 2 3}, {4 5}, <span class="string">'my pzmodel'</span>) +>> pl = plist(<span class="string">'pzmodel'</span>, pzm, <span class="string">'fs'</span>, 100) +>> fir = mfir(pl) +</pre></div> + + +<!-- --------------- NEXT EXAMPLE --------------- --> + +<hr></hr> +<h2 class="title"><a name="std_type"></a>Construct a MFIR object from a standard type</h2> +<p>Construct an FIR filter object from a standard type: 'lowpass', 'highpass', 'bandpass' or 'bandreject'</p> +<p>The relevant parameters are:</p> +<p> + <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%"> + <colgroup> + <col width="25%"/> + <col width="75%"/> + </colgroup> + <thead> + <tr valign="top"> + <th class="subcategorylist">Key</th> + <th class="subcategorylist">Description</th> + </tr> + </thead> + <tbody> + <tr valign="top"> + <td> + <p>'type'</p> + </td> + <td> + <p>one of the types: 'highpass', 'lowpass', 'bandpass', 'bandreject'<br></br> + [default 'lowpass']</p> + </td> + </tr> + </tbody> + </table> +</p> +<p>You can also specify optional parameters:</p> +<p> + <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%"> + <colgroup> + <col width="25%"/> + <col width="75%"/> + </colgroup> + <thead> + <tr valign="top"> + <th class="subcategorylist">Key</th> + <th class="subcategorylist">Description</th> + </tr> + </thead> + <tbody> + <tr valign="top"> + <td> + <p>'gain'</p> + </td> + <td> + <p>The gain of the filter [default: 1]</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'fc'</p> + </td> + <td> + <p>The roll-off frequency [default: 0.1 Hz]</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'fs'</p> + </td> + <td> + <p>The sampling frequency to design for [default: 1 Hz]</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'order'</p> + </td> + <td> + <p>The filter order [default: 64]</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'win'</p> + </td> + <td> + <p>Specify window function used in filter design [default: 'Hamming']</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'iunits'</p> + </td> + <td> + <p>the input unit of the filter</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'ounits'</p> + </td> + <td> + <p>the output unit of the filter</p> + </td> + </tr> + </tbody> + </table> +</p> +<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> +<div class="fragment"><pre class="programlisting"> +pl = plist(<span class="string">'type'</span>, <span class="string">'highpass'</span>, ... + <span class="string">'order'</span>, 64, ... + <span class="string">'gain'</span>, 2.0, ... + <span class="string">'fs'</span>, 1, ... + <span class="string">'fc'</span>, 0.2); +f = mfir(pl) +</pre></div> +<p>Furthermore it is possible to specify a spectral window.</p> +<div class="fragment"><pre class="programlisting"> +win = specwin(<span class="string">'Kaiser'</span>, 11, 150); +pl = plist(<span class="string">'type'</span>, <span class="string">'lowpass'</span>, ... + <span class="string">'Win'</span>, win, ... + <span class="string">'fs'</span>, 100, ... + <span class="string">'fc'</span>, 20, ... + <span class="string">'order'</span>, 10); +f = mfir(pl) +</pre></div> + +<!-- --------------- NEXT EXAMPLE --------------- --> + +<hr> +<h2 class="title"><a name="exist_model"></a>Construct a MFIR object from an existing filter</h2> +<p>The mfir constructor also accepts as an input existing filters stored in different formats:</p> +<p>LISO files</p> +<div class="fragment"><pre class="programlisting"> +f = mfir(<span class="string">'foo_fir.fil'</span>) +</pre></div> +<p>XML files</p> +<div class="fragment"><pre class="programlisting"> +f = mfir(<span class="string">'foo_fir.xml'</span>) +</pre></div> +<p>MAT files</p> +<div class="fragment"><pre class="programlisting"> +f = mfir(<span class="string">'foo_fir.mat'</span>) +</pre></div> +<p>From an LTPDA repository</p> +<p>The relevant parameters for retrieving a FIR filter from a LTPDA repository are:</p> +<p> + <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%"> + <colgroup> + <col width="25%"/> + <col width="75%"/> + </colgroup> + <thead> + <tr valign="top"> + <th class="subcategorylist">Key</th> + <th class="subcategorylist">Description</th> + </tr> + </thead> + <tbody> + <tr valign="top"> + <td> + <p>'hostname'</p> + </td> + <td> + <p>the repository hostname. [default: 'localhost']</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'database'</p> + </td> + <td> + <p>The database name [default: 'ltpda']</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'id'</p> + </td> + <td> + <p>A vector of object IDs. [default: []]</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'cid'</p> + </td> + <td> + <p>Retrieve all rational objects from a particular collection</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'binary'</p> + </td> + <td> + <p>Set to 'yes' to retrieve from stored binary representation (not always available). [default: yes]</p> + </td> + </tr> + </tbody> + </table> +</p> +<div class="fragment"><pre class="programlisting"> +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>, [])) +</pre></div> + + +<!-- --------------- NEXT EXAMPLE --------------- --> + +<hr> +<h2 class="title"><a name="equation"></a>Construct a MFIR object from a difference equation</h2> +<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> +<div align="center"> + <IMG src="images/sigproc_10.png" width="202" height="28" align="middle" border="0"> +</div> +<div class="fragment"><pre class="programlisting"> +a = [-0.8 10]; +fs = 1; + +f = mfir(a,fs) +</pre></div> +<p>or in a <tt>PLIST</tt></p> +<p>The relevant parameters are:</p> +<p> + <table cellspacing="0" border="0" cellpadding="2" class="simplelist_nottable_last" width="80%"> + <colgroup> + <col width="25%"/> + <col width="75%"/> + </colgroup> + <thead> + <tr valign="top"> + <th class="subcategorylist">Key</th> + <th class="subcategorylist">Description</th> + </tr> + </thead> + <tbody> + <tr valign="top"> + <td> + <p>'a'</p> + </td> + <td> + <p>vector of A coefficients. (see note ** below) [default: empty]</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'fs'</p> + </td> + <td> + <p>sampling frequency of the filter [default: empty]</p> + </td> + </tr> + <tr valign="top"> + <td> + <p>'name'</p> + </td> + <td> + <p>name of filter [default: 'None']</p> + </td> + </tr> + </tbody> + </table> +</p> +<div class="fragment"><pre class="programlisting"> +a = [-0.8 10]; +fs = 1; +pl = plist(<span class="string">'a'</span>, a, <span class="string">'fs'</span>, fs); + +fir = mfir(pl) +</pre></div> +<br></br> +<div class="fragment"> +NOTES:<br></br> +** 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> +y(n) = a(1)*x(n) + a(2)*x(n-1) + ... + a(na+1)*x(n-na). +</div> + + +<!-- ------------------------------------------------ --> +<!-- --------------- END CONTENT FILE --------------- --> +<!-- ------------------------------------------------ -->