7 posts

Page

**1**of**1**- KVRer
- 5 posts since 9 May, 2018

I've been working through Andy's papers to learn about filtering. I've successfully implemented the sallen-key filter, and I think I understand everything presented except for two concepts: why the g coefficient is calculated as tan(pi*cutoff/samplerate), and why k = 2*res (presuming res is [0.0, 1.0] then this effectively sets an upper bound of 2 for resonance).

I then took that two-stage filter and drew up a variant that had three stages -- so 18db slope -- analyzed it, and implemented an algorithm for it. It works quite well, but I noticed that whereas the original two-stage filter would really scream at res=2, my three stage filter would not. I started playing around with different max levels, and discovered that res=3 is too much, state values wind up going to infinity and the whole thing blows up. After some trial and error I found that the right limit is res=8/3, and not one iota more. That seems like too precious of a number to be a coincidence, but I don't understand where it comes from.

I suspect this resonance calculation is related to the tan() stuff. These are the only concepts in Andy's papers that I find unexplained, and I'm coming at this with zero prior DSP or electronics knowledge (just comp sci and some rusty calculus, linear algebra, and physics), everything else I've been able to figure out by studying his papers and the references. By the way, THANK YOU Andy, fantastic stuff! Very intuitively accessible.

I'm sorry if this question has already been answered, I've searched this forum as thoroughly as possible, and while I've seen grumblings about "tan pre-warping" (is that what this tan() stuff is?) I haven't yet found an explanation for why it's necessary, and how it interacts with the resonance levels (if at all) to determine maximum stable values.

I then took that two-stage filter and drew up a variant that had three stages -- so 18db slope -- analyzed it, and implemented an algorithm for it. It works quite well, but I noticed that whereas the original two-stage filter would really scream at res=2, my three stage filter would not. I started playing around with different max levels, and discovered that res=3 is too much, state values wind up going to infinity and the whole thing blows up. After some trial and error I found that the right limit is res=8/3, and not one iota more. That seems like too precious of a number to be a coincidence, but I don't understand where it comes from.

I suspect this resonance calculation is related to the tan() stuff. These are the only concepts in Andy's papers that I find unexplained, and I'm coming at this with zero prior DSP or electronics knowledge (just comp sci and some rusty calculus, linear algebra, and physics), everything else I've been able to figure out by studying his papers and the references. By the way, THANK YOU Andy, fantastic stuff! Very intuitively accessible.

I'm sorry if this question has already been answered, I've searched this forum as thoroughly as possible, and while I've seen grumblings about "tan pre-warping" (is that what this tan() stuff is?) I haven't yet found an explanation for why it's necessary, and how it interacts with the resonance levels (if at all) to determine maximum stable values.

- KVRAF
- 4838 posts since 11 Feb, 2006, from Helsinki, Finland

plb wrote:I've been working through Andy's papers to learn about filtering. I've successfully implemented the sallen-key filter, and I think I understand everything presented except for two concepts: why the g coefficient is calculated as tan(pi*cutoff/samplerate), and why k = 2*res (presuming res is [0.0, 1.0] then this effectively sets an upper bound of 2 for resonance).

The tan() comes from BLT-prewarping and is required for accurate tuning. Essentially, when you use the bilinear transform (=trapezoidal integration) the whole imaginary axis of the analog s-plane gets mapped to the unit-circle of the digital z-plane in a warped fashion such that "infinite" frequency ends up at Nyquist (ie. half sampling rate). The tan() pre-warp applies the reverse warping to put the cutoff at the correct frequency again.

As far as the feedback resonance goes, buffered Sallen-Key hits self-oscillation with feedback gain of 2 and I guess this is because the gain at the cutoff-frequency (where the feedback is in phase) without feedback is 0.5 (ie. -6dB). With feedback gain of 2 the loop gain at that frequency is 0dB so the filter no longer decays.

So.. basically to calculate the required feedback for a modified filter, first find the frequency where the feedback is in phase with the input (note that this will not be the "cutoff" if you add more stages after the feedback point) and then calculate the gain at that frequency. The reciprocal of that gain should then give you the required self-oscillation feedback gain.

Strictly speaking if you'd then like to tune the resonant frequency accurately you need to adjust the pre-warping to take the offset into account.

<- plugins | forum

- KVRer
- 5 posts since 9 May, 2018

Thanks for the thorough response. I think I need to learn some more math to understand your first paragraph, some googling indicates that I need to learn about the laplace transform and the z transform, is that so?

That said, I think I mostly understand what you're saying in the rest of your post.

The SK design takes the output and runs it back in through the input at the capacitor for the first stage -- so in effect you're taking the low-passed output, amplifying it by some factor, then high-passing it (that's what a series capacitor does!) to create a band-passed signal (tuned to the cutoff frequency of the overall filter) and feeding back into the input. For low enough k the system is still stable because the filter attenuates the feedback, but if k gets high enough eventually the feedback "overwhelms" the filter -- attenuation < amplification -- and then you immediately get a positive-amplification feedback loop and the filter goes pop.

How you can calculate that the resting gain when k = 0 is 0.5, and why that positive value corresponds to negative 6db, and it works out that k = 2 is when gain = 0 -- all of this still escapes me. However, it is intuitively obvious that it should all be calculable.

My modified design essentially sticks an additional stage in the middle, so feedback is still coming from the output of the final stage, thus the resonant frequency is still at the overall cutoff level. But more stages means more attenuation which means that the gain when k = 0 won't be 0.5. And I don't know the right way to calculate it. However, by trial and error, I discovered that the appropriate limit for k in this design is 8 / 3. Since I now know that the limit for k is the reciprocal of the "resting" gain (when k = 0), I can look at the normal SK filter and see that its resting gain is 0.5 = 4/8, hence its reciprocal limit for k = 8/4 = 2. My three stage SK has a limit for k = 8 /3, so it stands to reason that its resting gain is 3 / 8. And here we see a pattern emerging. I suspect that if I had a fourth stage, the resting gain will be 2/8, and so its limit for k will be 8 / 2 = 4.

So, there are still some major gaps in my knowledge to fill, but this gives me an intuitive and workable starting point. Thank you very much!

EDIT: So 4/8 -> 3/8 might look like a trend that implies 2/8 as the next step. But the trouble is that implies the subsequent steps are 1/8 and the 0/8 -- the reciprocal of which is invalid. Does that mean that the filter suddenly stops working entirely when you add two additional stages? That seems intuitively impossible.

Another way of looking at things is that 4/8 * 3/4 = 12/32 = 3/8. In other words, each stage reduces resting gain by 3/4. Then adding a fourth stage would be 3/8 * 3/4 = 9/32. Adding subsequent stages would reduce resting gain lower and lower, but it should never actually reach zero -- intuitively, this seems much more reasonable. Therefore I suspect that for my four-stage sallen-keyish filter, the stability ceiling for resonance will be 32/9 ~= 3.55...

That said, I think I mostly understand what you're saying in the rest of your post.

The SK design takes the output and runs it back in through the input at the capacitor for the first stage -- so in effect you're taking the low-passed output, amplifying it by some factor, then high-passing it (that's what a series capacitor does!) to create a band-passed signal (tuned to the cutoff frequency of the overall filter) and feeding back into the input. For low enough k the system is still stable because the filter attenuates the feedback, but if k gets high enough eventually the feedback "overwhelms" the filter -- attenuation < amplification -- and then you immediately get a positive-amplification feedback loop and the filter goes pop.

How you can calculate that the resting gain when k = 0 is 0.5, and why that positive value corresponds to negative 6db, and it works out that k = 2 is when gain = 0 -- all of this still escapes me. However, it is intuitively obvious that it should all be calculable.

My modified design essentially sticks an additional stage in the middle, so feedback is still coming from the output of the final stage, thus the resonant frequency is still at the overall cutoff level. But more stages means more attenuation which means that the gain when k = 0 won't be 0.5. And I don't know the right way to calculate it. However, by trial and error, I discovered that the appropriate limit for k in this design is 8 / 3. Since I now know that the limit for k is the reciprocal of the "resting" gain (when k = 0), I can look at the normal SK filter and see that its resting gain is 0.5 = 4/8, hence its reciprocal limit for k = 8/4 = 2. My three stage SK has a limit for k = 8 /3, so it stands to reason that its resting gain is 3 / 8. And here we see a pattern emerging. I suspect that if I had a fourth stage, the resting gain will be 2/8, and so its limit for k will be 8 / 2 = 4.

So, there are still some major gaps in my knowledge to fill, but this gives me an intuitive and workable starting point. Thank you very much!

EDIT: So 4/8 -> 3/8 might look like a trend that implies 2/8 as the next step. But the trouble is that implies the subsequent steps are 1/8 and the 0/8 -- the reciprocal of which is invalid. Does that mean that the filter suddenly stops working entirely when you add two additional stages? That seems intuitively impossible.

Another way of looking at things is that 4/8 * 3/4 = 12/32 = 3/8. In other words, each stage reduces resting gain by 3/4. Then adding a fourth stage would be 3/8 * 3/4 = 9/32. Adding subsequent stages would reduce resting gain lower and lower, but it should never actually reach zero -- intuitively, this seems much more reasonable. Therefore I suspect that for my four-stage sallen-keyish filter, the stability ceiling for resonance will be 32/9 ~= 3.55...

- KVRAF
- 4838 posts since 11 Feb, 2006, from Helsinki, Finland

plb wrote:How you can calculate that the resting gain when k = 0 is 0.5, and why that positive value corresponds to negative 6db, and it works out that k = 2 is when gain = 0 -- all of this still escapes me. However, it is intuitively obvious that it should all be calculable.

First of all, decibels are a logarithmic scale: +6dB means double amplitude (ie. gain=2), -6dB means half amplitude (ie. gain=0.5). That's not too important though.

The normalised s-plane transfer function (of the analog prototype; for BLT filters it usually makes sense to just work on the s-plane as this is way easier than trying to deal with the annoying trigonometry around unit-circle of the z-plane) of a high-pass pole is s/(s+1) and the same for the low-pass pole is 1/(s+1). So the total open-loop transfer function (multiplying the two together) is s/(s^2+2*s+1). To evaluate the response at frequency w, you substitute s=i*w and since our filter is normalised our cutoff frequency is w=1 and the response is simply i/(i^2+2*i+1) = i/(-1+2*i+1) = 1/2.

With the two-pole we know that the resonance is at the normalised cutoff. If you add additional poles to this particular topology, the main additional complication is figuring out where your actual resonant frequency is afterwards (for positive feedback, the phase needs to be zero or a multiple of 2*pi). I'll leave that as an exercise for the reader as I'm too lazy to figure out a nice analytical way to solve that right now... and you seriously should learn this stuff anyway if you plan on trying to design your own filters.

<- plugins | forum

- KVRist
- 389 posts since 24 Sep, 2014, from Specific Northwest

A pair of ear plugs and a trained knob monkey to slowly turn up the res.

It should be obvious from the equation you are using. Things blow up at divide by zero or very close to that, depending on your scale. Using your ear is the better determination, however, as some values, while legal, only succeed in peeling paint.

It should be obvious from the equation you are using. Things blow up at divide by zero or very close to that, depending on your scale. Using your ear is the better determination, however, as some values, while legal, only succeed in peeling paint.

- KVRer
- 5 posts since 9 May, 2018

Well I have a copy of the Steve Smith's DSP guide coming in the mail, I hope that after studying that I'll be able to make better use of mystran's insights (thanks for taking the time to spell those out for me). Until then, I'll keep using my ears -- I appreciate the validation of that method syntonica!