Accelerate/vDSP Biquad filter

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

niarn wrote:
earlevel wrote: And I didn't say it was "bad", I said use Andy's instead. It's better.
But from your perspective how is it better? What can you do with the other svf that you can't do with the chamberlin svf?
The Chamberlin SVF blows up when the cutoff is greater than 1/6th the sampling rate. If you don't plan on using higher cutoffs, or you don't plan on having audio rate modulation, it's just fine.

Biquads are fine, too, if you are using fixed filters, and you pay attention to the edge cases where biquads don't work that well. I have a few shelves of books in my bookshelves that discuss biquad design, as part of a huge legacy of DSP literature. The filters that Urs/Z1202/Andy are discussing are tailor made for the unique needs of music DSP (i.e. filters that reproduce the behavior of specific analog circuits, that can be modulated at audio rates, that can be swept without having weird artifacts, etc.), but these don't invalidate 40+ years of digital filter theory.

Sean Costello

Post

niarn wrote:
earlevel wrote: And I didn't say it was "bad", I said use Andy's instead. It's better.
But from your perspective how is it better? What can you do with the other svf that you can't do with the chamberlin svf? I'm just curious, it is not that I know some stuff that you don't know. I'm only here to learn.
earlevel wrote: It's a legacy design from Hal Chamberlin. If I misrepresented it, I'll fix it. If it's that the design could be better, I won't fix it. :wink:
I'm not questioning the design of the structure but I just wonder why you calculate the parameters f and q the way you do because they don't give you the responses that you want. Or is it intentional that you want 'incorrect' responses? Okay, I'm slightly confused about that. I just wanted to point out to you that if you use the expressions for f and q as provided 5-7 posts above this one you get responses identical to that other svf that you like. And if you use those expressions how is the other svf better than the chamberlin svf then?
OK, thanks for explaining...

Tuning is not the problem. But some comments on tuning: First, did Hal "get it wrong"? This was circa 1980, a sine lookup is required. Now look at your equations. Second, how far off is it? Would a synth user—of a 12 dB/oct filter that would not otherwise generate a stable, playable sine wave over the length of a keyboard without some work—be able to hear the mistuning? And certainly not when used as a filter. Third, how much more accurate was the tuning of analog state variable filters in synthesizers that used them? (Guessing "less".)

The biggest drawback of the filter: With either set of tuning equations, the Chamberlin digital state variable goes to hell somewhere in the neighborhood of f = 1.0, so if you're using it for audio range, it has to be oversampled by at least 2x.

For instance, I could sweep Andy's filter—no changes from the pdf—from 20 kHz to 80 Hz, sound good, like a synth. The same sweep blows up and yields no audio output (blows to big numbers in a few samples, then -inf, +inf recirculate to ensure output is screwed thereafter) with the Chamberlin. But if I drop the top of the sweep to, say, 8500 Hz, it sounds good fine.

There are other reasons, but that's reason enough.
My audio DSP blog: earlevel.com

Post

earlevel wrote: Tuning is not the problem. But some comments on tuning: First, did Hal "get it wrong"? This was circa 1980, a sine lookup is required. Now look at your equations. Second, how far off is it? Would a synth user—of a 12 dB/oct filter that would not otherwise generate a stable, playable sine wave over the length of a keyboard without some work—be able to hear the mistuning? And certainly not when used as a filter. Third, how much more accurate was the tuning of analog state variable filters in synthesizers that used them? (Guessing "less".)

The biggest drawback of the filter: With either set of tuning equations, the Chamberlin digital state variable goes to hell somewhere in the neighborhood of f = 1.0, so if you're using it for audio range, it has to be oversampled by at least 2x.
If you look in the Chamberlin book, the different in the tuning between the method that uses sin() and the method that leaves it out is very minimal, until the frequency gets fairly close to fs/6. Which is where things blow up. For something like a filter swept by an envelope follower, this would make no difference whatsoever, and the more efficient calculations could be used.

Post

valhallasound wrote:If you look in the Chamberlin book, the different in the tuning between the method that uses sin() and the method that leaves it out is very minimal, until the frequency gets fairly close to fs/6. Which is where things blow up. For something like a filter swept by an envelope follower, this would make no difference whatsoever, and the more efficient calculations could be used.
Right, fs/6 yields f = 1.0—I referred to it that way because the problem is terribly obvious with a glance at the diagram. It was a really cheap filter, even for the limited computing power back then, for cases where the range was acceptable.

Niarn's calculations make a larger difference, by fs/6, than do the two equations that Chamberlin gave, so I'm wondering...but not too much :wink:
My audio DSP blog: earlevel.com

Post

niarn wrote:
JCJR wrote: Re the tuning instability, I was looking up the chamberlin parameter setting formula and discovered that Nigel Redmond wrote a good description a few years ago--

http://www.earlevel.com/main/2003/03/02 ... le-filter/

In the first few paragraphs, he lists the formula and it is easy to see that the frequency coff will exceed 1.0 at a frequency far short of nyquist.

Edit: Nigel also mentions the easiest way to oversample the chamberlin svf, processing each sample multiple times. This can work good for simple uses of the filter. For instance tapping only the lowpass output for an auto-waa effect. But this simple oversample messes up even further the relationship between lp, bp, and hp. So far as I could tell, it isn't good enough to be able to precisely use all outputs simultaneously. I'm not being critical of what Nigel wrote. Just saying that repeat sample oversampling doesn't work good enough for some things that one might want to do with the svf. Maybe help someone avoid spending a few hours finding this out. :)
Hi JCJR
I just read the article and I can easily understand that there is a problem if the coefficients are calculated in the way as described on that page. I can't seem to find any source describing where the expression for the f parameter comes from. Also on the page is written "The only way around this is to oversample.".

if the coefficients are calculated this way

Code: Select all

k = 1/Q;
g = tan(pi*fc/fs);
p = sqrt(1 + g^2 + g*k)
f = 2*g / p
q = k / p
wouldn't that solve the (time-varying) instability problem?
I was wondering how long it would take for someone else would cotton on to this method :)

I sorted this out some time ago and wanted to publish a paper on it but haven't had time. It also works for the Sallen Key filter, but things get more difficult with cascade filters as things aren't nearly so neat.

For everyone else here is a pdf going into the details of how to solve this stuff for the Low pass output, I've removed the high, band, notch, and peak responses, but they are all possible as well with not too much extra working, as is summing the outputs like you can with the trapezoidal version:

https://cytomic.com/files/dsp/SvfMatchingFeToTr.pdf

Of interest in this technical paper is that multiple forward Euler variations are possible, each with a different damping limit and different numerical properties when non-linearities are introduced.
Last edited by andy-cytomic on Thu Feb 04, 2016 6:05 am, edited 1 time in total.
The Glue, The Drop, The Scream - www.cytomic.com

Post

niarn wrote:
earlevel wrote:Don't implement the Chamberlin structure—see Andy's paper:

http://cytomic.com/files/dsp/SvfLinearT ... mised2.pdf
I assume you are the author of this page: http://www.earlevel.com/main/2003/03/02 ... le-filter/

As I tried to indicate above the design equations on that page are wrong! No wonder you think it is bad. Maybe you should consider updating your page as it is quite misleading.

If you use the design equations above the SVF on your page and the SVF you linked to provides the exact same output and the exact same impulse response for the LTI case (meaning not screwing with the coefficients). Both SVFs realize frequency responses that are BLTs of corresponding analong transfer functions. If the design equations were wrong for the SVF you linked to you would also label that as bad I assume.

The tricky thing is what happens when the coefficients are modulated. For this case the two SVFs do not provide the exact same output. So is the difference audible? if it is audible is it then for the better of the worse? (or is it very subjective)

As you can see from this response
Z1202 wrote: Why BLT ZDF SVF is so fantastic has been explicitly answered before. ..... With a number of tricks probably naive SVF transfer function can be tweaked into a BLT one but a. that's quite tricky and involved mathematically and b. still raises some questions regarding the time-varying behavior. BLT ZDF SVF doesn't have any of the mentioned issues, thereby combining the benefits of both approaches.
the only real question left is in what way the two SVFs differ for the case where the coefficients are being modulated?
Not probably, but definitely you can match multiple different forward Euler SVF structures (and other 2 pole filters like the Sallen Key) to match the amplitude response of the trapezoidal exactly in the LTI case. Once in a forward Euler form it is easier to add non-linearities and get a decent result, although these won't be implicitly solved so sound quite different when driven and at high cutoffs.

As for the time varying results you can match these more closely by filtering the cutoff gain and damping factors with FIR averaging filters, the results are pretty good, but solving the full non-linear implicit equations gives a much better sound, and only takes a little more cpu when done right, since all the non-linearities can be computed in parallel, which is quite a saving.
The Glue, The Drop, The Scream - www.cytomic.com

Post

earlevel wrote:
niarn wrote:
earlevel wrote: And I didn't say it was "bad", I said use Andy's instead. It's better.
But from your perspective how is it better? What can you do with the other svf that you can't do with the chamberlin svf? I'm just curious, it is not that I know some stuff that you don't know. I'm only here to learn.
earlevel wrote: It's a legacy design from Hal Chamberlin. If I misrepresented it, I'll fix it. If it's that the design could be better, I won't fix it. :wink:
I'm not questioning the design of the structure but I just wonder why you calculate the parameters f and q the way you do because they don't give you the responses that you want. Or is it intentional that you want 'incorrect' responses? Okay, I'm slightly confused about that. I just wanted to point out to you that if you use the expressions for f and q as provided 5-7 posts above this one you get responses identical to that other svf that you like. And if you use those expressions how is the other svf better than the chamberlin svf then?
OK, thanks for explaining...
Nigel was just outlining the difference equations and coefficient calculation first published by Chamberlin, he's not saying - "this is the best filter to use".
earlevel wrote:Tuning is not the problem. But some comments on tuning: First, did Hal "get it wrong"? This was circa 1980, a sine lookup is required. Now look at your equations. Second, how far off is it? Would a synth user—of a 12 dB/oct filter that would not otherwise generate a stable, playable sine wave over the length of a keyboard without some work—be able to hear the mistuning? And certainly not when used as a filter. Third, how much more accurate was the tuning of analog state variable filters in synthesizers that used them? (Guessing "less".)
If damping is zero then you do get a sin for the warping of cutoff as chamberlin suggested, but for other values of damping it doesn't work:

Code: Select all

w = 2*pi*cutoff/samplerate
g2 = sin(w/2)/cos(w/2)
d2 = 0
g = 2*g2/(1 + g2*g2)
  = 2*sin(w/2)/cos(w/2)  /  sqrt (1 + sin(w/2)^2/cos(w/2)^2)
  = 2*sin(w/2)/cos(w/2) / (1/cos(w/2))
  = 2*sin(w/2)
earlevel wrote: The biggest drawback of the filter: With either set of tuning equations, the Chamberlin digital state variable goes to hell somewhere in the neighborhood of f = 1.0, so if you're using it for audio range, it has to be oversampled by at least 2x.

For instance, I could sweep Andy's filter—no changes from the pdf—from 20 kHz to 80 Hz, sound good, like a synth. The same sweep blows up and yields no audio output (blows to big numbers in a few samples, then -inf, +inf recirculate to ensure output is screwed thereafter) with the Chamberlin. But if I drop the top of the sweep to, say, 8500 Hz, it sounds good fine.

There are other reasons, but that's reason enough.
Warping of the FE, along with some added FIR averaging / gain adjustment gives the same response as the TR version in the LTI case across the entire 2d space of values of cutoff and damping from dc up to nyquist, and pretty close even when modulated if you also average the gain factor and damping values - when non-linearities are added then the behaviour varies more greatly - this warping makes it a semi-implicit type method, but it's not fully implicit (hey what do you expect when you cut corners like this!!)

https://cytomic.com/files/dsp/SvfMatchingFeToTr.pdf

(edit: removed some typos)
The Glue, The Drop, The Scream - www.cytomic.com

Post

Good info—thanks, Andy.
My audio DSP blog: earlevel.com

Post

earlevel wrote:
valhallasound wrote:If you look in the Chamberlin book, the different in the tuning between the method that uses sin() and the method that leaves it out is very minimal, until the frequency gets fairly close to fs/6. Which is where things blow up. For something like a filter swept by an envelope follower, this would make no difference whatsoever, and the more efficient calculations could be used.
Right, fs/6 yields f = 1.0—I referred to it that way because the problem is terribly obvious with a glance at the diagram. It was a really cheap filter, even for the limited computing power back then, for cases where the range was acceptable.

Niarn's calculations make a larger difference, by fs/6, than do the two equations that Chamberlin gave, so I'm wondering...but not too much :wink:
Nothing should really prevent us from doing a sweep from 80 Hz to 20 kHz with the Chamberlin svf. We just need to understand what we are doing :party:
Let us consider the most interesting case of complex poles. Then the two things you need to check is that f < 2 and fq < 1. If this is not the case the chamberlin svf is not stable. So you can fire up f all the way up to 2 but just take into account that fq < 1. In the Chamberlin svf the f parameter has a quite nice geometric interpretation, it is the distance from the complex poles to the point (1,0) in the complex plane. This makes is clear that f can't be increased above 2.

You can make a very small change to the chamberlin svf as explained in here http://www.dafx.ca/proceedings/papers/p_053.pdf
such that fq is treated as one parameter. Then you can adjust f from 0 to 2 without having to adjust the other parameter in order to not push the poles too far.
earlevel wrote:For instance, I could sweep Andy's filter—no changes from the pdf—from 20 kHz to 80 Hz, sound good, like a synth. The same sweep blows up and yields no audio output (blows to big numbers in a few samples, then -inf, +inf recirculate to ensure output is screwed thereafter) with the Chamberlin. But if I drop the top of the sweep to, say, 8500 Hz, it sounds good fine.

There are other reasons, but that's reason enough.
Let's pretend we have the sweep issue fixed as explained above can you give just one more reason?

Post

earlevel wrote:Good info—thanks, Andy.
You're welcome! I've also updated the pdf to include the output mixing SVF, so you can mix all outputs together in any amount to get notch / peak / bells etc with a damping limit of 0, 1, or 2 (i.e. when the cutoff goes high this is what the damping ends up at).

Please let me know if I made any mistakes in the mixing version as it is newly edited together from older material to make it a bit easier to see what is going on:

https://cytomic.com/files/dsp/SvfMatchingFeToTr.pdf
The Glue, The Drop, The Scream - www.cytomic.com

Post

niarn wrote:
earlevel wrote:For instance, I could sweep Andy's filter—no changes from the pdf—from 20 kHz to 80 Hz, sound good, like a synth. The same sweep blows up and yields no audio output (blows to big numbers in a few samples, then -inf, +inf recirculate to ensure output is screwed thereafter) with the Chamberlin. But if I drop the top of the sweep to, say, 8500 Hz, it sounds good fine.

There are other reasons, but that's reason enough.
Let's pretend we have the sweep issue fixed as explained above can you give just one more reason?
It depends on the application, so what do you want to use it for?

Some reasons to use the full trapezoidal implicit version over a warped / corrected forward euler:

1) all sin computation of coefficients and excellent numerical performance which is good for accuracy in critical engineering applications
2) correct time varying behaviour - the previous contributions from cutoff gain and damping are included in the state variables giving accurate time varying behaviour, so it sounds really good even with large amounts of fm
3) reasonably low cpu count if you want to mix the outputs - the warped forward Euler versions op count increases if you want all the outputs
4) although it's easier to add non-linearities to the warped / corrected forward euler they don't sound as good, you don't quite get the right self FM behaviour when it drives because it's not being solved implicitly. A full implicit non-linear solver allows for more parallel execution of the non-linearities, so only ends up costing a tiny bit more than the semi-implicit warped /corrected forward euler version, and it ends up that evaluation of the non-linearities dominates the cpu
The Glue, The Drop, The Scream - www.cytomic.com

Post

andy-cytomic wrote:
niarn wrote:
earlevel wrote:Don't implement the Chamberlin structure—see Andy's paper:

http://cytomic.com/files/dsp/SvfLinearT ... mised2.pdf
I assume you are the author of this page: http://www.earlevel.com/main/2003/03/02 ... le-filter/

As I tried to indicate above the design equations on that page are wrong! No wonder you think it is bad. Maybe you should consider updating your page as it is quite misleading.

If you use the design equations above the SVF on your page and the SVF you linked to provides the exact same output and the exact same impulse response for the LTI case (meaning not screwing with the coefficients). Both SVFs realize frequency responses that are BLTs of corresponding analong transfer functions. If the design equations were wrong for the SVF you linked to you would also label that as bad I assume.

The tricky thing is what happens when the coefficients are modulated. For this case the two SVFs do not provide the exact same output. So is the difference audible? if it is audible is it then for the better of the worse? (or is it very subjective)

As you can see from this response
Z1202 wrote: Why BLT ZDF SVF is so fantastic has been explicitly answered before. ..... With a number of tricks probably naive SVF transfer function can be tweaked into a BLT one but a. that's quite tricky and involved mathematically and b. still raises some questions regarding the time-varying behavior. BLT ZDF SVF doesn't have any of the mentioned issues, thereby combining the benefits of both approaches.
the only real question left is in what way the two SVFs differ for the case where the coefficients are being modulated?
Not probably, but definitely you can match multiple different forward Euler SVF structures (and other 2 pole filters like the Sallen Key) to match the amplitude response of the trapezoidal exactly in the LTI case. Once in a forward Euler form it is easier to add non-linearities and get a decent result, although these won't be implicitly solved so sound quite different when driven and at high cutoffs.
Do you mean inserting non-linearities into the svf itself? like some saturation on the states? because this is what is happening in the analog svf?

Post

niacin wrote:...Let's pretend we have the sweep issue fixed as explained above can you give just one more reason?
That's cool thanks niarn, thanks for the notes and discussion. Yes, I have seen the modified Chamberlin structures in the past. Please don't lose sight of what I said. Jim suggested the Chamberlin structure—and from my site in particular. Doing my civic duty, I said please don't use it, use Andy's instead—a simple, and well-described alternative.

The Chamberlin I described there in 2003 is a simple and useful filter from a couple of decades before that. But I've never presented a synthesizer filter on my site, and I don't want that omission to imply that another filter I have there is the best to use. Note I've never put up code for it unlike some other synthesizer components. Similarly, I have a lot of words on direct form biquads, including code and coefficient calculators, and the reasons are not because they are the best filter to use in all cases—just a well-known filter that every DSP'er should have in his toolkit and use when appropriate.

I guess to answer your question above, one more reason: I prefer telling someone (who needs a starting point—obviously the suggestion is not to you) to use Andy's svf and not my site's Chamberlin article svf because Andy derives and describes his filter, gives code for it, and it works. So I don't have to modify the one on my site to make it work well and write and article about it. Bear in mind that I'm not writing a synthesizer. I'm very interested in reading about such techniques, but I work seven days a week (which is why my site is so sadly neglected while partially completed articles and videos sit waiting), not designing software synthesizers (but doing other DSP things part of that time, glad to say).

I think you're asking why I'm not pursuing various things to make a good filter, so I want you to know I'm simple not making any filter at all at this time (but still reading for when I need to). :wink: (sorry for being so wordy, want to get to sleep and don't have time to edit)
My audio DSP blog: earlevel.com

Post

niarn wrote:Do you mean inserting non-linearities into the svf itself? like some saturation on the states? because this is what is happening in the analog svf?
Analog doesn't saturate the states as such, but saturates various voltages and currents in the circuit, which are then integrated to form the states. There are such things as non-linear capacitors as well, such as diffusion capacitors, but in most analog filter circuits the capacitors are pretty well linear, perhaps with some serial and parallel resistances.
The Glue, The Drop, The Scream - www.cytomic.com

Post

andy-cytomic wrote:
niarn wrote:Do you mean inserting non-linearities into the svf itself? like some saturation on the states? because this is what is happening in the analog svf?
Analog doesn't saturate the states as such, but saturates various voltages and currents in the circuit, which are then integrated to form the states. There are such things as non-linear capacitors as well, such as diffusion capacitors, but in most analog filter circuits the capacitors are pretty well linear, perhaps with some serial and parallel resistances.
At some points the state will saturate as well. E.g. if a state is capacitor voltage, it can't grow infinitely and normally will be limited by something like the power supply voltage. Whether this threshold can be reached practically depends on the circuit.

Post Reply

Return to “DSP and Plugin Development”