Filter problem

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

Post

Hello,

So I dived into plugin development and im having an issue with my filter. I'm developing a simple clip distortion with a pre-distortion filter. For some reason the filter in high-pass or bandpass mode does not seem to cut off correctly when i change the cutoff slope. It only seems to work in low pass mode. In the other two modes, regardless if I change the slope, it seems to cutoff at the same rate, OR it gives me the opposite effect, ie what should be a 12db slope seems to cutoff more than 12db, and if i change it to 24db, more low end is present in high-pass mode

Code: Select all

 //slope is an int, everything else is double
double Filter::process(double inputValue) {
	if (inputValue == 0.0) return inputValue;
	buf0 += cutoff * (inputValue - buf0 + feedbackAmount * (buf0 - buf1));
	buf1 += cutoff * (buf0 - buf1);
	buf2 += cutoff * (buf1 - buf2);
	buf3 += cutoff * (buf2 - buf3);
	switch (mode) {
	case FILTER_MODE_LOWPASS:
		if (slope) { return buf3; }
		return buf1;
	case FILTER_MODE_HIGHPASS:
		if (slope) { return inputValue - buf3; }
		return inputValue - buf1;
	case FILTER_MODE_BANDPASS:
		if (slope) { return buf0 - buf3; }
		return buf0 - buf1;
	default:
		return 0.0;
	}
}
"slope" changes when you change the cutoff amount. It's value is either 0 (12db slope) or 1 (24db slope). From my understanding of this filter algorithm, buf0 is a 6db filter & buf1 is as well, and they are in series resulting in a 12db filter. so four of them should be 24db. and then subtracting the 24db filter from the input value *should* give you a 24db slope on a high-pass filter, correct? Or am i reading something wrong here?

Any suggestions or possible alternate filters i could try out?

Also, while I'm here, do you guys have any recommendations for learning more DSP code or something? I'm REALLY new at this (been like 2 weeks) and would like to learn as much as possible.

Post

so, this looks to me like 4 cascaded stages with a weird bandpass feedback
you're probably experiencing weirdness (leaking) in the HP mode because the gain at the given stage is not quite "1.0"
also, i don't think such tricks (subtracting the 4-th stage from the input) won't really give you a 24dB HP, and probably won't work if you have a unit-sample delay in the feedback path

for your requirement, a neat solution that would work is to use a 4-pole ladder, and the "xpander" multimode tricks
with those tricks you can get all kinds of filter responses (including 24dB HP and BP) however you can't quite use them if you still have the 1-sample delay in the feedback (specifically the HP modes would not quite work)
a zdf/tpt ladder filter works great with the xpander multimode tricks

and a small optimization: do you really need the switch statement executed per sample? do you expect the "slope" parameter to be changed that often? i would put the switch outside, so it is only called once per "block" instead
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.libera.chat >>> #kvr

Post

antto wrote:so, this looks to me like 4 cascaded stages with a weird bandpass feedback
you're probably experiencing weirdness (leaking) in the HP mode because the gain at the given stage is not quite "1.0"
also, i don't think such tricks (subtracting the 4-th stage from the input) won't really give you a 24dB HP, and probably won't work if you have a unit-sample delay in the feedback path

for your requirement, a neat solution that would work is to use a 4-pole ladder, and the "xpander" multimode tricks
with those tricks you can get all kinds of filter responses (including 24dB HP and BP) however you can't quite use them if you still have the 1-sample delay in the feedback (specifically the HP modes would not quite work)
a zdf/tpt ladder filter works great with the xpander multimode tricks

and a small optimization: do you really need the switch statement executed per sample? do you expect the "slope" parameter to be changed that often? i would put the switch outside, so it is only called once per "block" instead
I'll look into it tomorrow, thanks for the feedback! I actually fixed the "leaks" part, it was an issue with my input/output in the processDoubleReplacing section apparently.

Would you happen to have any quick links I could check out in reference to what you are talking about? As mentioned, I am extremely new at this haha.

Post

there are nice threads here at this very section of the forum about most (if not all) of the things i mentioned
it would be probably easier to use google to find them

"zdf" (zero-delay feedback) is the technique of removing the 1-sample delay of the feedback path, that's done by precalculating (predicting) the output sample before using it

"TPT" (topology preserving transform?) is about preserving the whole topology of the filter (which itself also includes the requirement of there being no 1-sample delays)

so reading on any of those two will get you on the right track

the xpander multimode tricks (there's a thread by mystran) explains how you can get all sorts of filter modes out of a ladder filter by just applying some coefficients (weights) at the filter stages

i am just making my first steps at putting together such zdf filters myself, and given that i'm quite dumb, i think i might be able to explain what i've learned so far in a very simple way (less on the maths and more on the codez)
tho the recommended way is to read all the books instead
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.libera.chat >>> #kvr

Post

zdf/tpt threads:
http://www.kvraudio.com/forum/viewtopic ... 3&t=350246
http://www.kvraudio.com/forum/viewtopic ... 3&t=349859
http://www.kvraudio.com/forum/viewtopic ... 3&t=412944
http://www.kvraudio.com/forum/viewtopic ... 3&t=368466

about the multimode tricks:
http://www.kvraudio.com/forum/viewtopic.php?t=207647
and a small tip: there you see, for a 4-pole ladder, 5 coefficients
the first (A) coefficient is for the "input" and the other 4 are for the outputs of each of the 4 stages of the ladder
it might be confusing where to apply the A coefficient exactly, it should be applied on the whole input and feedback
so if you have something like:
y1 = (g*(in - k*y4) + s1)/(1.0+g); // first stage
the first coeff goes on the whole (in - k*y4) thing
so it's convenient to isolate it into a sepparate variable:
double fb = (in - k*y4); // "input" (with the feedback)
y1 = (g*fb + s1)/(1.0+g); // first stage
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.libera.chat >>> #kvr

Post

Heh, I was just reading that subtracting the result of a lowpass filter from its input doesn't result in a good highpass filter because of the phase difference.

(Kamenov's Digital Signal Processing for Audio Applications, which so far is a lot more math than I wanted and no code. A handful of concepts have managed to penetrate my skull but I'm doing a whole lot of grimacing and skimming. The highest math I had was trigonometry, though I did have a class in "business calculus" it was basically "here are a couple of things you can do with a graphing calculator" which didn't really stick.)

Post

This is alllllll news to me haha. Started reading up on those links yesterday. Gonna take me a bit to grasp it all, but thanks.

While I'm doing all this reading, any recommended readings on waveform algorithms or any other concepts one would use in a plugin that are a bit more complex than they seem?

@Foosnark, I feel you on the not understanding much part, I'm finding it difficult to understand as well and I've taken maybe 5 math courses above second year calculus haha. Just gonna take a while and a bit of re-reading.

Antto, where would you recommend I start? Should I read that whole Filter Design book first? Because I read all of those threads and I'm 100% confused haha. Like I have no idea where all those variables are coming from and what not. Will the book explain it better (and is it published yet?)

Post Reply

Return to “DSP and Plugin Development”