Direct Form 2 Biquad

stringtapper's icon

So I'm working on building filters in gen~ and I made a biquad based on the Direct Form 2 block diagram you can see here:

So it seems like my patch is working pretty well except that I get some clicking when I start moving the filtergraph~ center frequency around rapidly. This doesn't happen with the official "gen~.biquad.maxpat" patch that is included with Max (and looks to be based on the Direct Form 1).

Any ideas what's happening and how to fix it?

Thanks,

Max Patch
Copy patch and select New From Clipboard in Max.

Dave

stkr's icon

hi stringtapper.

it seems that there is something wrong in your implementation. not too much time now to check. also, remember, you are using param and thus lower control rate via message rate to the implementation which does not help. i think the direct form one msp [biquad~] object has some sort of protection against this.

a while ago i posted three forms of biquad in both gen~ and GenExpr implementations to the forum here:

perhaps that will help if you compare them. although i have not looked at the patch in a while!

stringtapper's icon

Thanks for the response stkr. I have been studying your GenExpr [Bp~] and Six-Pole Butterworth filters, so thanks for those as well!

When I compare the inside of my biquad gen~ with the inside of your "Direct Form 2 as gen~ patch" I can't find any difference between the two. Cosmetically, yes, but it seems like the configuration is ultimately the same. The biggest difference seems to be the use of [param] operators versus inputs.

I didn't figure that there would be a difference between using [param] operators and using input operators because the official "gen~.biquad" example patch uses [param] and it doesn't get the clicks that I'm getting.

Hmm, what to do…

Graham Wakefield's icon

Hi there,

Stkr is exactly right: [param] only updates at 'message rate' so it is essentially driving the filter coefficients with a step function. The fact that the direct form 1 doesn't click with small parameter changes is just a lucky artefact. Adding some kind of smoothing to the filter parameters coefficients is a good idea in most cases.

Graham

stringtapper's icon

Ok this is really good to know. So by "smoothing" we're essentially talking driving the coefficients with signals being sent into the gen~… right?

Thanks.

Dave

stringtapper's icon

Ok I think this modified version does the trick. I basically mirrored what stkr did in his patch using signals to control the coefficients. Well at least I can be satisfied that I built the overall structure of the filter correctly! Thanks for the help guys.

Max Patch
Copy patch and select New From Clipboard in Max.

Dave

stringtapper's icon

Would anyone like to take a look at my Direct Form I Biquad made in Codebox? It's my first foray into this and it seems like it should work but it seems like only the low pass is working. Thanks for any advice.

Max Patch
Copy patch and select New From Clipboard in Max.

Be gentle… :)

Tim Shatnyy's icon

Hey, Dave!

To make this code work you would need to swap assignments of x1, x2 and y1, y2 variables!

Here is the fixed version:

biquadCodebox.gendsp
gendsp 5.35 KB
Fixed Biquad Codebox Implementation

All the best,
Tim Shatnyy