In the Chapter 12 homework, Exercise 4 asks you to implement four filters using the WDF library. The LPF and HPF were simple enough to implement. However, I'm having a problem trying to figure out the shelving filters, but I'm going to talk about the low shelf. As I feel that if I can figure that one out the other should be easier.

I create the adapters in the in the createWDF() function. A series adapter with a R component, and a parallel adapter with a seriesRC component. Connect them together. Set the first adapter's source resistance to 0.0 and set the second for open terminal resistance since that's what's implied in the schematic and it worked fine for the LPF and HPF. So, I doubt that's the problem (?). Also, if I set initial values for the components, everything works fine, and I've even found a passive low shelf schematic online while trying to see what I'm missing in this, and the values from that worked too. The issue happens when I try to change those values in a setParameters() function.

So, transferring the equations from the exercise, changing the C1 value with the frequency seems to be working fine:

double c1Val = 1.0 / (kTwoPi * fc_Hz * r1Val);

parallel_R2_C1.setComponentValue_RC(r2_init, c1Val);

But the problem arises when I try to implement the gain equation that adjusts the R1 value. Again, transferring the equation from the book (in the function this is just before the c1Val calculation)

double r1Val = (r2_init * (1.0 - gain)) / gain;

series_R1.setComponentValue(r1Val);

As soon as I try that, it stops working.

The equation in the book for the gain used in the function is listed as 10^(-shelf_gain_dB/20) which looks to me to be your basic dB to gain conversion, but I do notice the negative sign in front of the shelf_gain_dB variable, which makes intuitive sense, because you'd want more resistance to decrease gain, and the R1 equation has (1 - gain) rather than (gain - 1), but when I work the calculations out by hand with the constants that work it seems to imply that the other way is closer to correct. So, I don't know if I'm drifting off to be even more wrong with that, but in trying to change the equation to account for that and other variations to further try to understand what was going wrong it still wasn't working out.

I also notice that in the book equation that the gain variable in not italicized in the (1 - gain), but is italicized in the denominator similar to the way it's italicized as the solution in the dB conversion, but that doesn't mean that they are different variables does it? I'm doubting that's the case but I thought I'd bring it up just to be sure, as I'm feeling very lost at the moment.

So, I'm not sure where to go from here, or how to better understand where I went wrong.

Hi Mike, welcome to the forum.

That implementation sounds correct as you've described. I haven't built this to test. But having a guess, it seems like you're not updating R2_C1 alongside the R1 value changing.

Not an issue in the case of altering C1's cutoff point alone but it's value is also directly calculated from the value of R1. So when R1 changes, R2_C1 needs to be updated as well else the filter won't function as intended.

Cheers,

Jim

Thanks a bunch. Both for the welcome and the response.

As I mentioned quickly above, the way I actually have the calls in the function is flipped around, so what the block actually looks like in setParameters() is:

double r1Val = (r2_init * (1.0 - gain)) / gain;

double c1Val = 1.0 / (kTwoPi * fc_Hz * r1Val);

series_R1.setComponentValue(r1Val);

parallel_R2_C1.setComponentValue_RC(r2_init, c1Val);

series_R1.initializeAdaptorChain();

So, C1 gets updated with the R1 value calculated from the first part. r2_init remains constant of course, as the equation notes it as arbitrary. Unless that's not correct? ðŸ¤·â€â™‚ï¸ But yeah, this is where I was saying that I wasn't sure what was going on with the gain equation, because (and I'm sorry if this seems obvious as I go through the equation) if we let R2 be a resistor rated at 12.1k ohms and cut by -3dB then the gain equation flips that negative in the exponent of course. So, the gain ends up at approximately 1.4125. But if the equation for R1 is using that same gain variable in both the numerator and denominator then (12100 * (1 - 1.4125)) / 1.4125 gives you a resistor rated at approximately -1497.59 ohms, which doesn't seem quite right. And like I was saying, I can choose to not flip the sign of the dB, but of course that isn't a solution since if I boost instead of cut, I'm running into the same problem.Â

Yep you'll be wanting to boost as well as cut so for sure the sign being flipped or not is probably not the problem.

That said, what is the problem you are having specifically? Might need some further details.

Also I doubt if you'd want to be calling to initialize the adaptor chain from setParameters().

I call the adaptor chain at the end because that's how it's implemented in the example ideal filters, as it looks like that's where the coefficients are actually updated after you set the values.

Anyway, the problem was pretty much just getting no sound after implementing it, though I guess except for a sound similar to when you have a dirty pot in a pedal if I turned up the speakers very high.

However, I sat with it for a good while as the thing with returning negative resistor values was really bugging me, because if I was putting this together on a breadboard or something that's definitely not something I'd expect to see. So, I made the gain a scalar multiplier of R2 and it was working with frequency and gain knobs both working with kind of a tone knob feel. I was trying to figure it out when I was looking again at that page I found with the passive low and high shelf schematics I found (over here, for reference: http://linkwitzlab.com/filters.htm#5) and I see that it uses R2 with the capacitor instead of R1, and I feel like that makes more sense though the following high shelf on the page does use the R1.

In the end, the way I have it working now is by using that R2-based scale and flipping the sign while changing the dB range to be from -20dB to just before 0.0dB to prevent it from boosting.

Because, if it's the way it's written in the book, if you start with those component values from that Linkwitz schematic again and you boost the gain (by any amount, but let's say 3dB) you end up with the negative resistor value again (-3533.9 ohms) and then if you carry that along to calculate the capacitor value you have a negative capacitor value (-61.7 nF) which would also result in a negative frequency (-2502.066 Hz). But even worse, if you set it to unity gain, the R2(1 - 1) in the R1 equation means that you'd end up dividing by zero in the next step. That kind of makes me believe that the 1 / ( 2pi * fshelf * R1) might possibly be a typo for the low shelf, though it's still possible that I overthought myself way off base.

With that, I'm also not sure anymore that the shelving filters are supposed to have a boost past 0.0dB. Mostly for the above reasons with the negative resistor values, and I feel like (again, thinking about breadboarding) if there was a boost it'd function similarly to a bass boost, and I feel like you'd need more components than what's shown in the schematic.

But still, if so, if that is supposed to be a capability then I'm not sure how you use the equation [R2(1-gain) / gain] to do it.

Right really should have checked first. Now I've tried the lowpass shelving filter variant and have exactly the same stability issues as you.Â

I think your idea that negative R values are invalid, is correct. Probably make a lot of sense since a passive filter shouldn't actually be capable of shelf boosting in real life, as there is no active source of gain in the circuit.

I verified against the equations from the site you posted (thanks, hard to find info on those), using an arbitrary R1 instead of R2 and finding for that -

R2 = R1 / ( Gain - 1.0 )

which is actually equivalent to Wills formula and also produced the exact same results. As R1 (or R2 in the above eq.) approaches towards 0 the shelf level keeps dropping, and I guess trending towards behaving as a normal RC filter. So I don't think it'll be possible to boost with this circuit.

You can increase overall gain and then shelf cut with the opposite filter type to receive almost the same result.

Thanks for bringing this up

Most Users Ever Online: 152

Currently Online:

9 Guest(s)

Currently Browsing this Page:

1 Guest(s)

Top Posters:

Chaes: 56

Skyler: 48

StevieD: 46

Derek: 46

Frodson: 45

Peter: 43

TheSmile: 43

Nickolai: 43

clau_ste: 39

jeanlecode: 37

Member Stats:

Guest Posters: 2

Members: 786

Moderators: 1

Admins: 6

Forum Stats:

Groups: 13

Forums: 42

Topics: 853

Posts: 3385

Newest Members:

F_Marchal, plenge, Kevin_1, jkarstedt, JohnW, Sean, loss1234, Murray J, Dave, jcloungeModerators: W Pirkle: 698