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

Biquad coeff calcs don't match

SigmaDSP & SigmaStudio Matt Rowe Jan 13, 2020 00:00 11 replies Original on forum ↗
Subscribe
Matt Rowe Question
Jan 13, 2020 00:00

Hello,

I'm controlling a parametric EQ and testing my system but not coming up with the same coefficient results as Sigma Studio.

Could someone verify the maths that is used please?

Cell Name: Zone1_EQ
Param Name: EQS300MultiDPSWSlewAlg16Targ_B2_2
Param Address: 0x6694

Setting a parametric band to boost -12, freq 20Hz, Q 1.4, gain 0, SigmaStudio produces coeffs:

0.99767017364502

-1.99626898765564

0.998605668544769

-0.99627584189789

1.99626898765564

Using the maths from this page: https://wiki.analog.com/resources/tools-software/sigmastudio/toolbox/filters/general2ndorder implemented as follows:

float A, w0, alpha, gainLinear;
float b0, b1, b2, a0, a1, a2;
float coefficients[5];

A = pow(10, (equalizer.boost / 40)); // 10^(boost/40)
w0 = 2 * PI * equalizer.freq / FS; // 2*PI*freq/FS
gainLinear = pow(10, (equalizer.gain / 20)); // 10^(gain/20)

switch (equalizer.filterType)
{
// Parametric
case parameters::filterType::parametric:
// Peaking
case parameters::filterType::peaking:
default:
alpha = sin(w0) / (2 * A * equalizer.Q);
a0 = 1 + alpha / A;
a1 = -2 * cos(w0);
a2 = 1 - alpha / A;
b0 = (1 + alpha * A) * gainLinear;
b1 = -(2 * cos(w0)) * gainLinear;
b2 = (1 - alpha * A) * gainLinear;
break;

produces the following coeffs:

0.997242748737335,

-1.992628812789917,

0.995392858982086,

1.992628812789917,

-0.992635488510132

As you can see - they are not quite the same. Close, but not the same.

Also, coeffs 4 & 5 seem to be reversed. If I swap those, I get a filter response very close to what I'm asking it to do, but not spot on.

I've tried different decimal places of PI (7, 11 and 15) but that doesn't help.

Thanks

Ken.M Reply
Jan 13, 2020 00:00

Matt,

Please keep in mind that this is a fixed point architecture, and the coefficients are formatted as 8.24 numbers. The coefficients are the same to four significant figure, which is as close as you're going to get with this DSP. Note that your corner frequency is very low in the audio range, and LSBs matter in this range.

I'm not quite sure why b1 and b2 are swapped, but I will investigate further.

Ken

Ken.M Reply
Jan 13, 2020 00:00

Apparently, b1 and b2 are swapped internally to leverage the dual-MAC architecture of the processor. This is normal.

Ken

Matt Rowe Reply
Jan 13, 2020 00:00

Hi Ken,

I don't understand this point.

These coefficients are both before the float to fixed conversion, so the numbers should be identical and we're obviously using different maths.

I realise once converted they will become 8.24 and lose accuracy but that's not what we're looking at here. I'd like to at least start with the correct numbers.

Incidentally, higher frequencies create coeffs with a greater error.

Excel maths calcs attached.

5531.Biquad coeffs.zip

Thanks

Ken.M Reply
Jan 13, 2020 00:00

My apologies. You are correct. This is not the answer. I will investigate further.

Matt Rowe Reply
Jan 13, 2020 00:00

Yes. There is Value (which I assume to be the floating point coeff) and the fixed point bytes are shown as Data. I can't replicate the data bytes at all, so I'm starting with the maths.

I can accurately reproduce the decimal float values (to 15dp) for the tone gen for frequency and gain, but not for EQs.

Ken.M Reply
Jan 13, 2020 00:00

Where in the SigmaStudio interface are you reading the coefficients? In the capture window?

Ken.M Reply
Jan 14, 2020 00:00

Matt,

Please take a look at this FAQ page:

https://ez.analog.com/dsp/sigmadsp/w/documents/5205/calculating-filter-coefficients-to-store-in-a-microcontroller

The parametric EQ coefficients generated by the spreadsheet attached to this page match the coefficients generated by the Fixed Point Filter Table Generator (under the Tools menu). However, they are a little off from the coefficients written to the output window (about 10e-4 difference).

I'll continue to investigate.

Ken

Ken.M Reply
Jan 17, 2020 00:00

Apparently, there is an error in the parametric EQ equations on the wiki. they should be:

Attached is the corrected version of your spreadsheet.

Ken

Biquad Coeffs.xlsx

7875.Parametric_EQ_eqns.png
7875.Parametric_EQ_eqns.png
Matt Rowe Reply
Jan 17, 2020 00:00

Thanks that's much closer.

Is that as close as I can expect to get, as there is still an error?

What I was hoping to do was generate exactly the same fixed-point numbers and these floats are intermediate. I still can't do that - perhaps SigmaStudio is rounding somewhere?

Excel and my C code match exactly, to 15dp so I'm still quite puzzled.

Ken.M Reply
Jan 17, 2020 00:00

Were the "SigmaStudio" values in the spreadsheet read from the capture window? If so, these are formatted for the DSP. The remaining difference would be the fixed point rounding error. The value in decimal of one LSB in 8.24 would be 1/(2^24) = 5.96E-8, and all of the errors are less than that. Am I still missing something?

Ken

Matt Rowe Reply
Jan 18, 2020 00:00

Are we to understand that the decimal numbers in the SigmaStudio capture window are a conversion *back* from the fixed point number to float and that the true floating point calculaiton is not visible anywhere?

What would be the point of that? I don't see how that's useful other than on a read. It's certainly not useful on a write.

We need to know what the coefficient calculator generates for the 5 coefficients to validate any maths so that we can then ensure the correct fixed point numbers are being generated.