Post Go back to editing

Medium Size EQ

Category: Software

Hello. I am doing tone control with Sigma studio. The schematic below works for me. It works the way I want. I want to control it with the processor. I don't understand how it generates these 5 datas. Limited data is shared on some sites I've reviewed. I added the sites. Can you share the calculations with me? What can I do? What is the way to generate this data? Is there a document or link with calculations for all toolboxes? It is upsetting to go through a continuous research process for each toolbox. It would make everyone's job easier if you could collect them in a single file.

I've included a work I did below. My calculations do not match the results in the image. I am aware that my calculations are inaccurate. What are the relevant formulas?

Good day.

#include <stdint.h>
#include <math.h>
//using namespace std;


return (uint32_t)(value * (0x01 << 23));


int main(){
double PI = 3.14159265;
double dBgain = 0.00;
double frequency = 100.00;
double sampleRate = 48000.00;
double Q = 1.41;
double bandwidth = frequency/Q;
double A = pow(10, dBgain / 40);
double omega = 2 * PI * frequency / sampleRate;
double alpha = sin(omega) / (2 *A * Q);
double gainLinear = pow(10, (dBgain / 20));

double a0 = 1 + alpha/A;
double a1 = 2 * cos(omega);
double a2 = 1 - alpha/A;
double b0 = (1 + alpha * A) * gainLinear;
double b1 = (2 * cos(omega)) * gainLinear;
double b2 = (1 - alpha * A) * gainLinear;

printf(" B0 = %X \n B1 = %X \n B2 = %X \n A1 = %X \n A2 = %X \n", B0, B1, B2, A1, A2);
printf(" B0 = %f \n B1 = %f \n B2 = %f \n A1 = %f \n A2 = %f \n", b0/a0, b1 / a0, b2 / a0, a1 / a0, a2 / a0);


B0 = 800000
B2 = 7ED134
A2 = 7ED134
B0 = 1.000000
B1 = 1.990589
B2 = 0.990759
A1 = 1.990589
A2 = 0.990759 

 Sigma Studio Medium Size EQ calculations 

 Calculating Filter Coefficients to Store in a Microcontroller 

  • Hi ,

    You need calculate each filter ( then get 4 needed bytes value for each parameter, that are 5 coeficents ( B2, B1, B0, A2, A1 ) total is 20 bytes , so you will need the folowing as example:

    48000hz ( fs from your project )
    74 hz ( frequency you want to boost )
    1.41 factor ( quality factor )
    0 gain
    0..10 Boost
    Low shelf ( Filter type )

    With all values, do calculation and you will have 20 bytes as result, that is ready to send to your DSP, if you need change frequeny too, you can, just keep filter address same and use another frequency.

    i have write an realtime javascript web page, that can helps you with that, you can see it at this website also code examples is available.

    You some options:

         1) Use analog potentiometer, then read analog value from your microprocessor input, calculate desired filter, then send bytes to DSP

         2) Use rotary encoder, read value, calculate desired filter, then send  bytes to DSP

         3) Use html User UI to do that ( if your processor have network access and an http server), also rotary encoder, you can have at same time Html User Interface too.

    Please note:

    1) All filter changes must be written to DSP with saleload to prevent undesired noise.

    2) Some DSPs needs to write 5 bytes to safeload, ont this case, send 0x00 + 0xXX + 0xXX + 0xXX + 0xXX ) where XX is each byte value of each parameter.

    3) Not all filter types requires/have same parameters, it may difer from one to another.

    Best regards..

  • hello rocha,

    I did the same calculations. As in the image below, the data does not match with each other. There are slight differences in the numbers. What am I missing? Do you have an idea?

  • Hi, I would like to say thank you, you found a bug in the calculator.

    When I coded this calculator, I coded and tested it with ADAU1466 which has the 8.24 format, however you are using it for ADAU1701 which is the 5.23 format, so the conversion is different.

    So I added the ADAU family field to the calculator this way, people can select the correct DSP family and have the correct decimal conversion.

    In this case, the only change is:

    For Adau 1452 and others from the 300 family
    uint32_t doubleTo824 ( double value ) { return __builtin_bswap32 ( ( round( value * 0x1000000) / 0x1000000 ) * 0x1000000 ); }

    For Adau 1701 and others from the 100 family
    uint32_t doubleTo523 ( double value ) { return __builtin_bswap32 ( ( round( value * 0x800000) / 0x800000 ) * 0x800000 ); }

    If this helps you, dont forget to make this question as anwser, thanks..

  • Hello Rocha. Thank you for your support. First of all, if you don't compile the part you show in the image as the other error, it doesn't show the addresses. If you try after compiling, you will see the addresses appear. The C++ code on the site has extra parentheses }. Additionally, it might be nicer if you change it from uint23_t to uint32_t. If you look at B2, the differences start to appear after the 4th digit after the comma. I don't know how you can edit that part. Thanks for the support.

  • Hi 

    a) about uint23_t, it's a typo, correct is uint32_t, I already changed that..

    b) about extra parentheses, there are no extras, instead I'm missing one after swap, I already changed that.

    c) about the difference after the comma, I see that there is a difference in the decimal value, which is rounded,
    for B2 it corresponds to 7 decimal digits, i.e. 0.9891638 also corresponds to hexadecimal values, which you will need to send to the DSP.

    PS: I think this decimal difference is because I used round, some processors have different round precision, about that I'll try to correct.

    Thanks for point that, also fee free to contact any time.

  • Hello  Rocha. Thank you for your support. The values sent by Sigma studio match the values on the site, super. I was currently migrating the c++ code to my own embedded code. I ran into a problem. Calculation formulas do not match the results on the site. For example, you said cs= cos(omega) in the filterPeaking function. As a result, the value in the site does not come out. My guess is it should be called (1.0-cos(omega)). There are also errors in the subsequent processing. The linear calculations of ax, a0, do not give correct results either.

    According to what and how do you do the calculations? Can you share your path with me? There are other filters that I use in my application. I can also make rapid progress with them.

  • Hi  ,

    Mathematical calculations depend on several factors which will determinate the correct result.

    a) You must use correct variable data types, so that you can adjust parameters and results, as an example for C++, if double ( 8 bytes ) is required, you cannot use float ( 4 bytes ).

    b) The correct conversion from double to another format ( 5.23, 8.24 or 32 bits ) must take into account the DSP family, as the format changes from one family to another.

    c) If rounding is used before converting between formats, only round() should not be used, because there any many chances of not works as expected.

    So that I can better help you, it would be interesting for you to inform which programming language you are using, even which IDE you are programming and, if possible, partial code in question, which can be sent privately if you wish.

    Best regards