<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>filter2</title> <link rel="stylesheet" type="text/css" href="csound.css" /> <link rel="stylesheet" type="text/css" href="syntax-highlighting.css" /> <meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /> <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" /> <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" /> <link rel="prev" href="fft.html" title="fft" /> <link rel="next" href="fin.html" title="fin" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">filter2</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="fft.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="fin.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry"> <a id="filter2"></a> <div class="titlepage"></div> <a id="IndexFilter2" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">filter2</span> </h2> <p>filter2 — Performs filtering using a transposed form-II digital filter lattice with no time-varying control. </p> </div> <div class="refsect1"> <a id="idm281472937475496"></a> <h2>Description</h2> <p> General purpose custom filter with no time-varying pole control. The filter coefficients implement the following difference equation: </p> <div class="literallayout"> <p><br /> (1)*y(n) = b0*x[n] + b1*x[n-1] +...+ bM*x[n-M] - a1*y[n-1] -...- aN*y[n-N]<br /> </p> </div> <p> </p> <p> the system function for which is represented by: </p> <div class="literallayout"> <p><br /> B(Z) b0 + b1*Z<sup>-1</sup> + ... + bM*Z<sup>-M</sup><br /> H(Z) = ---- = --------------------------<br /> A(Z) 1 + a1*Z<sup>-1</sup> + ... + aN*Z<sup>-N</sup><br /> </p> </div> <p> </p> </div> <div class="refsect1"> <a id="idm281472937409384"></a> <h2>Syntax</h2> <pre class="synopsis">ares <span class="command"><strong>filter2</strong></span> asig, iM, iN, ib0, ib1, ..., ibM, ia1, ia2, ..., iaN</pre> <pre class="synopsis">kres <span class="command"><strong>filter2</strong></span> ksig, iM, iN, ib0, ib1, ..., ibM, ia1, ia2, ..., iaN</pre> </div> <div class="refsect1"> <a id="idm281472937405704"></a> <h2>Initialization</h2> <p> 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 <a class="link" href="GEN01.html" title="GEN01"><em class="citetitle">GEN01</em></a>. </p> </div> <div class="refsect1"> <a id="idm281472937403256"></a> <h2>Performance</h2> <p> The<span class="emphasis"><em> filter2</em></span> opcodes perform filtering using a transposed form-II digital filter lattice with no time-varying control. </p> <p> Since <span class="emphasis"><em>filter2</em></span> 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 <a class="link" href="delayr.html" title="delayr"><em class="citetitle">delayr</em></a> and <a class="link" href="delayw.html" title="delayw"><em class="citetitle">delayw</em></a> opcodes in conjunction with the <span class="emphasis"><em>filter2</em></span> opcode. </p> </div> <div class="refsect1"> <a id="idm281472937398056"></a> <h2>Examples</h2> <p> A first-order linear-phase lowpass FIR filter operating on a k-rate signal: </p> <div class="informalexample"> <pre class="programlisting"> k1 <span class="opc">filter2</span> ksig, 2, 0, 0.5, 0.5 <span class="comment">;; k-rate FIR filter</span></pre> </div> <p> </p> <p> Here is another example of the filter2 opcode. It uses the file <a class="ulink" href="examples/filter2.csd" target="_top"><em class="citetitle">filter2.csd</em></a>. </p> <div class="example"> <a id="idm281472937393368"></a> <p class="title"> <strong>Example 277. Example of the filter2 opcode.</strong> </p> <div class="example-contents"> <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p> <div class="refsect1"> <a id="idm281472769636056"></a> <pre class="programlisting"> <span class="nt"><CsoundSynthesizer></span> <span class="nt"><CsOptions></span> <span class="c1">; Select audio/midi flags here according to platform</span> -odac <span class="c1">;;;realtime audio out</span> <span class="c1">;-iadc ;;;uncomment -iadc if realtime audio input is needed too</span> <span class="c1">; For Non-realtime ouput leave only the line below:</span> <span class="c1">; -o filter2.wav -W ;;; for file output any platform</span> <span class="nt"></CsOptions></span> <span class="nt"><CsInstruments></span> <span class="vg">sr</span> <span class="o">=</span> <span class="mi">44100</span> <span class="vg">ksmps</span> <span class="o">=</span> <span class="mi">32</span> <span class="vg">nchnls</span> <span class="o">=</span> <span class="mi">2</span> <span class="vg">0dbfs</span> <span class="o">=</span> <span class="mi">1</span> <span class="kd">instr</span> <span class="nf">1</span> <span class="c1">; 2 saw waves of which one is slightly detuned</span> i<span class="n">b1</span> <span class="o">=</span> <span class="nb">p5</span> i<span class="n">vol</span> <span class="o">=</span> <span class="nb">p6</span> <span class="c1">;volume to compensate </span> k<span class="n">cps</span> <span class="nb">init</span> <span class="nb">cpspch</span><span class="p">(</span><span class="nb">p4</span><span class="p">)</span> a<span class="n">sig1</span> <span class="nb">vco2</span> <span class="mf">.05</span><span class="p">,</span> k<span class="n">cps</span> <span class="c1">;saw 1</span> a<span class="n">saw1</span> <span class="nb">filter2</span> a<span class="n">sig1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> i<span class="n">b1</span> <span class="c1">;filter 1 </span> a<span class="n">sig2</span> <span class="nb">vco2</span> <span class="mf">.05</span><span class="p">,</span> k<span class="n">cps</span><span class="o">+</span><span class="mi">1</span> <span class="c1">;saw 2 </span> a<span class="n">saw2</span> <span class="nb">filter2</span> a<span class="n">sig2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> i<span class="n">b1</span> <span class="c1">;filter 2</span> a<span class="n">out</span> <span class="o">=</span> <span class="p">(</span>a<span class="n">saw1</span><span class="o">+</span>a<span class="n">saw2</span><span class="p">)</span><span class="o">*</span>i<span class="n">vol</span> <span class="c1">;mix</span> <span class="nb">outs</span> a<span class="n">out</span><span class="p">,</span> a<span class="n">out</span> <span class="kd">endin</span> <span class="nt"></CsInstruments></span> <span class="nt"><CsScore></span> <span class="nb">i</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">4</span> <span class="mf">6.00</span> <span class="o">-</span><span class="mf">.001</span> <span class="mi">5</span> <span class="c1">;different filter values</span> <span class="nb">i</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">4</span> <span class="mf">6.00</span> <span class="o">-</span><span class="mf">.6</span> <span class="mi">2</span> <span class="c1">;and different volumes</span> <span class="nb">i</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">4</span> <span class="mf">6.00</span> <span class="o">-</span><span class="mf">.95</span> <span class="mf">.3</span> <span class="c1">;to compensate</span> <span class="nb">e</span> <span class="nt"></CsScore></span> <span class="nt"></CsoundSynthesizer></span> </pre> </div> </div> </div> <p><br class="example-break" /> </p> </div> <div class="refsect1"> <a id="idm281472937389080"></a> <h2>See Also</h2> <p> <a class="link" href="zfilter2.html" title="zfilter2"><em class="citetitle">zfilter2</em></a> </p> </div> <div class="refsect1"> <a id="idm281472937387032"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: Michael A. Casey</td> </tr> <tr> <td>M.I.T.</td> </tr> <tr> <td>Cambridge, Mass.</td> </tr> <tr> <td>1997</td> </tr> </table> <p> </p> <p>New in version 3.47</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="fft.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="OpcodesTop.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="fin.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">fft </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> fin</td> </tr> </table> </div> </body> </html>