| 1 | |
| 2 | <refentry id="filter2"> |
| 3 | <indexterm id="IndexFilter2"><primary>filter2</primary></indexterm> |
| 4 | <refentryinfo><title>Signal Modifiers:Specialized Filters</title></refentryinfo> |
| 5 | <refmeta> |
| 6 | <refentrytitle>filter2</refentrytitle> |
| 7 | </refmeta> |
| 8 | |
| 9 | <refnamediv> |
| 10 | <refname>filter2</refname> |
| 11 | <refpurpose> |
| 12 | Performs filtering using a transposed form-II digital filter lattice with no time-varying control. |
| 13 | </refpurpose> |
| 14 | </refnamediv> |
| 15 | |
| 16 | <refsect1> |
| 17 | <title>Description</title> |
| 18 | <para> |
| 19 | General purpose custom filter with no time-varying pole control. The filter coefficients implement the following difference equation: |
| 20 | <literallayout> |
| 21 | (1)*y(n) = b0*x[n] + b1*x[n-1] +...+ bM*x[n-M] - a1*y[n-1] -...- aN*y[n-N] |
| 22 | </literallayout> |
| 23 | </para> |
| 24 | |
| 25 | <para> |
| 26 | the system function for which is represented by: |
| 27 | <literallayout> |
| 28 | B(Z) b0 + b1*Z<superscript>-1</superscript> + ... + bM*Z<superscript>-M</superscript> |
| 29 | H(Z) = ---- = -------------------------- |
| 30 | A(Z) 1 + a1*Z<superscript>-1</superscript> + ... + aN*Z<superscript>-N</superscript> |
| 31 | </literallayout> |
| 32 | </para> |
| 33 | </refsect1> |
| 34 | |
| 35 | <refsect1> |
| 36 | <title>Syntax</title> |
| 37 | <synopsis>ares <command>filter2</command> asig, ibcoefs, iacoefs, ib0, ib1, ..., ibM, ia1, ia2, ..., iaN</synopsis> |
| 38 | |
| 39 | <synopsis>kres <command>filter2</command> ksig, ibcoefs, iacoefs, ib0, ib1, ..., ibM, ia1, ia2, ..., iaN</synopsis> |
| 40 | </refsect1> |
| 41 | |
| 42 | <refsect1> |
| 43 | <title>Initialization</title> |
| 44 | <para> |
| 45 | <emphasis>ibcoefs</emphasis> -- number of feedforward coefficients |
| 46 | including b0. |
| 47 | </para> |
| 48 | <para> |
| 49 | <emphasis>iacoefs</emphasis> -- number of feedback coefficients |
| 50 | </para> |
| 51 | |
| 52 | <para> |
| 53 | <emphasis>ib0, ... ibM</emphasis> -- feedforward coefficients |
| 54 | including b0. |
| 55 | </para> |
| 56 | <para> |
| 57 | <emphasis>ia1, ... iaN</emphasis> -- feedback coefficients |
| 58 | </para> |
| 59 | <para> |
| 60 | At initialization the number of zeros and poles of the filter are specified along with the corresponding zero and pole coefficients. The coefficients must be obtained by an external filter-design application such as Matlab and specified directly or loaded into a table via <link linkend="GEN01"><citetitle>GEN01</citetitle></link>. |
| 61 | </para> |
| 62 | </refsect1> |
| 63 | |
| 64 | <refsect1> |
| 65 | <title>Performance</title> |
| 66 | <para> |
| 67 | The<emphasis> filter2</emphasis> opcodes perform filtering using a transposed form-II digital filter lattice with no time-varying control. |
| 68 | </para> |
| 69 | |
| 70 | <para> |
| 71 | Since <emphasis>filter2</emphasis> implements generalized recursive filters, it can be used to specify a large range of general DSP algorithms. For example, a digital waveguide can be implemented for musical instrument modeling using a pair of <link linkend="delayr"><citetitle>delayr</citetitle></link> and <link linkend="delayw"><citetitle>delayw</citetitle></link> opcodes in conjunction with the <emphasis>filter2</emphasis> opcode. |
| 72 | </para> |
| 73 | </refsect1> |
| 74 | |
| 75 | <refsect1> |
| 76 | <title>Examples</title> |
| 77 | <para> |
| 78 | A first-order linear-phase lowpass FIR filter operating on a k-rate signal: |
| 79 | |
| 80 | <informalexample> |
| 81 | <programlisting> |
| 82 | k1 <emphasis role="opc">filter2</emphasis> ksig, 2, 0, 0.5, 0.5 <emphasis role="comment">;; k-rate FIR filter</emphasis></programlisting> |
| 83 | </informalexample> |
| 84 | </para> |
| 85 | <para> |
| 86 | Here is another example of the filter2 opcode. It uses the file <ulink url="examples/filter2.csd"><citetitle>filter2.csd</citetitle></ulink>. |
| 87 | <example> |
| 88 | <title>Example of the filter2 opcode.</title> |
| 89 | <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para> |
| 90 | <xi:include href="examples-xml/filter2.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 91 | </example> |
| 92 | </para> |
| 93 | </refsect1> |
| 94 | |
| 95 | <refsect1> |
| 96 | <title>See also</title> |
| 97 | <para><link linkend="SigmodSpeciali"><citetitle>Specialized Filters: Other filters</citetitle></link></para> |
| 98 | </refsect1> |
| 99 | |
| 100 | <refsect1> |
| 101 | <title>Credits</title> |
| 102 | <para> |
| 103 | <simplelist> |
| 104 | <member>Author: Michael A. Casey</member> |
| 105 | <member>M.I.T.</member> |
| 106 | <member>Cambridge, Mass.</member> |
| 107 | <member>1997</member> |
| 108 | </simplelist> |
| 109 | </para> |
| 110 | <para>New in version 3.47</para> |
| 111 | </refsect1> |
| 112 | </refentry> |