How can I generate proper coefficients for shelf filters
Hello all
I'm confused. My procedure generates different coefficient than FilterTableGen.
(Filter Table Generator)
very simple C source in attached file
filter
Hello wielad,
Welcome to the forum. As is often the case where unexpected results occur, there may be more than one issue in play here. It appears your C code is based on the same formulas as Brett's spreadsheet at https://ez.analog.com/docs/DOC-1819 , I've used this manually and have also based microcontroller code upon it; it worked for me either way. Comparing its coefficients with those from the FilterTableGen shows that both produce useful results. With the values you're using (1KHz /48KHz, Q=1.41, unity gain), the Generator produces this table:
The zero-boost case is interesting since it sets B0 = 1 and all others zero. Typing that directly into SigmaStudio's IIR Coefficient filter block yields a flat result as expected (note you need not negate the a0 and a1 coefficients when using this window, SigmaStudio does that for you):
The Parametric_EQ_IIR_Coefficient spreadsheet produces the different coefficients shown below, yet they also yield a flat response:
Apparently the FilterTableGen includes logic that realizes that with boost = 0 the filter is moot -- might as well do a unity-gain buffer. The spreadsheet doesn't recognize this condition but the math cancels out to a flat response anyway. For nonzero boost, the spreadsheet and Filter Gen produce similar coefficients and responses. This example is for boost = +10dB:
Since the spreadsheet works I compared its formulas to your C code and make a few changes -- file attached below.
Best regards,
Bob
Excellent work. Thanks, Bob!
We put in a conditional statement that would simply creates the unity-gain buffer when boost is set to zero. This is not present in the equations that are published, as you noted.
Thank you, Brett!
Come to think of it, perhaps we all should put the same "boost = 0" condition in our own microcontroller code -- after all, many EQ sliders end up at zero. Would it improve operation or sound quality?
Bob
Maybe Miguel can comment on this, but my guess is that, due to the fixed-point nature of the DSP, the response might not be totally flat when using the non-zero coefficients resulting from the equations when using boost=0. However, the "unity-gain buffer" substitution guarantees a perfectly flat response, even with fixed-point math.
Many thanks for help.
As I see I did one mistake in my equations
A=10^(Boost/20)
instead of
A=10^(Boost/40)
That because A is not defined in common variables in General 2nd-Order Filters description. Maybe it is good idea to correct the description.
Best Regards
wielad
Please log in to reply.









