Generating Sound and Organizing Time - chapter 6 Filters - peaknotch filter excluded

HighHarmonics's icon

GSOT is a great resource! I'm digging into Ch 6 and working with the GO abstractions provided for the different types of biquad filters (lp, hp, bp, etc). However, I see that the "peaknotch" filter is not included.

"Peaknotch" is one of the options in the MSP biquad~/cascade~/filtergraph~ object chains. IMHO it is one of the most useful and versatile filter mode (edit_type) options, so I was surprised to see this one missing from GSOT. peaknotch is my go-to filter for many things and unless I am misunderstanding (quite possible) - it can't be achieved with any of the others (for instance it is quite different from a "notch pass".)

Is there a reason it was not included? If it was just oversight, is there anyway this could be added to the go abstractions (go.biquad.pn and go.biquad4.pn)? Perhaps update the download files?

Alternatively, can anyone provide the coefficients gen~ patching for a peaknotch filter? I realize that is a big ask. I would do it myself, but that level of math is beyond me.

Thanks for any comments or guidance.

ecuk's icon

For coefficients you could try the Audio EQ Cookbook. I believe that if you use its peakingEQ filter with a negative dBgain (i.e., in the calculation of the intermediate value A), it will give you a notch instead of a peak. It has been a few years since I last played with it, however, so I could be wrong.

Another good resource for such things is Ernest’s SynthCore gen~ library, but I don’t recall if a peak-notch filter is lurking somewhere amongst its many goodies.

Roman Thilenius's icon

i was about to say "if you do not need to modulate the gain through zero in realtime you could combine peak and notch and switch between them using a gate~."

but that´s all what the peak/notch design seems to be about anyway?

https://www.dsprelated.com/showcode/169.php

i have an old pluggo which did it that way. but you could also just use 2 parallel biquads. (what does not work is to switch between filterdesign~ modes, since you cannot interpolate the switching.)

the filtergraph~ object of course is of no help if you need it in full-signal, but you can use it to compare the coefficients to see if you did it right.

HighHarmonics's icon

Thanks for the suggestions. I was able to follow the equations in the Audio EQ Cookbook. Using other GO patches as a models, I got a biquad-peakingEQ filter working. I think this is correct, but would welcome input from someone who actually knows.

The end result works, sort of, but is not quite behaving as I expect. But I haven't done much troubleshooting / exploring yet. I tried accepting gain input from -1 to +1, but that blows up the filter with negative values, so I set the gain @min back to 0.0001.

The Audio EQ Cookbook indicates to set the value of "A" to: 10 to the power of dBgain/40
But GSOT uses A as a gain In of 0 to 1 in the biquad shelving coeffs, so I went with that.

I also tried the suggestion of validating coefficient output via filtergraph~, but I couldn't make that work. Filtergraph~ accepts input for a0, a1, a2, b1, b2. The GSOT coefficient output uses b0, b1, b2, a1, a2. I'm not sure how to reconcile this.

Any other insights most welcome!

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

Roman Thilenius's icon

i just noticed that the peaknotch mode of filtergraph~ is not constant-q, so one might have to set it to a fixed value.

btw, in case this is for a parallel EQ, you could avoid the requirement of "notch" totally and just switch sign. :)

these naming schemes make me sick. i have an abstraction for changing the order between max and pd, but even pd does not follow the direct form II order (which its biquad object performs) and has a and b switched (compared to wikipedia or matlab)