This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TAS5825M: Calculating filter coefficients on the fly

Part Number: TAS5825M


I have an application , that I need to be able to adjust EQ parameters on the fly through software. .This is something I have done many times before with the SigmaStudio processors Anyhow, I captured  the I2S output from PurePath for a 48Khz peaking, filter  Freq=1000, Q=.71, Gain = 12dB.which generates a I2S address, sub address and a series of 5 32 bit numbers in hex.. However, nowhere in the documentation is there an indication  the coefficient load order and the actual coefficients don't seem to make sense.  I understand that your implementation of Direct Form 1 has a 2x gain for B! and A1.

Do you have any additional information  of time?

 

  • Hi Richard,

    Let me contact our software team. I think we should be provide something to help you.

    Andy

  • Hi Richard,

    See the two files.

    You can find the equations in the Audio-EQ-Cookbook.txt.

    The excel file shows how to convert a coefficient to a 32-bit data in 5.27 format.

    EQ format calculation tool.xlsx

             Cookbook formulae for audio EQ biquad filter coefficients
    ----------------------------------------------------------------------------
               by Robert Bristow-Johnson  <rbj@audioimagination.com>
    
    
    All filter transfer functions were derived from analog prototypes (that
    are shown below for each EQ filter type) and had been digitized using the
    Bilinear Transform.  BLT frequency warping has been taken into account for
    both significant frequency relocation (this is the normal "prewarping" that
    is necessary when using the BLT) and for bandwidth readjustment (since the
    bandwidth is compressed when mapped from analog to digital using the BLT).
    
    First, given a biquad transfer function defined as:
    
                b0 + b1*z^-1 + b2*z^-2
        H(z) = ------------------------                                  (Eq 1)
                a0 + a1*z^-1 + a2*z^-2
    
    This shows 6 coefficients instead of 5 so, depending on your architechture,
    you will likely normalize a0 to be 1 and perhaps also b0 to 1 (and collect
    that into an overall gain coefficient).  Then your transfer function would
    look like:
    
                (b0/a0) + (b1/a0)*z^-1 + (b2/a0)*z^-2
        H(z) = ---------------------------------------                   (Eq 2)
                   1 + (a1/a0)*z^-1 + (a2/a0)*z^-2
    
    or
    
                          1 + (b1/b0)*z^-1 + (b2/b0)*z^-2
        H(z) = (b0/a0) * ---------------------------------               (Eq 3)
                          1 + (a1/a0)*z^-1 + (a2/a0)*z^-2
    
    
    The most straight forward implementation would be the "Direct Form 1"
    (Eq 2):
    
        y[n] = (b0/a0)*x[n] + (b1/a0)*x[n-1] + (b2/a0)*x[n-2]
                            - (a1/a0)*y[n-1] - (a2/a0)*y[n-2]            (Eq 4)
    
    This is probably both the best and the easiest method to implement in the
    56K and other fixed-point or floating-point architechtures with a double
    wide accumulator.
    
    
    
    Begin with these user defined parameters:
    
        Fs (the sampling frequency)
    
        f0 ("wherever it's happenin', man."  Center Frequency or
            Corner Frequency, or shelf midpoint frequency, depending
            on which filter type.  The "significant frequency".)
    
        dBgain (used only for peaking and shelving filters)
    
        Q (the EE kind of definition, except for peakingEQ in which A*Q is
            the classic EE Q.  That adjustment in definition was made so that
            a boost of N dB followed by a cut of N dB for identical Q and
            f0/Fs results in a precisely flat unity gain filter or "wire".)
    
         _or_ BW, the bandwidth in octaves (between -3 dB frequencies for BPF
            and notch or between midpoint (dBgain/2) gain frequencies for
            peaking EQ)
    
         _or_ S, a "shelf slope" parameter (for shelving EQ only).  When S = 1,
            the shelf slope is as steep as it can be and remain monotonically
            increasing or decreasing gain with frequency.  The shelf slope, in
            dB/octave, remains proportional to S for all other values for a
            fixed f0/Fs and dBgain.
    
    
    
    Then compute a few intermediate variables:
    
        A  = sqrt( 10^(dBgain/20) )
           =       10^(dBgain/40)     (for peaking and shelving EQ filters only)
    
        w0 = 2*pi*f0/Fs
    
        cos(w0)
        sin(w0)
    
        alpha = sin(w0)/(2*Q)                                       (case: Q)
              = sin(w0)*sinh( ln(2)/2 * BW * w0/sin(w0) )           (case: BW)
              = sin(w0)/2 * sqrt( (A + 1/A)*(1/S - 1) + 2 )         (case: S)
    
            FYI: The relationship between bandwidth and Q is
                 1/Q = 2*sinh(ln(2)/2*BW*w0/sin(w0))     (digital filter w BLT)
            or   1/Q = 2*sinh(ln(2)/2*BW)             (analog filter prototype)
    
            The relationship between shelf slope and Q is
                 1/Q = sqrt((A + 1/A)*(1/S - 1) + 2)
    
        2*sqrt(A)*alpha  =  sin(w0) * sqrt( (A^2 + 1)*(1/S - 1) + 2*A )
            is a handy intermediate variable for shelving EQ filters.
    
    
    Finally, compute the coefficients for whichever filter type you want:
       (The analog prototypes, H(s), are shown for each filter
            type for normalized frequency.)
    
    
    LPF:        H(s) = 1 / (s^2 + s/Q + 1)
    
                b0 =  (1 - cos(w0))/2
                b1 =   1 - cos(w0)
                b2 =  (1 - cos(w0))/2
                a0 =   1 + alpha
                a1 =  -2*cos(w0)
                a2 =   1 - alpha
    
    
    
    HPF:        H(s) = s^2 / (s^2 + s/Q + 1)
    
                b0 =  (1 + cos(w0))/2
                b1 = -(1 + cos(w0))
                b2 =  (1 + cos(w0))/2
                a0 =   1 + alpha
                a1 =  -2*cos(w0)
                a2 =   1 - alpha
    
    
    
    BPF:        H(s) = s / (s^2 + s/Q + 1)  (constant skirt gain, peak gain = Q)
    
                b0 =   sin(w0)/2  =   Q*alpha
                b1 =   0
                b2 =  -sin(w0)/2  =  -Q*alpha
                a0 =   1 + alpha
                a1 =  -2*cos(w0)
                a2 =   1 - alpha
    
    
    BPF:        H(s) = (s/Q) / (s^2 + s/Q + 1)      (constant 0 dB peak gain)
    
                b0 =   alpha
                b1 =   0
                b2 =  -alpha
                a0 =   1 + alpha
                a1 =  -2*cos(w0)
                a2 =   1 - alpha
    
    
    
    notch:      H(s) = (s^2 + 1) / (s^2 + s/Q + 1)
    
                b0 =   1
                b1 =  -2*cos(w0)
                b2 =   1
                a0 =   1 + alpha
                a1 =  -2*cos(w0)
                a2 =   1 - alpha
    
    
    
    APF:        H(s) = (s^2 - s/Q + 1) / (s^2 + s/Q + 1)
    
                b0 =   1 - alpha
                b1 =  -2*cos(w0)
                b2 =   1 + alpha
                a0 =   1 + alpha
                a1 =  -2*cos(w0)
                a2 =   1 - alpha
    
    
    
    peakingEQ:  H(s) = (s^2 + s*(A/Q) + 1) / (s^2 + s/(A*Q) + 1)
    
                b0 =   1 + alpha*A
                b1 =  -2*cos(w0)
                b2 =   1 - alpha*A
                a0 =   1 + alpha/A
                a1 =  -2*cos(w0)
                a2 =   1 - alpha/A
    
    
    
    lowShelf: H(s) = A * (s^2 + (sqrt(A)/Q)*s + A)/(A*s^2 + (sqrt(A)/Q)*s + 1)
    
                b0 =    A*( (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha )
                b1 =  2*A*( (A-1) - (A+1)*cos(w0)                   )
                b2 =    A*( (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha )
                a0 =        (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha
                a1 =   -2*( (A-1) + (A+1)*cos(w0)                   )
                a2 =        (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha
    
    
    
    highShelf: H(s) = A * (A*s^2 + (sqrt(A)/Q)*s + 1)/(s^2 + (sqrt(A)/Q)*s + A)
    
                b0 =    A*( (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha )
                b1 = -2*A*( (A-1) + (A+1)*cos(w0)                   )
                b2 =    A*( (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha )
                a0 =        (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha
                a1 =    2*( (A-1) - (A+1)*cos(w0)                   )
                a2 =        (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha
    
    
    
    
    
    FYI:   The bilinear transform (with compensation for frequency warping)
    substitutes:
    
                                      1         1 - z^-1
          (normalized)   s  <--  ----------- * ----------
                                  tan(w0/2)     1 + z^-1
    
       and makes use of these trig identities:
    
                         sin(w0)                               1 - cos(w0)
          tan(w0/2) = -------------           (tan(w0/2))^2 = -------------
                       1 + cos(w0)                             1 + cos(w0)
    
    
       resulting in these substitutions:
    
    
                     1 + cos(w0)     1 + 2*z^-1 + z^-2
          1    <--  ------------- * -------------------
                     1 + cos(w0)     1 + 2*z^-1 + z^-2
    
    
                     1 + cos(w0)     1 - z^-1
          s    <--  ------------- * ----------
                       sin(w0)       1 + z^-1
    
                                          1 + cos(w0)     1         -  z^-2
                                      =  ------------- * -------------------
                                            sin(w0)       1 + 2*z^-1 + z^-2
    
    
                     1 + cos(w0)     1 - 2*z^-1 + z^-2
          s^2  <--  ------------- * -------------------
                     1 - cos(w0)     1 + 2*z^-1 + z^-2
    
    
       The factor:
    
                        1 + cos(w0)
                    -------------------
                     1 + 2*z^-1 + z^-2
    
       is common to all terms in both numerator and denominator, can be factored
       out, and thus be left out in the substitutions above resulting in:
    
    
                     1 + 2*z^-1 + z^-2
          1    <--  -------------------
                        1 + cos(w0)
    
    
                     1         -  z^-2
          s    <--  -------------------
                          sin(w0)
    
    
                     1 - 2*z^-1 + z^-2
          s^2  <--  -------------------
                        1 - cos(w0)
    
    
       In addition, all terms, numerator and denominator, can be multiplied by a
       common (sin(w0))^2 factor, finally resulting in these substitutions:
    
    
          1         <--   (1 + 2*z^-1 + z^-2) * (1 - cos(w0))
    
          s         <--   (1         -  z^-2) * sin(w0)
    
          s^2       <--   (1 - 2*z^-1 + z^-2) * (1 + cos(w0))
    
          1 + s^2   <--   2 * (1 - 2*cos(w0)*z^-1 + z^-2)
    
    
       The biquad coefficient formulae above come out after a little
       simplification.
    

    Andy

  • Andy,

    I am very familiar with the Audio Eq Cookbook .

    Here is my problem.

    The calculated values of the normalized coefficients for a a peaking filter 1000hz, Q=.71, Boost=12 dB.  at a 48khz sample

    Freq. 1000 Hz
    Q 0.707
    Gain 12 dB
    Fs 48000 Hz
    Digital coefficients: supply to the
    MiniDSP plugin - advanced biquad
    a0 1
    a1 1.895208759112340
    a2 -0.911562440785883
    b0 1.131819352739890
    b1 -1.895208759112340
    b2 0.779743088045993
    Status Stable
    A 1.995262315
    w0 0.130899694
    alpha 0.092309895
    a0 1.046264541

    Here are the 5.27 values for above

    BQ Coeff [5.27] Format  
    1.8952087591 0F296336 a1
    -0.9115624408 F8B51EC0 a2
    1.1318193527 090DF74E b0
    -1.8952087591 F0D69CCA b1
    0.779743088 063CE9F2 b2

    Here is the I2s dump output of the same filter  from Purepath 3 TAS5825 EVal board

    w 98 30 0a 03 4b ef f1 79 cb ec 04 a2 fd b5 0e 86 34 14 f9 59 b6 5b

    You can easily see that the the hex values do not match .

  • I took the I2c output from the eval board and converted  to the floating  point values .

    Calculated
    a0 1 Eval output 1
    a1 1.895208759112340 0F296336 0E863414 1.815529019
    a2 -0.911562440785883 F8B51EC0 F959B65B -0.831195153
    b0 1.131819352739890 090DF74E 0A034BEF 1.251609676
    b1 -1.895208759112340 F0D69CCA F179CBEC -1.815529019
    b2 0.779743088045993 063CE9F2 04A2FDB5 0.57958547

  • Hi Richard,

    I will take a look and get back to you tomorrow.

    Andy

  • Hi Richard,

    Actually PPC3 can tell you the calculated coefficients. See the screenshot below.

    If you convert these coefficients to their corresponding values in 5.27 format,  you will get these values below. 

    B0 = 0A054C43
    B1 = F17B20B3
    B2 = 049FA5A9
    A1 = 0E84DF4D
    A2 = F95B0E14

    Here is the i2c dump output I see in the PPC3 I2C Monitor. 

    w 98 30 0a 05 4c 43 f1 7b 20 b3 04 9f a5 a9 0e 84 df 4d f9 5b 0e 14 

    Andy

  • Andy,

    Maybe I haven't been clear on the problem. The coefficients calculated by PurePath do not  match the values calculated by the formulas in the Audio EQ Cook Book.. The questions is how our these values calculated? 

  • Hi Richard,

    Here is some Matlab/Octave code to show how to calculate coefficients shown in the screenshot above.

    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/6/bq_5F00_coeff_5F00_example.m

    Andy

  • Andy,

    Perfect ! do you have the formulas for the rest of the filters

    High Pass Variable Q

    Low Pas Variable Q

    Bass Shelf

    Treble shelf.

    If use the Audio EQ Cook Book formulas , just  let me know .

  • Hi Richard,

    Probably. I would need some time to prepare the sample code. 

    Andy

  • See two more examples below.
    a) Bass Shelf

    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/6/Bass-Shelf.m

    b) Treble Shelf

    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/6/Treble_5F00_Shelf.m

    Andy

  • Andy,

    Did you get a chance to look at the formulas for the variable Q 2nd order low pass and high pass filters?

    Rich.

  • I look at the coefficients generated for the variable Q low and High and they are the classical calculations so you don't  need to provide any additional information