What's the most basic implementation of resonant lowpass filter?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Hey, sorry if this has been asked before. Similar questions may have been asked, but I'm looking for something very specific:

1. Least possible code
2. Efficiency doesn't matter
3. Don't pre-calculate anything, that just adds to the amount of code, see #2.
4. Sound doesn't matter, it can sound like crap.
5. Probably needs to be 1 pole since 2 poles would require typing some more. :tu:

Thank you!

Post

Here's one without resonance, but it has cut->

streamin in;
streamout out;
streamin cut;
out = out * (1 - cut) + in * cut;

Post

That's good for parameter smoothing.... Is there a super-simple addition to that piece of code to make it a resonant lowpass? Or is a resonant filter just not possible to make so simply?

Post

Found this on musicdsp, I think this fits the bill:

http://www.musicdsp.org/showArchiveComm ... chiveID=29

Code: Select all

//set feedback amount given f and q between 0 and 1
fb = q + q/(1.0 - f);

//for each sample...
buf0 = buf0 + f * (in - buf0 + fb * (buf0 - buf1));
buf1 = buf1 + f * (buf0 - buf1);
out = buf1;

Post

http://www.elanhickler.com/_/simple_res_filter.wav

implemented in jesusonic, sounds fine to me.... is there a simple way to add nonlinearity / resonance overdrive / clipping? Maybe you don't need to type out the code but a short explanation would be sweet!

Post

Architeuthis wrote:Found this on musicdsp, I think this fits the bill:

http://www.musicdsp.org/showArchiveComm ... chiveID=29

Code: Select all

//set feedback amount given f and q between 0 and 1
fb = q + q/(1.0 - f);

//for each sample...
buf0 = buf0 + f * (in - buf0 + fb * (buf0 - buf1));
buf1 = buf1 + f * (buf0 - buf1);
out = buf1;
This actually sounds good, but any filter in this style tends to break at the edges, especially below 100hz.
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better? :(

Post

Architeuthis wrote:1. Least possible code
2. Efficiency doesn't matter
3. Don't pre-calculate anything, that just adds to the amount of code, see #2.
4. Sound doesn't matter, it can sound like crap.
5. Probably needs to be 1 pole since 2 poles would require typing some more. :tu:
!
1&2: "Least code possible" and "efficiency doesn't matter"...if it's least code it's probably optimized and efficient...

3: OK

4: Um...too vague...I suppose you don't want it to sound like such crap that it's not the resonant filter you asked for... :wink:

5: You need two poles to be resonant. You're not going to get up AND down with one pole/zero.

I can't imagine why you aren't just using a biquad, source code everywhere, and do whatever you feel like to minimize setting or initializing (too vague to answer that part—do you just want to hard code the coefficients? Go ahead. Otherwise, it's unclear how you want to trade off the ability to set it accurately versus code size).

Throw away parts you don't want:

http://www.earlevel.com/main/2012/11/26 ... urce-code/
My audio DSP blog: earlevel.com

Post

I just wanted the least code possible because I'm trying to understand how digital filters work... or... more specifically I want to know how simple you can get and still have the appearance of a filter... uhh... something like that :)

Post

Architeuthis wrote:I just wanted the least code possible because I'm trying to understand how digital filters work... or... more specifically I want to know how simple you can get and still have the appearance of a filter... uhh... something like that :)
OK, that makes sense...

So, you need a second-order filter to get a resonance, the simplest would be the direct forms. You can see the basic "direct form" structure here; the transposed direct form II is the best for floating point—the block diagram may look a little more complicated, but it isn't really (see my code that I linked to last time), but go with any form you like:

http://www.earlevel.com/main/2003/02/28/biquads/

As you can see, a very simple filter. Then you only need to calculate the coefficients. You want simple, so you could just set or hardcode them from the coefficient calculator:

http://www.earlevel.com/main/2013/10/13 ... ulator-v2/
My audio DSP blog: earlevel.com

Post

So there are problems in low frequency with biquads and high frequency with state variable.

How about this:

Code: Select all

out = out * (1 - cut) + in * cut;
what's the disadvantage? (ignore the fact it doesn't resonate and it's only 1 pole)

Post

Architeuthis wrote:So there are problems in low frequency with biquads and high frequency with state variable.
It's a quantization issue with the direct forms at low frequency, but much less so with floating point. Not an issue with audio, especially double precision, and the transposed DFII addresses a negative aspect of floating point. It is a big deal with fixed point, even at 24-bit by 56-bit accumulation (56k, for instance). With the Chamberlin state variable, the limit is absolute—you need to change the architecture (like Andy Simper's trapezoidal integrated version), oversample, or just don't go up against the limits.
How about this:

Code: Select all

out = out * (1 - cut) + in * cut;
what's the disadvantage? (ignore the fact it doesn't resonate and it's only 1 pole)
Well, you just said it—it is what it is. Here's my article on the one-pole, fwiw:

http://www.earlevel.com/main/2012/12/15 ... le-filter/
My audio DSP blog: earlevel.com

Post

Sorry mate,
filters are one of the areas I am hazy on,
so I can't put a q on it myself.
I think I will try and turn it into a hi pass though for my own learning purposes.

I think EarLevel has your tail though.

Yeah, it is usually used for smooth,
but when you can do that with applicability to a frequency like this it is handy.

Post

Code: Select all

// Coefficient computation
// Cutoff and reso are [0,128) integers
c = 0.5^[(128-Cutoff) / 16.0]
r = 0.5^[( 24+Reso)   / 16.0]

v0 = (1.0 - r*c)*v0 - c*v1 + c*input
v1 = (1.0 - r*c)*v1 + c*v0
No idea if it works though :oops:
No band limits, aliasing is the noise of freedom!

Post

Nielzie, it works. I used 0 to 150 for cutoff to get a bit more frequency. It explodes near the end of that, but a clipper on v0 solves it, just like a clipper on buf0 solves explosions for the previous resonant filter.
earlevel wrote:
Architeuthis wrote:what's the disadvantage? (ignore the fact it doesn't resonate and it's only 1 pole)
Well, you just said it—it is what it is. Here's my article on the one-pole, fwiw:

http://www.earlevel.com/main/2012/12/15 ... le-filter/
Nice, thank you! Hey EarLevel, are there any filter algorithms that use oscillators for resonance?

Post

Those algorithms which require clippers are far too common in DSP. It gets more complicated with feedback topology.

Post Reply

Return to “DSP and Plugin Development”