<?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" /> <meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /> <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="filevalid.html" title="filevalid" /> <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="filevalid.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" title="filter2"> <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" title="Description"> <a id="idp20157024"></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" title="Syntax"> <a id="idp20169312"></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" title="Initialization"> <a id="idp20171232"></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" title="Performance"> <a id="idp20172600"></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" title="Examples"> <a id="idp20205792"></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="idp20208272"></a> <p class="title"> <strong>Example 231. 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> <pre class="programlisting"> <span class="csdtag"><CsoundSynthesizer></span> <span class="csdtag"><CsOptions></span> <span class="comment">; Select audio/midi flags here according to platform</span> -odac <span class="comment">;;;realtime audio out</span> <span class="comment">;-iadc ;;;uncomment -iadc if realtime audio input is needed too</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o filter2.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">ksmps</span> <span class="op">=</span> 32 <span class="ohdr">nchnls</span> <span class="op">=</span> 2 <span class="ohdr">0dbfs</span> <span class="op">=</span> 1 <span class="oblock">instr</span> 1 <span class="comment">; 2 saw waves of which one is slightly detuned</span> ib1 <span class="op">=</span> p5 ivol <span class="op">=</span> p6 <span class="comment">;volume to compensate </span> kcps <span class="opc">init</span> <span class="opc">cpspch</span>(p4) asig1 <span class="opc">vco2</span> .05, kcps <span class="comment">;saw 1</span> asaw1 <span class="opc">filter2</span> asig1, 1, 1, 1, ib1 <span class="comment">;filter 1 </span> asig2 <span class="opc">vco2</span> .05, kcps<span class="op">+</span>1 <span class="comment">;saw 2 </span> asaw2 <span class="opc">filter2</span> asig2, 1, 1, 1, ib1 <span class="comment">;filter 2</span> aout <span class="op">=</span> (asaw1<span class="op">+</span>asaw2)<span class="op">*</span>ivol <span class="comment">;mix</span> <span class="opc">outs</span> aout, aout <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">i</span> 1 0 4 6.00 -.001 5 <span class="comment">;different filter values</span> <span class="stamnt">i</span> 1 + 4 6.00 -.6 2 <span class="comment">;and different volumes</span> <span class="stamnt">i</span> 1 + 4 6.00 -.95 .3 <span class="comment">;to compensate</span> <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> </p> </div> <div class="refsect1" title="See Also"> <a id="idp20210552"></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" title="Credits"> <a id="idp20211568"></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="filevalid.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">filevalid </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>