| 1 |
|
| 2 |
<!DOCTYPE html> |
| 3 |
|
| 4 |
<html lang="en"> |
| 5 |
<head> |
| 6 |
<meta charset="utf-8"/> |
| 7 |
<meta content="width=device-width, initial-scale=1.0" name="viewport"/><meta content="Docutils 0.17.1: http://docutils.sourceforge.net/" name="generator"/> |
| 8 |
<title>02-bandpass-filters.py - Narrowing a bandpass filter bandwidth. — Pyo 1.0.5 documentation</title> |
| 9 |
<link href="../../_static/pygments.css" rel="stylesheet" type="text/css"/> |
| 10 |
<link href="../../_static/agogo.css" rel="stylesheet" type="text/css"/> |
| 11 |
<link href="../../_static/sphinx-codeautolink.css" rel="stylesheet" type="text/css"/> |
| 12 |
<link href="../../_static/autoclasstoc.css" rel="stylesheet" type="text/css"/> |
| 13 |
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> |
| 14 |
<script src="../../_static/jquery.js"></script> |
| 15 |
<script src="../../_static/underscore.js"></script> |
| 16 |
<script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script> |
| 17 |
<script src="../../_static/doctools.js"></script> |
| 18 |
<script src="../../_static/sphinx_highlight.js"></script> |
| 19 |
<link href="../../_static/E-PyoIcon.ico" rel="shortcut icon"/> |
| 20 |
<link href="../../about.html" rel="author" title="About these documents"/> |
| 21 |
<link href="../../genindex.html" rel="index" title="Index"/> |
| 22 |
<link href="../../search.html" rel="search" title="Search"/> |
| 23 |
<link href="03-complex-resonator.html" rel="next" title="03-complex-resonator.py - Filtering by mean of a complex multiplication."/> |
| 24 |
<link href="01-lowpass-filters.html" rel="prev" title="01-lowpass-filters.py - The effect of the order of a filter."/> |
| 25 |
</head><body> |
| 26 |
<div class="header-wrapper" role="banner"> |
| 27 |
<div class="header"> |
| 28 |
<div class="headertitle"><a href="../../index.html">Pyo 1.0.5 documentation</a></div> |
| 29 |
<div aria-label="related navigation" class="rel" role="navigation"> |
| 30 |
<a accesskey="P" href="01-lowpass-filters.html" title="01-lowpass-filters.py - The effect of the order of a filter.">previous</a> | |
| 31 |
<a accesskey="N" href="03-complex-resonator.html" title="03-complex-resonator.py - Filtering by mean of a complex multiplication.">next</a> | |
| 32 |
<a accesskey="I" href="../../genindex.html" title="General Index">index</a> |
| 33 |
</div> |
| 34 |
</div> |
| 35 |
</div> |
| 36 |
<div class="content-wrapper"> |
| 37 |
<div class="content"> |
| 38 |
<div class="sidebar"> |
| 39 |
<h3>Table of Contents</h3> |
| 40 |
<ul> |
| 41 |
<li class="toctree-l1"><a class="reference internal" href="../../about.html">About pyo</a></li> |
| 42 |
<li class="toctree-l1"><a class="reference internal" href="../../download.html">Installing pyo with pip</a></li> |
| 43 |
<li class="toctree-l1"><a class="reference internal" href="../../compiling.html">Compiling pyo from sources</a></li> |
| 44 |
<li class="toctree-l1"><a class="reference internal" href="../../structure.html">Structure of the library</a></li> |
| 45 |
<li class="toctree-l1"><a class="reference internal" href="../../gettingstarted.html">Getting started</a></li> |
| 46 |
<li class="toctree-l1"><a class="reference internal" href="../../winaudioinspect.html">Configuring the audio output (Windows)</a></li> |
| 47 |
<li class="toctree-l1"><a class="reference internal" href="../../perftips.html">Improve performance of pyo programs</a></li> |
| 48 |
</ul> |
| 49 |
<ul class="current"> |
| 50 |
<li class="toctree-l1"><a class="reference internal" href="../../api/index.html">API documentation</a></li> |
| 51 |
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">Examples</a><ul class="current"> |
| 52 |
<li class="toctree-l2"><a class="reference internal" href="../01-intro/index.html">First steps</a></li> |
| 53 |
<li class="toctree-l2"><a class="reference internal" href="../02-controls/index.html">Parameter control</a></li> |
| 54 |
<li class="toctree-l2"><a class="reference internal" href="../03-generators/index.html">Synthesis generators</a></li> |
| 55 |
<li class="toctree-l2"><a class="reference internal" href="../04-soundfiles/index.html">Playing with soundfiles</a></li> |
| 56 |
<li class="toctree-l2"><a class="reference internal" href="../05-envelopes/index.html">Amplitude envelopes</a></li> |
| 57 |
<li class="toctree-l2 current"><a class="reference internal" href="index.html">Filtering</a></li> |
| 58 |
<li class="toctree-l2"><a class="reference internal" href="../07-effects/index.html">Creating sound effects</a></li> |
| 59 |
<li class="toctree-l2"><a class="reference internal" href="../08-dynamics/index.html">Dynamic range of audio signals</a></li> |
| 60 |
<li class="toctree-l2"><a class="reference internal" href="../09-callbacks/index.html">Calling python functions from audio objects</a></li> |
| 61 |
<li class="toctree-l2"><a class="reference internal" href="../10-tables/index.html">Using tables</a></li> |
| 62 |
<li class="toctree-l2"><a class="reference internal" href="../16-midi/index.html">How to use MIDI with pyo</a></li> |
| 63 |
<li class="toctree-l2"><a class="reference internal" href="../17-osc/index.html">How to use OSC with pyo</a></li> |
| 64 |
<li class="toctree-l2"><a class="reference internal" href="../19-multirate/index.html">Multirate audio processing</a></li> |
| 65 |
<li class="toctree-l2"><a class="reference internal" href="../20-multicore/index.html">Multicore audio programming</a></li> |
| 66 |
<li class="toctree-l2"><a class="reference internal" href="../21-utilities/index.html">Utilities</a></li> |
| 67 |
<li class="toctree-l2"><a class="reference internal" href="../22-events/index.html">Events framework</a></li> |
| 68 |
<li class="toctree-l2"><a class="reference internal" href="../23-expression/index.html">Evaluating prefix expression</a></li> |
| 69 |
</ul> |
| 70 |
</li> |
| 71 |
<li class="toctree-l1"><a class="reference internal" href="../../tutorials/index.html">Advanced tutorials</a></li> |
| 72 |
</ul> |
| 73 |
<div role="search"> |
| 74 |
<h3 style="margin-top: 1.5em;">Search</h3> |
| 75 |
<form action="../../search.html" class="search" method="get"> |
| 76 |
<input name="q" type="text"/> |
| 77 |
<input type="submit" value="Go"/> |
| 78 |
</form> |
| 79 |
</div> |
| 80 |
</div> |
| 81 |
<div class="document"> |
| 82 |
<div class="documentwrapper"> |
| 83 |
<div class="bodywrapper"> |
| 84 |
<div class="body" role="main"> |
| 85 |
<section id="bandpass-filters-py-narrowing-a-bandpass-filter-bandwidth"> |
| 86 |
<h1>02-bandpass-filters.py - Narrowing a bandpass filter bandwidth.<a class="headerlink" href="#bandpass-filters-py-narrowing-a-bandpass-filter-bandwidth" title="Permalink to this heading">¶</a></h1> |
| 87 |
<p>This example illustrates the difference between a simple IIR second-order |
| 88 |
bandpass filter and a cascade of second-order bandpass filters. A cascade |
| 89 |
of four bandpass filters with a high Q can be used as a efficient resonator |
| 90 |
on the signal.</p> |
| 91 |
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <a class="sphinx-codeautolink-a" href="../../api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span> |
| 92 |
|
| 93 |
<span class="n">s</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">()</span><span class="o">.</span><span class="n">boot</span><span class="p">()</span> |
| 94 |
|
| 95 |
<span class="c1"># White noise generator</span> |
| 96 |
<a class="sphinx-codeautolink-a" href="../../api/classes/generators.html#pyo.Noise" title="pyo.lib.generators.Noise"><span class="n">n</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/classes/generators.html#pyo.Noise" title="pyo.lib.generators.Noise"><span class="n">Noise</span></a><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span> |
| 97 |
|
| 98 |
<span class="c1"># Common cutoff frequency control</span> |
| 99 |
<a class="sphinx-codeautolink-a" href="../../api/classes/controls.html#pyo.Sig" title="pyo.lib._core.Sig"><span class="n">freq</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/classes/controls.html#pyo.Sig" title="pyo.lib._core.Sig"><span class="n">Sig</span></a><span class="p">(</span><span class="mi">1000</span><span class="p">)</span> |
| 100 |
<span class="n">freq</span><span class="o">.</span><span class="n">ctrl</span><span class="p">([</span><a class="sphinx-codeautolink-a" href="../../api/classes/map.html#pyo.SLMap" title="pyo.lib._maps.SLMap"><span class="n">SLMap</span></a><span class="p">(</span><span class="mi">50</span><span class="p">,</span> <span class="mi">5000</span><span class="p">,</span> <span class="s2">"lin"</span><span class="p">,</span> <span class="s2">"value"</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)],</span> <span class="n">title</span><span class="o">=</span><span class="s2">"Cutoff Frequency"</span><span class="p">)</span> |
| 101 |
|
| 102 |
<span class="c1"># Common filter's Q control</span> |
| 103 |
<a class="sphinx-codeautolink-a" href="../../api/classes/controls.html#pyo.Sig" title="pyo.lib._core.Sig"><span class="n">q</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/classes/controls.html#pyo.Sig" title="pyo.lib._core.Sig"><span class="n">Sig</span></a><span class="p">(</span><span class="mi">5</span><span class="p">)</span> |
| 104 |
<span class="n">q</span><span class="o">.</span><span class="n">ctrl</span><span class="p">([</span><a class="sphinx-codeautolink-a" href="../../api/classes/map.html#pyo.SLMap" title="pyo.lib._maps.SLMap"><span class="n">SLMap</span></a><span class="p">(</span><span class="mf">0.7</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="s2">"log"</span><span class="p">,</span> <span class="s2">"value"</span><span class="p">,</span> <span class="mi">5</span><span class="p">)],</span> <span class="n">title</span><span class="o">=</span><span class="s2">"Filter's Q"</span><span class="p">)</span> |
| 105 |
|
| 106 |
<span class="c1"># Second-order bandpass filter</span> |
| 107 |
<a class="sphinx-codeautolink-a" href="../../api/classes/filters.html#pyo.Reson" title="pyo.lib.filters.Reson"><span class="n">bp1</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/classes/filters.html#pyo.Reson" title="pyo.lib.filters.Reson"><span class="n">Reson</span></a><span class="p">(</span><a class="sphinx-codeautolink-a" href="../../api/classes/generators.html#pyo.Noise" title="pyo.lib.generators.Noise"><span class="n">n</span></a><span class="p">,</span> <a class="sphinx-codeautolink-a" href="../../api/classes/controls.html#pyo.Sig" title="pyo.lib._core.Sig"><span class="n">freq</span></a><span class="p">,</span> <span class="n">q</span><span class="o">=</span><a class="sphinx-codeautolink-a" href="../../api/classes/controls.html#pyo.Sig" title="pyo.lib._core.Sig"><span class="n">q</span></a><span class="p">)</span> |
| 108 |
<span class="c1"># Cascade of second-order bandpass filters</span> |
| 109 |
<a class="sphinx-codeautolink-a" href="../../api/classes/filters.html#pyo.Resonx" title="pyo.lib.filters.Resonx"><span class="n">bp2</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/classes/filters.html#pyo.Resonx" title="pyo.lib.filters.Resonx"><span class="n">Resonx</span></a><span class="p">(</span><a class="sphinx-codeautolink-a" href="../../api/classes/generators.html#pyo.Noise" title="pyo.lib.generators.Noise"><span class="n">n</span></a><span class="p">,</span> <a class="sphinx-codeautolink-a" href="../../api/classes/controls.html#pyo.Sig" title="pyo.lib._core.Sig"><span class="n">freq</span></a><span class="p">,</span> <span class="n">q</span><span class="o">=</span><a class="sphinx-codeautolink-a" href="../../api/classes/controls.html#pyo.Sig" title="pyo.lib._core.Sig"><span class="n">q</span></a><span class="p">,</span> <span class="n">stages</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span> |
| 110 |
|
| 111 |
<span class="c1"># Interpolates between input objects to produce a single output</span> |
| 112 |
<span class="n">sel</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/classes/pan.html#pyo.Selector" title="pyo.lib.pan.Selector"><span class="n">Selector</span></a><span class="p">([</span><a class="sphinx-codeautolink-a" href="../../api/classes/filters.html#pyo.Reson" title="pyo.lib.filters.Reson"><span class="n">bp1</span></a><span class="p">,</span> <a class="sphinx-codeautolink-a" href="../../api/classes/filters.html#pyo.Resonx" title="pyo.lib.filters.Resonx"><span class="n">bp2</span></a><span class="p">])</span><span class="o">.</span><span class="n">out</span><span class="p">()</span> |
| 113 |
<span class="n">sel</span><span class="o">.</span><span class="n">ctrl</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s2">"Filter selector (0=Reson, 1=Resonx)"</span><span class="p">)</span> |
| 114 |
|
| 115 |
<span class="c1"># Displays the spectrum contents of the chosen source</span> |
| 116 |
<a class="sphinx-codeautolink-a" href="../../api/classes/analysis.html#pyo.Spectrum" title="pyo.lib.analysis.Spectrum"><span class="n">sp</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/classes/analysis.html#pyo.Spectrum" title="pyo.lib.analysis.Spectrum"><span class="n">Spectrum</span></a><span class="p">(</span><span class="n">sel</span><span class="p">)</span> |
| 117 |
|
| 118 |
<span class="n">s</span><span class="o">.</span><span class="n">gui</span><span class="p">(</span><span class="nb">locals</span><span class="p">())</span> |
| 119 |
</pre></div> |
| 120 |
</div> |
| 121 |
</section> |
| 122 |
<div class="clearer"></div> |
| 123 |
</div> |
| 124 |
</div> |
| 125 |
</div> |
| 126 |
</div> |
| 127 |
<div class="clearer"></div> |
| 128 |
</div> |
| 129 |
</div> |
| 130 |
<div class="footer-wrapper"> |
| 131 |
<div class="footer"> |
| 132 |
<div class="left"> |
| 133 |
<div aria-label="related navigaton" role="navigation"> |
| 134 |
<a href="01-lowpass-filters.html" title="01-lowpass-filters.py - The effect of the order of a filter.">previous</a> | |
| 135 |
<a href="03-complex-resonator.html" title="03-complex-resonator.py - Filtering by mean of a complex multiplication.">next</a> | |
| 136 |
<a href="../../genindex.html" title="General Index">index</a> |
| 137 |
</div> |
| 138 |
<div aria-label="source link" role="note"> |
| 139 |
</div> |
| 140 |
</div> |
| 141 |
<div class="right"> |
| 142 |
<div class="footer" role="contentinfo"> |
| 143 |
© Copyright 2021, Olivier Bélanger. |
| 144 |
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0. |
| 145 |
</div> |
| 146 |
</div> |
| 147 |
<div class="clearer"></div> |
| 148 |
</div> |
| 149 |
</div> |
| 150 |
</body> |
| 151 |
</html> |