<?xml version="1.0" encoding="UTF-8"?>
<rss version='2.0' xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Urs Heckmann</title>
    <description>runs u-he</description>
    <link>https://urs.silvrback.com/feed</link>
    <atom:link href="https://urs.silvrback.com/feed" rel="self" type="application/rss+xml"/>
    <category domain="urs.silvrback.com">Content Management/Blog</category>
    <language>en-us</language>
      <pubDate>Sun, 12 Jun 2022 09:50:18 -0500</pubDate>
    <managingEditor>urs@aliencircuits.com (Urs Heckmann)</managingEditor>
      <item>
        <guid>https://urs.silvrback.com/clap#53720</guid>
          <pubDate>Sun, 12 Jun 2022 09:50:18 -0500</pubDate>
        <link>https://urs.silvrback.com/clap</link>
        <title>CLAP</title>
        <description>and why it&#39;s a great name for an audio plug-in ABI</description>
        <content:encoded><![CDATA[<p>Let&#39;s start with a little essay:</p>

<blockquote>
<p>“Since ancient times, clapping has always been deeply associated with music: From the rhythmic clapping at tribal gatherings or concerts, to the iconic clap sound in drum machines. But the ‘high five’ clap signifying shared achievement, closely related to the handshake signifying agreement or mutual appreciation, is another positive association. And that metaphor transcends the duality between host application and plug-in, which meet as equals in CLAP.”</p>
</blockquote>

<p>and let&#39;s round it off with the logo:</p>

<p><img alt="Silvrback blog image" class="sb_float_center" src="https://silvrback.s3.amazonaws.com/uploads/99b0f0a0-2c08-4af2-92bf-de1ba08cb0be/clap-full-logo-black-on-white_medium.png" /></p>

<p>The logo is basically an infinity symbol inside a triangle. The symbol is broken so it looks like a twisted band. Due to its position and tilt, the left half forms the letter “C” while the right half forms a “P” – the first and last letters of CLAP. Also, the two blobs in the middle resemble musical note symbols.</p>

<p><img alt="Silvrback blog image " class="sb_float_center" src="https://silvrback.s3.amazonaws.com/uploads/728b1d30-b6d4-4ab6-97c2-d1d4ea017e31/high%20five_medium.png" /></p>

<p>Then there’s the “high five” association of clapping, which I also see in the symmetry of c and p coming together – which is perhaps wishful thinking on my part: It may have worked better if human hands more closely resembled those of Lego minifigures.</p>

<p>Audio associations are also welcome: The sound of clapping easily associates with a plug-in snapping into the host, as if a virtual hardware cartridge was inserted into some kind of virtual console.</p>

<p>Lastly, clapping is also the foundation of applause, which I&#39;ll have for the whole team who worked more than a year on this.</p>
]]></content:encoded>
      </item>
      <item>
        <guid>https://urs.silvrback.com/specimen#23378</guid>
          <pubDate>Wed, 30 Mar 2016 05:12:36 -0500</pubDate>
        <link>https://urs.silvrback.com/specimen</link>
        <title>Specimen</title>
        <description>or why does my synth sound so different?</description>
        <content:encoded><![CDATA[<p>So I&#39;m sitting here, tuning my algorithms and parameters to do just what the circuits do in that little black box next to me. I&#39;d match some parameter ranges and curves, such as mapping cutoff frequency to its control voltage down to a few cents and then I&#39;d try some oscillator and envelope on that control voltage. Quite often when it gets to extreme settings I&#39;d have the feeling there&#39;s no way this model sounds like its analogue counterpart.</p>

<p>So then I turn to the analogue synth and set the knobs to similar settings. With extreme modulations though just touching a pot ever so slightly may alter the sound quite a bit. So it takes a minute or two until everything lines up and sure enough, the result may be closer than was expected. Which my colleagues next room notice by my giggles, or because I&#39;d call them to demonstrate the effect.</p>

<p>It so happens regularly that on the next day or maybe just a coffee break later, that match is gone. Suddenly the analogue synth doesn&#39;t do the same thing anymore and sometimes it isn&#39;t even possible to dial the same tone back in. It may be subtle, but it&#39;s an audible difference.</p>

<p>So there it is. No two analogue synths of the same make sound the same, and actually not even a single analogue synths sounds like itself at two different points in time.</p>

<p>What it means is, it doesn&#39;t really make much sense to do those AB comparisons between analogue hardware and softsynths that are supposed to model said hardware. They&#39;re not only controversial because of bias on both the maker&#39;s and listener&#39;s side, because of sound design skills, choice of settings or genre and numerous other possible reasons - they&#39;re most of all controversial because it&#39;s inherently unlikely, if not impossible, to create the definitive match. This alone leaves the door wide open for people to hear what they want to hear. I&#39;ll get back to that later.</p>

<p>So where do these differences stem from?</p>

<h3 id="climate">Climate</h3>

<p>First of all the most prominent candidate is temperature. Everybody knows that analogue synths need to warm up until the oscillators keep in tune. But not just the oscillators, also the filters, envelopes, amplifiers, glide circuit, modulation depth and whatever else are subject to change with temperature. Only, we&#39;re not as perceptive to these effects as we are for out of tune oscillators. But it&#39;s not just the pitch that drifts over time, it&#39;s also the sound.</p>

<p>In the same vein, climate also plays a role albeit a tiny one. Humidity and air pressure may have very little effect, but they do have some effect. Hey, a cent off is a cent off. I was told that the developers of Monark had a Winter model and a Summer one. I don&#39;t know which one was chosen in the end, I&#39;d be curious to know which one they thought sounded better.</p>

<p>In any case, when you start matching a digital model to an analogue synth in the morning in an office that - no offense - gets more humid over the day, it&#39;ll simply sound a tad different in the evening. Likewise if the afternoon sun comes round and you turn the aircon on...</p>

<p>With this in mind, it may make sense to record the synth in the parameter ranges you&#39;re trying to match, and verify how the beginning of your work matches up with the end. Keep track of your drift, and if it&#39;s bad, maybe model to a snapshot (samples...) entirely.</p>

<h3 id="its-in-the-parts">It&#39;s in the Parts</h3>

<p>Secondly, there are part tolerances that may create some difference between two specimen of the same synth. Most people have heard of matched transistors. It&#39;s often noted in schematics whether or not transistors must be matched. Which in turn means, there&#39;s a whole lot of them which are not matched. If they aren&#39;t matched on the board, chances are great they aren&#39;t matched among machines. Thus they&#39;re all a tad different, as are diodes, resistors, capacitors, knobs, faders and all the complex parts glued into chips as well.</p>

<p>Those aren&#39;t earthshattering differences, not much at all. But they add another dimension of subtlety to the aforementioned temperature drift. For instance, with our Pro One, when I dial resonance from start of self oscillation to maximum, the pitch of the self oscillating filter goes up by about a quarter tone. When I asked people to send audio samples from their Pro Ones, the pitch would usually go down towards maximum resonance, some as much as a third or fourth - as it happens in pretty much the majority of synths out there.</p>

<p>One can get datasheets for most parts that are used in vintage synthesizers. Not only do they contain formulae that are useful for modelling, but component tolerances are often quoted i.e. how much their properties are allowed to vary. If some resistance or so can be off by 5% it&#39;s sometimes quite surprising how some synths actually sound similar. Which brings up the next bit:</p>

<h3 id="your-service-technician-of-choice">Your Service Technician of Choice</h3>

<p>What&#39;s baked into part tolerances is usually compensated by little trimpots that let your synth repair man dial in correct frequencies and voltages in critical sections. While this is supposed to level out the differences between units it may also bear potential for sonic differences. These trimpots can also be used to change the sound in many ways, and like their counterparts on the front panel, a tad to the left or right may change the sound ever so slightly, yet audibly.</p>

<p>Furthermore when synths get serviced, parts may be exchanged. Some people have collected filter or envelope chips that match each other in order to equip polysynths with a set of chips that sound as similar as possible. Some people also modify some of the resistors and capacitors for smoother or more aggressive operation. That&#39;s not necessarily circuit bending, it should merely be seen as improving the hardware surgically.</p>

<p>So, analogue synth afficionados - including myself - will often point out that they made this or that sound on a freshly serviced device. This doesn&#39;t mean that all freshly serviced units will sound exactly the same. Not only because of everything else but also because the people who calibrate synths take their own pride in how they make that synth sound better than when it came fresh from the factory!</p>

<h3 id="age">Age</h3>

<p>But even a good service won&#39;t always bring back what&#39;s lost through wear and tear. It&#39;s not only the pots that become scratchy and all that, some parts simply break gradually over the years. Most classically it&#39;s electrolyte capacitors that run dry. But of course there&#39;s also dust, things getting loose or just old and squishy, who knows. A synth that has been locked in the basement for a decade will need service, there&#39;s no question about that.</p>

<p>Talking about age in a synth is a tad ambiguous. The more vintage the higher the price. But how likely is it that the sound of a synthesizer ages as well as a great port in a barrel? I secretly hope that the sound doesn&#39;t really change that much, not least if parts can be replaced. However Hans Zimmer told me that his newly built Moog Modular sounds a great deal better than the vintage wall at the back of his studio - same modules, 40+ years apart.</p>

<hr>

<p>Lo and behold, climate, parts, service and age are the main reasons of sonic differences between two specimen of the same synth, heck, even of a single synth. No-one expects their synth to sound the same before and after service, but why not also before and after lunch?</p>

<p>So, how can we ever do those popular AB tests again when we know all this?</p>
]]></content:encoded>
      </item>
      <item>
        <guid>https://urs.silvrback.com/one-pole-monster#22748</guid>
          <pubDate>Fri, 26 Feb 2016 01:47:27 -0600</pubDate>
        <link>https://urs.silvrback.com/one-pole-monster</link>
        <title>One Pole Monster</title>
        <description>going hands on with source code</description>
        <content:encoded><![CDATA[<p>That filter problem I&#39;ve laid out in my previous blog entry... let&#39;s solve it. Unfortunately that code section has become much larger than I expected, so I&#39;ve concentrated on the various methods to resolve that implicit non-linear equation with the tanh() term. As a drawback I&#39;ve thrown the highpass input and the inverting lowpass out. They&#39;re not overly difficult to put back in once the basic methods are understood. Hope that&#39;s okay :-)</p>

<p>Some clarification up front: I haven&#39;t invented any of this. It&#39;s all pretty standard stuff, but it might not all be very obvious to many people. I know it took me a while to grasp all of this, and it&#39;s a bit frightening to see it laid out so simple in front of me now. Hehehe, but wait for the next chapters. This one is still on the easy gear!</p>

<h3 id="re-cap">Re-Cap</h3>

<p>Here&#39;s your standard active lowpass filter, all naked and without the bloat:</p>

<p><img alt="Silvrback blog image" src="https://silvrback.s3.amazonaws.com/uploads/de4c760b-08d9-4750-87d3-9f176aa81db3/OnePoleLP_VCCS_large.png" /></p>

<p>This time I threw KCL right into the graph. Hence we get:</p>

<p>0 = Ivccs - Icap<br>
0 = g * ( tanh(Vin) - tanh(Vout) ) - Vout + s</p>

<p>which leads to following &quot;unsolvable&quot; equation:</p>

<p><strong>Vout = g * ( tanh(Vin) - tanh(Vout) ) + s</strong></p>

<p>To sum this up, the general problem we face is, if we want to compute Vout, we already need to know Vout. It&#39;s computed by itself. This article is about methods to do exactly that in the non-linear case, all forgoing psychic abilities. I&#39;ll be showing three kinds of basic techniques that are more or less fit to serve this purpose:</p>

<ul>
<li>Numerical Methods using iterative solvers</li>
<li>Analytical Methods using &quot;one step&quot; solutions</li>
<li>Lookup tables (yep, that works too)</li>
</ul>

<p>As a helpful addendum, if there weren&#39;t any tanh() terms, we&#39;d have a linear equation and we could solve for Vout, like this (which we&#39;ll use for various purposes later on):</p>

<p><strong>VoutLin = ( g * Vin + s ) / ( g + 1 )</strong></p>

<p>But first things first... something really helpful to get started with:</p>

<h3 id="making-that-estimate">Making That Estimate</h3>

<p>Every method to solve this kind of implicit non-linear filter works best with a proper estimate. That means, one way or another we &quot;guess&quot; the value of  Vout - or tanh(Vout).</p>

<p>The most well known - and probably the worst - estimate is using Vout from its previous computation. While you&#39;ll find this recommended often, particularly for iterative methods, it&#39;s not necessarily a good starting point. For a one pole filter it&#39;s probably better to use the linear estimate. That is, we simply compute VoutLin using the linear equation and start our iterative solver or our one step method from there.</p>

<p>If you look at the graphics in my Numerical Integration article, you&#39;ll notice that s (or iceq) is sort of in the middle between two Vouts. It&#39;s proven quite useful to use s[n+1] as an estimate for Vout[n+1]. But how about a linear estimate for s[n+2]? (Hint: It ain&#39;t good, but it may encourage experimenting, for instance you could blend it with something else)</p>

<p>Lastly, I mentioned lookup tables. If precision is key, calculating the initial estimate from a lookup table and running, say, a bisection solver will work wonders.</p>

<p>Here&#39;s our first piece of code:</p>
<div class="highlight"><pre><span></span>    <span class="c1">// member variables:</span>
    <span class="kt">float</span> <span class="n">Vout</span><span class="p">;</span>                 <span class="c1">// output</span>
    <span class="kt">float</span> <span class="n">s</span><span class="p">;</span>                    <span class="c1">// state</span>

    <span class="k">enum</span> <span class="n">EstimateSource</span>
    <span class="p">{</span>
        <span class="n">State</span><span class="p">,</span>                      <span class="c1">// use current state</span>
        <span class="n">PreviousVout</span><span class="p">,</span>               <span class="c1">// use z-1 of Vout</span>
        <span class="n">LinearStateEstimate</span><span class="p">,</span>        <span class="c1">// use linear estimate of future state</span>
        <span class="n">LinearVoutEstimate</span><span class="p">,</span>         <span class="c1">// use linear estimate of Vout</span>
        <span class="n">LookUpTable</span>                 <span class="c1">// use lookup table</span>
    <span class="p">};</span>

    <span class="kt">float</span> <span class="nf">getInitialEstimate</span><span class="p">(</span> <span class="kt">float</span> <span class="n">tanh_input</span><span class="p">,</span> <span class="n">EstimateSource</span> <span class="n">inSource</span> <span class="p">)</span>
    <span class="p">{</span>
        <span class="k">if</span><span class="p">(</span>     <span class="n">inSource</span> <span class="o">==</span> <span class="n">LinearStateEstimate</span> 
            <span class="o">||</span>  <span class="n">inSource</span> <span class="o">==</span> <span class="n">LinearVoutEstimate</span> <span class="p">)</span>
        <span class="p">{</span>
            <span class="c1">// run linear, update Vout</span>
            <span class="n">Vout</span> <span class="o">=</span> <span class="n">runOneStep</span><span class="p">(</span> <span class="n">tanh_input</span> <span class="p">);</span> 
        <span class="p">}</span>

        <span class="k">switch</span><span class="p">(</span> <span class="n">inSource</span> <span class="p">)</span>
        <span class="p">{</span>
            <span class="k">default</span><span class="o">:</span>
            <span class="k">case</span> <span class="nl">LinearVoutEstimate</span><span class="p">:</span>
            <span class="k">case</span> <span class="nl">PreviousVout</span><span class="p">:</span>              <span class="k">return</span> <span class="n">Vout</span><span class="p">;</span>
            <span class="k">case</span> <span class="nl">State</span><span class="p">:</span>                     <span class="k">return</span> <span class="n">s</span><span class="p">;</span>
            <span class="k">case</span> <span class="nl">LinearStateEstimate</span><span class="p">:</span>       <span class="k">return</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">Vout</span> <span class="o">-</span> <span class="n">s</span><span class="p">;</span>
            <span class="k">case</span> <span class="nl">LookUpTable</span><span class="p">:</span>               <span class="k">return</span> <span class="n">runLookUp</span><span class="p">(</span> <span class="n">tanh_input</span> <span class="p">);</span>
        <span class="p">}</span>
    <span class="p">}</span>
</pre></div>
<p>Note that, in order to avoid complaints of excessive use of tanh() I have written most functions so that whenever there&#39;s an input sample, it&#39;s already passed with tanh() applied.</p>

<p>Another convention right here: Methods that start with &quot;run...&quot; don&#39;t change the s, i.e. they don&#39;t update the filter state. They may however change Vout. Each run... method also has one or more accompanying &quot;tick...&quot; methods which also update the state. Reason is, some methods are called multiple times where the same state is required.</p>

<p>All cases I described are covered. Two cases use a linear estimate, for which they run the lowpass filter without any implicit tanh() term. The linear method is baked into the code for the OneStep  solution. The OneStep solution actually defaults to linear if nothing else is specified.</p>

<p>(if you&#39;re really picky, you could say that running a linear estimate or a table lookup first turns a one step method into a multi step one... you&#39;re right if you will, I won&#39;t be splitting hairs over this ;-)</p>

<h3 id="newtons-method">Newton&#39;s Method</h3>

<p>Here comes your CPU smoker right there. <a href="https://en.wikipedia.org/wiki/Newton%27s_method">Newton&#39;s Method</a> aka Newton Raphson etc. is an iterative method, a so called root finding algorithm. What latter have in common, they take a function f(x) and they find one or more zero crossings. They start at some point (estimate!), calculate the result - which is often far from 0 - and use that result to compute a new estimate that hopefully brings us closer to a 0. I really really really wish to not go any deeper about the maths, but if you click the link above it&#39;ll take you to Wikipedia.</p>

<p><em>Source Code! Yay!</em></p>
<div class="highlight"><pre><span></span><span class="cp">#define MAX_NEWTON_ERROR 0.000001</span>

<span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">Filter</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="kt">float</span> <span class="n">NewtonRaphson_Solver</span> <span class="p">(</span> <span class="kt">float</span><span class="o">&amp;</span> <span class="n">input</span><span class="p">,</span> <span class="kt">float</span><span class="o">&amp;</span> <span class="n">estimate</span><span class="p">,</span> <span class="n">Filter</span><span class="o">*</span> <span class="n">object</span> <span class="p">)</span>
<span class="p">{</span>
    <span class="kt">float</span> <span class="n">residue</span> <span class="o">=</span> <span class="n">object</span><span class="o">-&gt;</span><span class="n">runFilter</span><span class="p">(</span> <span class="n">input</span><span class="p">,</span> <span class="n">estimate</span> <span class="p">)</span> <span class="o">-</span> <span class="n">estimate</span><span class="p">;</span>

    <span class="kt">float</span> <span class="n">numIterations</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>

    <span class="k">while</span><span class="p">(</span> <span class="n">fabs</span><span class="p">(</span><span class="n">residue</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">MAX_NEWTON_ERROR</span> <span class="p">)</span>
    <span class="p">{</span>
            <span class="c1">// new_estimate = old_estimate - residue/derivative</span>

        <span class="kt">float</span> <span class="n">derivative</span> <span class="o">=</span> <span class="n">object</span><span class="o">-&gt;</span><span class="n">getDerivative</span><span class="p">();</span>
        <span class="n">estimate</span> <span class="o">=</span> <span class="n">estimate</span> <span class="o">-</span> <span class="n">residue</span><span class="o">/</span><span class="n">derivative</span><span class="p">;</span>

            <span class="c1">// get next residue</span>

        <span class="n">residue</span> <span class="o">=</span> <span class="n">object</span><span class="o">-&gt;</span><span class="n">runFilter</span><span class="p">(</span> <span class="n">input</span><span class="p">,</span> <span class="n">estimate</span> <span class="p">)</span> <span class="o">-</span> <span class="n">estimate</span><span class="p">;</span>

        <span class="n">numIterations</span><span class="o">++</span><span class="p">;</span>

        <span class="k">if</span><span class="p">(</span> <span class="n">numIterations</span> <span class="o">&gt;</span> <span class="mi">50</span> <span class="p">)</span>
        <span class="p">{</span>
            <span class="c1">// Debug_log(&quot;BUG?!? - iterations &gt; 50, returning 0 for safety reasons&quot;);</span>

            <span class="c1">// this can also happen if MAX_NEWTON_ERROR is too small,</span>
            <span class="c1">// e.g. due to truncation errors</span>

            <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="k">return</span> <span class="n">estimate</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>This is, in a nutshell, a Newton Solver that can be reused for any filter that implements two important methods, runFilter() and getDerivative(). It&#39;ll call former as often as it needs to bring the estimate closer to Vout. If Vout and the estimate are the same, we speak of &quot;convergence&quot;. In a typical scenario, convergence is reached at 2-5 iterations. At worst case (diode ladder filter..?) it should be about 3-8 iterations (but this also requires a <em>slightly</em> enhanced solver).</p>

<p>In-between each call to runFilter() it picks up the derivative of the filter equation at the last estimate. This sounds like a terrible idea, math and performance wise. However, if you refresh your memory for derivative rules (sum rule, chain rule, product rule) and if you keep in mind that the derivative of tanh(x) is just 1 - (tanh(x))<sup>2,</sup> it&#39;s actually not too bad. Check this out:</p>

<p><em>More Source Code! Yay!</em></p>
<div class="highlight"><pre><span></span><span class="c1">// ------------------------------ tanh&#39;(x) = 1 - tanh^2(x) ------------------------------------</span>

<span class="kr">inline</span> <span class="kt">float</span> <span class="nf">sech2_with_tanh</span><span class="p">(</span> <span class="kt">float</span> <span class="n">tanh_value</span> <span class="p">)</span>
<span class="p">{</span>
    <span class="k">return</span> <span class="mf">1.f</span> <span class="o">-</span> <span class="n">tanh_value</span> <span class="o">*</span> <span class="n">tanh_value</span><span class="p">;</span>
<span class="p">}</span>

<span class="kr">inline</span> <span class="kt">float</span> <span class="nf">tanh_derivative</span><span class="p">(</span> <span class="kt">float</span> <span class="n">x</span> <span class="p">)</span> <span class="c1">// not used, for edu purpose only</span>
<span class="p">{</span>
    <span class="k">return</span> <span class="n">sech2_with_tanh</span><span class="p">(</span> <span class="n">tanh</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>Those are two helper functions defined outside our filter class. The first one, sech2_with_tanh, will return the derivative or tanh_value  = tanh(x) from, well, tanh_value itself - like I said before, many methods and functions expect their input already tanh()&#39;d to avoid redundant calls to tanh()!</p>
<div class="highlight"><pre><span></span><span class="c1">// ------------------------------ Newton&#39;s Method ------------------------------------</span>

    <span class="c1">// member variable:</span>
    <span class="kt">float</span> <span class="n">tanh_result</span><span class="p">;</span> <span class="c1">// stores tanh(Vout) to reuse whenever applicable </span>

    <span class="kt">float</span> <span class="nf">runFilter</span><span class="p">(</span> <span class="kt">float</span> <span class="n">tanh_input</span> <span class="cm">/* tanh(input)</span> <span class="err">*/</span><span class="p">,</span> <span class="kt">float</span> <span class="n">v_estimate</span> <span class="p">)</span>
    <span class="p">{</span>
        <span class="n">tanh_result</span> <span class="o">=</span> <span class="n">tanh</span><span class="p">(</span> <span class="n">v_estimate</span> <span class="p">);</span>
        <span class="k">return</span> <span class="n">g</span> <span class="o">*</span> <span class="p">(</span> <span class="n">tanh_input</span> <span class="o">-</span> <span class="n">tanh_result</span> <span class="p">)</span> <span class="o">+</span> <span class="n">s</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">float</span> <span class="nf">getDerivative</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="c1">// tanh&#39;(x) = 1 - tanh^2(x)</span>
        <span class="k">return</span>  <span class="o">-</span><span class="n">g</span> <span class="o">*</span> <span class="n">sech2_with_tanh</span> <span class="p">(</span> <span class="n">tanh_result</span> <span class="p">)</span> <span class="o">-</span> <span class="mf">1.f</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">float</span> <span class="nf">tickNewtonRaphson</span><span class="p">(</span>    <span class="kt">float</span> <span class="n">input</span><span class="p">,</span> 
                                <span class="n">EstimateSource</span> <span class="n">inSource</span> 
                                <span class="o">=</span> <span class="n">LinearVoutEstimate</span> <span class="p">)</span>
    <span class="p">{</span>
        <span class="kt">float</span> <span class="n">tanh_input</span> <span class="o">=</span> <span class="n">tanh</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
        <span class="kt">float</span> <span class="n">estimate</span> <span class="o">=</span> <span class="n">getInitialEstimate</span><span class="p">(</span> <span class="n">tanh_input</span><span class="p">,</span> <span class="n">inSource</span> <span class="p">);</span>
        <span class="n">Vout</span> <span class="o">=</span> <span class="n">NewtonRaphson_Solver</span> <span class="p">(</span> <span class="n">tanh_input</span><span class="p">,</span> <span class="n">estimate</span><span class="p">,</span> <span class="k">this</span> <span class="p">);</span>
        <span class="n">updateState</span><span class="p">();</span>
        <span class="k">return</span> <span class="n">Vout</span><span class="p">;</span>
    <span class="p">}</span>
</pre></div>
<p>There you go. That&#39;s all there is. We tanhify our input, we pick up our initial estimate and then we let our filter visit the Newton-Raphson solver from the listing above. That&#39;s all it takes.</p>

<p>This is an utterly common and reliable way to solve implicit non-linear equations. Similar methods are <a href="https://en.wikipedia.org/wiki/Bisection_method">bisection method</a>, <a href="https://en.wikipedia.org/wiki/False_position_method">regula falsi</a>, <a href="https://en.wikipedia.org/wiki/Secant_method">secant method</a> and <a href="https://en.wikipedia.org/wiki/Brent%27s_method">Brent&#39;s method</a>. All have different advantages and drawbacks. Some are &quot;bracketed&quot; which means that the actual value remains between two estimates. This guarantees convergence and it guarantees a measurable accuracy. Other methods are ideal for vectorization or computationally inexpensive.</p>

<p>Newton&#39;s Method is certainly not the cheapest per iteration and it&#39;s also not always guaranteed to converge. In fact, it works best with a good initial estimate. But it&#39;s also the method that converges the fastest out of the lot. If it converges. For our filter (or any classic filter topology using tanh() distortion) it&#39;s guaranteed to converge. The only reason it may not is, when you drive the filter hard enough to loose the numerical floating point precision to have your residue below the maximum error. If you want to drive your filter hard, maybe adjust the maximum error dynamically to filter gain.</p>

<p>Another reason to promote Newton&#39;s Method: It can be put in vectorial form. That is, if we calculate a higher order filter with 2, 3...11 tanh() terms, we need to converge as many estimates with their respective results. And this, in other words, is why some filters can kill the CPU. But before we get there, let&#39;s have a look at the aternatives.</p>

<h3 id="cheap-out">Cheap Out!</h3>

<p>Now, I guess pretty much every developer reading this has gazed over Teemu Voipio aka Mystan&#39;s &quot;Cheap non-linear zero-delay filters&quot; <a href="http://www.kvraudio.com/forum/viewtopic.php?f=33&t=349859">over in this thread on KVR</a> . What&#39;s described there is probably one of the most influentual solutions to avoid the unit delay in both the outer loop and the Euler integration used in this infamous <a href="http://www.mirlab.org/conference_papers/International_Conference/DAFx%202004/Proc/P_061.pdf">transistor ladder model</a> published by Antti Huovilainen in 2004 (which btw. is a must read as it has been a great catalyst for Analogue Modeling).</p>

<p>The gist of this method is, it belongs to a category of methods that approximates the implicit non-linear equation with a single computation. I&#39;ve sometimes seen these solutions called &quot;one step methods&quot;, hence I&#39;m calling them that way. They are a subset of so-called &quot;analytical&quot; solutions because they use maths to &quot;up front&quot; to get to the result, i.e. the system&#39;s properties were analyzed and a fitting solution/workaround was found. In contrast, iterative solvers are called &quot;numerical&quot; solutions because they don&#39;t minimize the problem, they just math it out. As computers often do.</p>

<p>A word of caution: Neither of these methods can be as accurate as the numerical ones without additional computation. However, the audible difference might be neglectible if one considers that the CPU usage is not much higher than that of a filter calculated with Euler and unit delays. Up to your preference I&#39;d say ;-)</p>

<blockquote>
<p>Addendum: There was a discussion whether or not these methods are analytical. My stance is that while they approximate to the original, implicit system numerically, we could also look at these equations as a system on their own right - which was then solved analytically. Thoughts on that are welcome in the comments section below or <a href="http://www.kvraudio.com/forum/viewtopic.php?f=33&t=458066">on KVR</a>.</p>
</blockquote>

<p>Now, the actual solution I&#39;m presenting here is based on the concept that tanh(x) is replaced by a linear term, and quite literally so: What we do is, we replace tanh(x) - which is an s-shaped curve -  by a straight line a * x + b. Latter is <em>the</em> general formula for all straight lines that map x to y. Obviously, for each sample we&#39;d try to choose a and b so that our result would be the closest possible to the s-shaped tanh()-curve. Sounds logical? - Well, there&#39;s various methods to go by.</p>

<p>The interesting bit is that we can use the very same code for different ways to compute a and b. In fact we can set a = 1 and b = 0 to calculate our filter linearly, i.e. without the tanh() in the negative coupling. We can furthermore set a to tanh(s)/s and b to 0 to compute Mystan&#39;s method - which I call &quot;pivotal&quot; because our straight line that approximates tanh() pivots around the origin (x = 0/y=0).</p>

<p>The other method I&#39;ll show is one which I think has been used in many  products... but I&#39;m not so sure of that... It&#39;s essentially based on drawing a tangent to our estimated tanh(x), and then move our function result along that line. This is in many ways identical to Newton&#39;s Method, but wrapped into a single step method.</p>

<p><img alt="Silvrback blog image" src="https://silvrback.s3.amazonaws.com/uploads/ed474d6f-2a8f-42d9-878c-47951011d8e4/OneStepLinearTanh_large.png" /></p>

<p>As you can see, the pivotal method is a good &quot;allrounder&quot;. However, a fast rise in absolute value can go way out of bounds because the slope is always steeper as values run high.</p>

<p>The tangential method on the other hand is very good if the estimate is good, but then it might deviate even quicker than the pivotal method, particularly after a change of sign on a large jump.</p>

<p>I would love to provide for a full analysis of the two and I&#39;d also love to show more variations, e.g. such that take the statistical error of the estimate into account. But that really would make my head explode right now. So let&#39;s just cut it short and post some code:</p>
<div class="highlight"><pre><span></span><span class="c1">// ------------------------- linear / analytical methods --------------------------</span>

    <span class="k">enum</span> <span class="n">AnalyticalMethod</span>
    <span class="p">{</span>
        <span class="n">Linear</span><span class="p">,</span>         <span class="c1">// linear solution</span>
        <span class="n">Pivotal</span><span class="p">,</span>        <span class="c1">// Mystran&#39;s &quot;cheap&quot; method, using x=0 as pivot</span>
        <span class="n">Tangential</span>      <span class="c1">// Newton-like linearisation</span>
    <span class="p">};</span>

    <span class="kt">float</span> <span class="nf">runOneStep</span><span class="p">(</span>   <span class="kt">float</span> <span class="n">tanh_input</span> <span class="cm">/* tanh(input)</span> <span class="err">*/</span><span class="p">,</span> 
                        <span class="n">AnalyticalMethod</span> <span class="n">inMethod</span> <span class="o">=</span> <span class="n">Linear</span><span class="p">,</span>
                        <span class="n">EstimateSource</span> <span class="n">inSource</span> <span class="o">=</span> <span class="n">State</span> <span class="p">)</span>
    <span class="p">{</span>
        <span class="kt">float</span> <span class="n">b</span> <span class="o">=</span> <span class="mf">0.f</span><span class="p">;</span>
        <span class="kt">float</span> <span class="n">a</span> <span class="o">=</span> <span class="mf">1.f</span><span class="p">;</span>

        <span class="k">if</span><span class="p">(</span> <span class="n">inMethod</span> <span class="o">!=</span> <span class="n">Linear</span> <span class="p">)</span>
        <span class="p">{</span>
            <span class="c1">// base variable for tangent/angle</span>
            <span class="kt">float</span> <span class="n">base</span> <span class="o">=</span> <span class="n">getInitialEstimate</span><span class="p">(</span> <span class="n">tanh_input</span><span class="p">,</span> <span class="n">inSource</span> <span class="p">);</span> 

            <span class="kt">float</span> <span class="n">tBase</span> <span class="o">=</span> <span class="n">tanh</span><span class="p">(</span><span class="n">base</span><span class="p">);</span>

            <span class="k">switch</span><span class="p">(</span> <span class="n">inMethod</span> <span class="p">)</span>
            <span class="p">{</span>
                <span class="k">case</span> <span class="nl">Pivotal</span><span class="p">:</span>
                <span class="p">{</span>
                    <span class="n">a</span> <span class="o">=</span> <span class="n">base</span> <span class="o">==</span> <span class="mi">0</span> <span class="o">?</span> <span class="mf">1.f</span> <span class="o">:</span> <span class="n">tBase</span><span class="o">/</span><span class="n">base</span><span class="p">;</span>
                    <span class="k">break</span><span class="p">;</span>
                <span class="p">}</span>
                <span class="k">case</span> <span class="nl">Tangential</span><span class="p">:</span>
                <span class="p">{</span>
                    <span class="c1">// tanh&#39;(x) = 1 - tanh^2(x)</span>
                    <span class="n">a</span> <span class="o">=</span> <span class="n">sech2_with_tanh</span><span class="p">(</span> <span class="n">tBase</span> <span class="p">);</span>   
                    <span class="n">b</span> <span class="o">=</span> <span class="n">tBase</span> <span class="o">-</span> <span class="n">base</span> <span class="o">*</span> <span class="n">a</span><span class="p">;</span>
                    <span class="k">break</span><span class="p">;</span>
                <span class="p">}</span>
                <span class="c1">// surplus, but compilers may complaining if we don&#39;t keep it</span>
                <span class="k">case</span> <span class="nl">Linear</span><span class="p">:</span> <span class="p">;</span> 
            <span class="p">}</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="p">(</span> <span class="n">g</span> <span class="o">*</span> <span class="p">(</span> <span class="n">tanh_input</span> <span class="o">-</span> <span class="n">b</span> <span class="p">)</span> <span class="o">+</span> <span class="n">s</span> <span class="p">)</span> <span class="o">/</span> <span class="p">(</span> <span class="n">a</span> <span class="o">*</span> <span class="n">g</span> <span class="o">+</span> <span class="mi">1</span> <span class="p">);</span>
    <span class="p">}</span>
</pre></div>
<p>Yet again, this is it. That&#39;s all there is to it. Or is there? :-)</p>

<p>And again, like in the iterative method, we first pick up an estimate. Then we prepare a and b for whatever method out of Pivotal, Tangential and Linear we wish for. Then we compute Vout directly from that. Here&#39;s the path to get to the final equation:</p>

<p>Take original non-linear equation</p>

<p><strong>Vout = g * ( tanh(input) - tanh(Vout) ) + s</strong></p>

<p>Replace</p>

<p><strong>tanh(Vout) -&gt; a * Vout + b</strong></p>

<p>Such that</p>

<p><strong>Vin = tanh(input)</strong><br>
    <strong>Vout = g * ( Vin - (a * Vout + b) ) + s</strong></p>

<p>Now Vout can be isolated</p>

<p><strong>Vout = (Vin*g-b*g+s)/(a*g+1)</strong></p>

<p>Note: If a = 1 and b = 0 we get the linear form Vout = ( Vin * g + s)/( g + 1 )</p>

<p>For sake of completeness, let&#39;s post the tick functions for Pivotal, Tangential and truely Linear as previously mentioned and as announced elsewhere on KVR:</p>
<div class="highlight"><pre><span></span>    <span class="c1">// method originally described by Mystran on KVR</span>
    <span class="kt">float</span> <span class="nf">tickPivotal</span><span class="p">(</span> <span class="kt">float</span> <span class="n">input</span> <span class="p">)</span>    
    <span class="p">{</span>
        <span class="n">Vout</span> <span class="o">=</span>  <span class="n">runOneStep</span><span class="p">(</span> <span class="n">tanh</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="n">Pivotal</span><span class="p">,</span> <span class="n">State</span> <span class="p">);</span>
        <span class="n">updateState</span><span class="p">();</span>
        <span class="k">return</span> <span class="n">Vout</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="c1">// Newton&#39;s method in one step with linear estimate</span>
    <span class="kt">float</span> <span class="nf">tickTangential</span><span class="p">(</span> <span class="kt">float</span> <span class="n">input</span> <span class="p">)</span> 
    <span class="p">{</span>
        <span class="n">Vout</span> <span class="o">=</span>  <span class="n">runOneStep</span><span class="p">(</span> <span class="n">tanh</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="n">Tangential</span><span class="p">,</span> <span class="n">LinearVoutEstimate</span> <span class="p">);</span>
        <span class="n">updateState</span><span class="p">();</span>
        <span class="k">return</span> <span class="n">Vout</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="c1">// --------------------------- Linear Filter ---------------------------------</span>

    <span class="c1">// fully linear version, not shaping the input</span>
    <span class="kt">float</span> <span class="nf">tickLinear</span><span class="p">(</span> <span class="kt">float</span> <span class="n">input</span> <span class="p">)</span>
    <span class="p">{</span>
        <span class="n">Vout</span> <span class="o">=</span>  <span class="n">runOneStep</span><span class="p">(</span> <span class="n">input</span> <span class="p">);</span>
        <span class="n">updateState</span><span class="p">();</span>
        <span class="k">return</span> <span class="n">Vout</span><span class="p">;</span>
    <span class="p">}</span>
</pre></div>
<h3 id="intermezzo">Intermezzo</h3>

<p>A short note in-between. Both the iterative method as well as the one step method above seem very simple, and indeed they are - as long as we deal with one pole filters. But as soon as we go further, i.e. with higher order filters, things can become quite nasty. While one can keep iterative methods nice and clean for higher orders, doing a true &quot;vectorial Newton solver&quot; involves matrices and linear equation system solvers.</p>

<p>Therefore you&#39;ll often find a mix of different approaches right there in one filter algorithm. E.g. one can do an iterative solver for the overall feedback of a filter while keeping the single stages simple with a one step method. Also, you&#39;ll often hear of &quot;corrective steps&quot; which improve the accuracy of one step methods by a second or third computation - which basically also makes them iterative methods.</p>

<p>Everything is allowed - as long as it sounds good.</p>

<p>Anyhow, the focus of this article is teaching the differences of the basic popular methods. There&#39;s always a lot more that can be said and done, and I&#39;ll be happy to discuss a few more in-depth things later or elsewhere.</p>

<h3 id="look-it-up">Look! It! Up!</h3>

<p>Look Up Tables for filters <em>...whaaat?</em> - Being a bit of an ousider, this method only applies to one pole filters. There&#39;s a tiny chance to maybe do it for 2nd order filters, but you&#39;ll soon run out of memory. But who knows, maybe this method is great for FPGAs... or someone comes up with great equations that approximate the table solution in 17 dimensions...</p>

<p>The idea is this:</p>

<p>Out of all variables in Vout = g * ( tanh(Vin) - tanh(Vout) ) + s only Vout is unknown, all other values are available beforehand. So how do we get this into a lookup table?</p>

<p>If we rewrite the equation as</p>

<p>Vout = ( -g * tanh(Vout) ) + ( g * tanh(Vin) + s )</p>

<p>We can see that Vout depends on g itself and g * tanh(Vin) + s. Latter we can fully calculate into a single value:</p>

<p>State_gIn = g * tanh(Vin) + s;</p>

<p>Now we can create a lookup table for g in one dimension and State_gIn in another. We can thence use our Newton Raphson solver to populate that table with the correct values for Vout. Next thing you know, you can read Vout from g and State_gIn, without a single tanh() term involved :-) - furthermore, a considerably small table gives us a pretty good result from just bilinear interpolation alone (that is, linear interpolation in two dimensions as used in graphics software).</p>

<p>Hint: a table with 256 * 256 entries and linear interpolation gives us perfect results, but the table is quite big. We could always optimise it by cutting it in half and storing the sign bit of  State_gIn, but d&#39;oh... I haven&#39;t checked that out yet. Hint 2: Check out 3D plots. You might find ways to minimize the table in one dimension or the other.</p>

<p>Now, for some unexpected fun, here&#39;s a small table for a pretty good initial guess:</p>
<div class="highlight"><pre><span></span><span class="c1">// ------------------------ two dimensional lookup table ----------------------------</span>

    <span class="cp">#define numEntries 16</span>

    <span class="kt">float</span> <span class="n">table</span><span class="p">[</span> <span class="n">numEntries</span> <span class="p">][</span> <span class="n">numEntries</span> <span class="p">];</span>

    <span class="kt">float</span> <span class="n">minG</span><span class="p">,</span> <span class="n">maxG</span><span class="p">,</span> <span class="n">maxState_gIn</span><span class="p">;</span>

    <span class="kt">float</span> <span class="n">coeffMul</span><span class="p">,</span> <span class="n">maxState_gInMul</span><span class="p">;</span>

    <span class="kt">void</span> <span class="nf">createTable</span><span class="p">(</span> <span class="kt">float</span> <span class="n">inMinG</span><span class="p">,</span> <span class="kt">float</span> <span class="n">inMaxG</span><span class="p">,</span> <span class="kt">float</span> <span class="n">inMaxState_gIn</span> <span class="p">)</span>
    <span class="p">{</span>
        <span class="c1">// using numEntries-2 for boundaries so that </span>
        <span class="c1">// reading index+1 isn&#39;t out of bounds later</span>

        <span class="n">minG</span>            <span class="o">=</span> <span class="n">inMinG</span><span class="p">;</span>
        <span class="n">maxG</span>            <span class="o">=</span> <span class="n">inMaxG</span><span class="p">;</span>
        <span class="n">maxState_gIn</span>    <span class="o">=</span> <span class="n">inMaxState_gIn</span><span class="p">;</span>

        <span class="n">coeffMul</span>        <span class="o">=</span> <span class="p">((</span><span class="kt">float</span><span class="p">)(</span><span class="n">numEntries</span><span class="o">-</span><span class="mi">2</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">maxG</span> <span class="o">-</span> <span class="n">minG</span><span class="p">);</span>
        <span class="n">maxState_gInMul</span> <span class="o">=</span> <span class="p">((</span><span class="kt">float</span><span class="p">)(</span><span class="n">numEntries</span><span class="o">-</span><span class="mi">2</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="mf">2.f</span> <span class="o">*</span> <span class="n">maxState_gIn</span><span class="p">);</span>

        <span class="n">clear</span><span class="p">();</span>

        <span class="k">for</span><span class="p">(</span> <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">numEntries</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span> <span class="p">)</span>
        <span class="p">{</span>
            <span class="n">g</span> <span class="o">=</span> <span class="n">minG</span> <span class="o">+</span> <span class="p">(</span><span class="n">maxG</span> <span class="o">-</span> <span class="n">minG</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="n">i</span> <span class="o">/</span> <span class="kt">float</span><span class="p">(</span> <span class="n">numEntries</span> <span class="o">-</span> <span class="mi">2</span> <span class="p">);</span>

            <span class="k">for</span><span class="p">(</span> <span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="n">numEntries</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span> <span class="p">)</span>
            <span class="p">{</span>
                <span class="kt">float</span> <span class="n">State_gIn</span> <span class="o">=</span>   <span class="o">-</span><span class="n">maxState_gIn</span> 
                                    <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">maxState_gIn</span> <span class="o">*</span> <span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="n">k</span> 
                                    <span class="o">/</span> <span class="kt">float</span><span class="p">(</span> <span class="n">numEntries</span> <span class="o">-</span> <span class="mi">2</span> <span class="p">);</span>

                <span class="n">s</span> <span class="o">=</span> <span class="n">State_gIn</span><span class="p">;</span>

                <span class="n">table</span><span class="p">[</span> <span class="n">i</span> <span class="p">][</span> <span class="n">k</span> <span class="p">]</span> <span class="o">=</span> <span class="n">tickNewtonRaphson</span><span class="p">(</span> <span class="mf">0.f</span> <span class="p">);</span>
            <span class="p">}</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="kt">float</span> <span class="nf">runLookUp</span><span class="p">(</span> <span class="kt">float</span> <span class="n">tanh_input</span> <span class="cm">/* tanh(input)</span> <span class="err">*/</span> <span class="p">)</span>
    <span class="p">{</span>
        <span class="kt">float</span> <span class="n">inG</span> <span class="o">=</span> <span class="n">g</span><span class="p">;</span>

        <span class="k">if</span><span class="p">(</span> <span class="n">inG</span> <span class="o">&lt;</span> <span class="n">minG</span> <span class="p">)</span> <span class="k">return</span> <span class="n">s</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">inG</span> <span class="o">&gt;</span> <span class="n">maxG</span> <span class="p">)</span> <span class="n">inG</span> <span class="o">=</span> <span class="n">maxG</span><span class="p">;</span>

        <span class="kt">float</span> <span class="n">State_gIn</span> <span class="o">=</span> <span class="n">inG</span> <span class="o">*</span> <span class="n">tanh_input</span> <span class="o">+</span> <span class="n">s</span><span class="p">;</span>

        <span class="k">if</span><span class="p">(</span> <span class="n">State_gIn</span> <span class="o">&gt;</span>  <span class="n">maxState_gIn</span> <span class="p">)</span> <span class="n">State_gIn</span> <span class="o">=</span>  <span class="n">maxState_gIn</span><span class="p">;</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">State_gIn</span> <span class="o">&lt;</span> <span class="o">-</span><span class="n">maxState_gIn</span> <span class="p">)</span> <span class="n">State_gIn</span> <span class="o">=</span> <span class="o">-</span><span class="n">maxState_gIn</span><span class="p">;</span>

        <span class="n">State_gIn</span>               <span class="o">=</span> <span class="p">(</span><span class="n">State_gIn</span> <span class="o">+</span> <span class="n">maxState_gIn</span><span class="p">)</span> <span class="o">*</span> <span class="n">maxState_gInMul</span><span class="p">;</span>
        <span class="n">inG</span>                     <span class="o">=</span> <span class="p">(</span><span class="n">inG</span>       <span class="o">-</span> <span class="n">minG</span>        <span class="p">)</span> <span class="o">*</span> <span class="n">coeffMul</span><span class="p">;</span>

        <span class="kt">int</span> <span class="n">State_gIn_index</span>     <span class="o">=</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">State_gIn</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">inG_index</span>           <span class="o">=</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">inG</span><span class="p">;</span>

        <span class="kt">float</span> <span class="n">State_gIn_fract</span>   <span class="o">=</span> <span class="n">State_gIn</span> <span class="o">-</span> <span class="n">floorf</span><span class="p">(</span> <span class="n">State_gIn</span> <span class="p">);</span>
        <span class="kt">float</span> <span class="n">inG_fract</span>         <span class="o">=</span> <span class="n">inG</span>       <span class="o">-</span> <span class="n">floorf</span><span class="p">(</span> <span class="n">inG</span> <span class="p">);</span>

        <span class="kt">float</span> <span class="n">ingLowSL</span>          <span class="o">=</span> <span class="n">table</span><span class="p">[</span> <span class="n">inG_index</span>    <span class="p">][</span> <span class="n">State_gIn_index</span>    <span class="p">];</span>
        <span class="kt">float</span> <span class="n">ingLowSH</span>          <span class="o">=</span> <span class="n">table</span><span class="p">[</span> <span class="n">inG_index</span>    <span class="p">][</span> <span class="n">State_gIn_index</span> <span class="o">+</span><span class="mi">1</span> <span class="p">];</span>
        <span class="kt">float</span> <span class="n">ingHighSL</span>         <span class="o">=</span> <span class="n">table</span><span class="p">[</span> <span class="n">inG_index</span> <span class="o">+</span><span class="mi">1</span> <span class="p">][</span> <span class="n">State_gIn_index</span>    <span class="p">];</span>
        <span class="kt">float</span> <span class="n">ingHighSH</span>         <span class="o">=</span> <span class="n">table</span><span class="p">[</span> <span class="n">inG_index</span> <span class="o">+</span><span class="mi">1</span> <span class="p">][</span> <span class="n">State_gIn_index</span> <span class="o">+</span><span class="mi">1</span> <span class="p">];</span>

        <span class="kt">float</span> <span class="n">ingLow</span>        <span class="o">=</span>   <span class="n">ingLowSL</span>  
                                <span class="o">+</span> <span class="n">State_gIn_fract</span> <span class="o">*</span> <span class="p">(</span> <span class="n">ingLowSH</span>  <span class="o">-</span> <span class="n">ingLowSL</span>  <span class="p">);</span>
        <span class="kt">float</span> <span class="n">ingHigh</span>       <span class="o">=</span>   <span class="n">ingHighSL</span> 
                                <span class="o">+</span> <span class="n">State_gIn_fract</span> <span class="o">*</span> <span class="p">(</span> <span class="n">ingHighSH</span> <span class="o">-</span> <span class="n">ingHighSL</span> <span class="p">);</span>

        <span class="k">return</span> <span class="n">ingLow</span> <span class="o">+</span> <span class="n">inG_fract</span> <span class="o">*</span> <span class="p">(</span> <span class="n">ingHigh</span> <span class="o">-</span> <span class="n">ingLow</span> <span class="p">);</span>
    <span class="p">}</span>

    <span class="kt">float</span> <span class="nf">tickLookup</span><span class="p">(</span> <span class="kt">float</span> <span class="n">input</span> <span class="p">)</span>
    <span class="p">{</span>
        <span class="n">Vout</span> <span class="o">=</span> <span class="n">runLookUp</span><span class="p">(</span> <span class="n">tanh</span><span class="p">(</span><span class="n">input</span><span class="p">)</span> <span class="p">);</span>
        <span class="n">updateState</span><span class="p">();</span>

        <span class="k">return</span> <span class="n">Vout</span><span class="p">;</span>
    <span class="p">}</span>
</pre></div>
<p>Ok, it looks a bit more messy than the other solutions, but maybe you can customize it to your needs. Which brings up the final chapter for today:</p>

<h3 id="explore">Explore!</h3>

<p>I doubt that too many people have ever before lost so many words on such a simple lowpass filter. It&#39;s for a good cause though, because I hope I could illustrate some of the methods me and others are so conveniently mentioning in the forums all the time. I hope that people will put this to good use and start exploring the possibilities. For instance, adapting the one step method for the one pole lowpass with an inverting input is a bit of a challenge.</p>

<p>To be honest, I&#39;d much rather post challenges than recipes that one could just copy and paste. There&#39;s a lot of challenge underlying these technologies. Making them fast, making them more accurate, adapting them for new filter types. It&#39;s endless. And also of course, there are more methods - but you gotta start somewhere...</p>

<p>Anyhow, my vacation is almost over, I doubt I&#39;ll have time to post the next step anytime soon. Which might include bit about a higher order filter and/or the vectorial Newton method. Which is then also how we relate the principles laid out so far to actual crcuit simulators. or maybe I do another piece about one pole filters that don&#39;t have tanh distortion... We&#39;ll see...</p>

<p>Lastly, here&#39;s the full filter class and utility functions or you to work with. Compiles here, should compile for you too...</p>

<p><a href="http://www.u-he.com/downloads/UrsBlog/onePoleLowpass.h">http://www.u-he.com/downloads/UrsBlog/onePoleLowpass.h</a> </p>

<p>Enjoy,</p>

<ul>
<li>Urs</li>
</ul>

<hr>

<p>Update Feb 27th 2016: The same oversight happened here as in the previous article - I messed up the OTA voltage to current equation. Hence I also changed the schematic and equations in this article to a general concept of a Voltage Controlled Current Source. As promised, I&#39;ll try to add a solution for the proper OTA-based one pole filter some time. Also, I added some thoughts on the analytical vs. numerical debate (which slightly confused me as well ;-)</p>
]]></content:encoded>
      </item>
  </channel>
</rss>