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

FilterTableGen Coefficient Calculation?

SigmaDSP & SigmaStudio lasersocks Mar 9, 2017 00:00 2 replies Original on forum ↗
Thread Summary

Thread Summary

The user encountered sign and value discrepancies in the coefficients generated for a bandpass filter in C, using formulas from the help documentation. The final answer clarified that the coefficients are normalized by dividing by a0 and that a1 and a2 need to be inverted in the DSP implementation, resolving the issue. The accompanying answer noted that the sign convention for filter coefficients can vary, suggesting to try flipping the signs if the initial results are incorrect.
AI Generated Content
Subscribe
lasersocks Question
Mar 9, 2017 00:00

I am attempting to create my own filter coefficient generator in c and ran into an issue. I am using the formulas from the help documentation, which I have also confirmed elsewhere on the internet.

An example is the bandpass filter with equations shown here:

The result of the FilterTableGen, which also matches up what ends up in the compiled ram is shown here:

When you actually follow the formulas the A coefficients are the opposite sign of what they show in FilterTableGen and the RAM. a1 is shown as 1.99298 when the calculation gives -1.99298.

w0 = 2*pi*(f/Fs) which at 150 Hz and 96000 Hz sample rate, so w0 = 0.00981. and -2*cos(w0) then comes out to --1.99990, not 1.99298. Which happens to different in value and sign... This is the same for a2.

When you use back calculate the f0/Fs ratio from the values shown in this table using -2*cos(w0) you end up with a ratio of 0.013333 rather than 150/96000 which equals .001563. This is off by a factor of 10.

Is there something that I am missing about these coefficients? Is there a factor that I am missing? Am I calculating w0 incorrectly?

Thanks!

8161cfd4fe8c25371552bef263288514.png
8161cfd4fe8c25371552bef263288514.png
8161cfd4fe8c25371552bef263288514.png-620x215.png
8161cfd4fe8c25371552bef263288514.png-620x215.png
8fb897981165df3981049acb93969230.png
8fb897981165df3981049acb93969230.png
8fb897981165df3981049acb93969230.png-620x353.png
8fb897981165df3981049acb93969230.png-620x353.png
lasersocks Reply
Mar 9, 2017 00:00

It looks like there is common procedure that I missed that is described at the very bottom of the help document:

"For all of the above filters, the coefficients are divided by a0, normalizing them and making a0 = 1 so that only 5 coefficients must be stored. In the actual implementation on the DSP, when the coefficients are stored in parameter RAM, a1 and a2 need to be inverted. This is done automatically, in software, before the parameters are written to memory."

The numbers now work out. I guess this is common in the DSP world, and I missed it.

KJBob Reply
Mar 9, 2017 00:00

Absolutely! The recursive coefficients, which some DSP authors label as "b" and others label "a", come from equations wherein every one comes with a minus sign. Some authors leave the minus signs with the equations, others transfer them to the coefficients themselves. Thus when given a set of coefficients or a set of formulas to calculate them, you rarely if ever know which convention the source followed. The best advice seems to be: Try them out -- if they don't work, flip the signs. I'm not making this up; I've got two different textbooks which say exactly that.

Best regards,

Bob