ΣSigmaStudio Ask AI Русский Log in

How can I generate proper coefficients for shelf filters

SigmaDSP & SigmaStudio wielad Dec 4, 2013 00:00 5 replies Original on forum ↗
Subscribe
wielad Question
Dec 4, 2013 00:00

Hello all

I'm confused. My procedure generates different coefficient than FilterTableGen.

(Filter Table Generator)

very simple C source in attached file

filter

KJBob Reply
Dec 4, 2013 00:00

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

8228.727ee8f55b24bc0cf13e6db38c267c72.jpg
8228.727ee8f55b24bc0cf13e6db38c267c72.jpg
8228.727ee8f55b24bc0cf13e6db38c267c72.jpg-353x295.jpg
8228.727ee8f55b24bc0cf13e6db38c267c72.jpg-353x295.jpg
2727.ae049e87581cd959cd3e45b60b6078ba.jpg
2727.ae049e87581cd959cd3e45b60b6078ba.jpg
2727.ae049e87581cd959cd3e45b60b6078ba.jpg-544x289.jpg
2727.ae049e87581cd959cd3e45b60b6078ba.jpg-544x289.jpg
1376.db0fb2e989353a99de6ac51cc39792db.jpg
1376.db0fb2e989353a99de6ac51cc39792db.jpg
1376.db0fb2e989353a99de6ac51cc39792db.jpg-544x288.jpg
1376.db0fb2e989353a99de6ac51cc39792db.jpg-544x288.jpg
3252.6a4c7d432222cf208a78d8470ad2165e.jpg
3252.6a4c7d432222cf208a78d8470ad2165e.jpg
3252.6a4c7d432222cf208a78d8470ad2165e.jpg-545x287.jpg
3252.6a4c7d432222cf208a78d8470ad2165e.jpg-545x287.jpg
ADIApproved Reply
Dec 4, 2013 00:00

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.

KJBob Reply
Dec 4, 2013 00:00

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

ADIApproved Reply
Dec 4, 2013 00:00

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.

wielad Reply
Dec 5, 2013 00:00

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

699cb9523d929e5ad61db6a2613aaafb.jpg
699cb9523d929e5ad61db6a2613aaafb.jpg
699cb9523d929e5ad61db6a2613aaafb.jpg-450x484.jpg
699cb9523d929e5ad61db6a2613aaafb.jpg-450x484.jpg