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.

TLV320AIC3111: The correctness of the algorithm for generating the biquar IIR coefficients is not possible

Part Number: TLV320AIC3111


There is a task to make a 5-band equalizer for TLV320AIC3111. Coefficients must be calculated by the microcontroller depending on the bandwidth and the necessary gain (attenuation) at a given frequency. The coefficients are calculated using the script from slaa447 on page 12 (Appendix C). Then we check the obtained coefficients with the coefficients calculated in TIBQ.exe. The values ​​are different. Even the calculation of the example given in Appendix C does not converge with the calculations made by the TIBQ.exe program. Calculations of examples given in Annexes A and B converge, with the exception of negative coefficients, where the values ​​differ by one, which I understand is entirely acceptable. What could be the problem? I give an example of the script below.

% C.1 MATLAB script to calculate [N0, N1, N2, D1, D2]

%user-defined parameters:
fs = 48000; %sampling frequency
f0 = 600;
dBgain = 10; %10 dB
Q = 1;

%intermediate parameters
wo = 2*pi*f0/fs;
cosW = cos(wo);
sinW = sin(wo);
A = 10^(dBgain/40);
alpha = sinW/(2*Q*A);

% %Peaking EQ coefficients
b0 = 10^(dBgain/20)*(1 + alpha*A);
b1 = 10^(dBgain/20)*(-2*cos(wo));
b2 = 10^(dBgain/20)*(1 - alpha*A);
a0 = 1 + (alpha/A);
a1 = -2*cos(wo);
a2 = 1 - (alpha/A);

%Normalize so that A0 = 1
B0 = b0/a0;
B1 = b1/(2*a0);
B2 = b2/a0;
A1 = a1/(-2*a0);
A2 = a2/(-a0);

Mx = max(abs([B0, B1, B2]));
if Mx > 1
B0new = B0/Mx;
B1new = B1/Mx;
B2new = B2/Mx;
else
B0new = B0;
B1new = B1;
B2new = B2;
end

NB = 16; % number of bits
Range = 2^(NB-1)-1;

N0 = floor(B0new*Range);
N1 = floor(B1new*Range);
N2 = floor(B2new*Range);
D1 = floor(A1*Range);
D2 = floor(A2*Range);


F = 65535;

if N0 < 0
hex_N0 = dec2hex(bitxor (abs(N0), F) + 1);
else
hex_N0 = dec2hex(N0, 5);
end

disp(' Dec Hex')
X = [' N0 ',num2str(N0,5),' ', num2str(hex_N0)];
disp(X)


if N1 < 0
hex_N1 = dec2hex(bitxor (abs(N1), F) + 1);
else
hex_N1 = dec2hex(N1, 5);
end

X = [' N1 ',num2str(N1,5),' ', num2str(hex_N1)];
disp(X)


if N2 < 0
hex_N2 = dec2hex(bitxor (abs(N2), F) + 1);
else
hex_N2 = dec2hex(N2, 5);
end

X = [' N2 ',num2str(N2,5),' ', num2str(hex_N2)];
disp(X)

if D1 < 0
hex_D1 = dec2hex(bitxor (abs(D1), F) + 1);
else
hex_D1 = dec2hex(D1, 5);
end

X = [' D1 ',num2str(D1,5),' ', num2str(hex_D1)];
disp(X)


if D2 < 0
hex_D2 = dec2hex(bitxor (abs(D2), F) + 1);
else
hex_D2 = dec2hex(D2, 5);
end

X = [' D2 ',num2str(D2,5),' ', num2str(hex_D2)];
disp(X)

  • hello Alexsandr,

    I appreciate your bringing this to our attention. I will evaluate the script and get back to you. Is this holding up your development? or is it more a matter of curiosity?

    best regards,
    -Steve wilson
  • Hello Steve,

    No, this is not a question of curiosity, we are making the first project with sound processing and therefore experience in this area is still not enough. Therefore, we are trying to take advantage of already ready solutions and developments. And to verify the correctness of their own calculations, we tried to use the already ready program for calculating the filter coefficients (TIBQ.exe) and came across a discrepancy in the calculated data. And now, respectively, we try to understand where we were wrong. Therefore, please help to deal with this issue.

  • Alexandr,

    Sorry for the delayed response.  This one initially seemed very simple, but everytime I thought I was done there was more to figure out.

    first,  TIBQ and AIC310x GUI are rather old as far as software is concerned,  I am trying to find the source code to see how those programs calculate the biquad coefficients,  but I'm still working on that.

    Second,  those two programs are both pretty good at calculating the coefficients, but there are not correct. there is a horizontal shift.. ie.  The center frequency is not right.  I generated results for 600 hz, and it gave me a curve that was centered on 630-635 hz or so.   the Bandwidth was correct.

    third,  the matlab script appears to have an error in the intermediate parameter definition  alpha is defined as alpha = sinW/(2*Q*A).  this should be alpha = sinW/(2*Q)

    fourth,  TIBQ asks for BW,  while the Matlab script, asks for Q.    Q and BW are related of course, (Q = F0/BW)  so if you want to have 100 hz BW with an F0 of 600,  your Q needs to be 6.  

    Once you make these modifications to the matlab script,  you should be able to generate proper coefficients. I will continue to look into why TIBQ is not giving the proper coefficients,  but It is hard to say if we would end up updating the TIBQ,  it might make more sense for us to simply provide some kind of Excel file that would allow a person to do the same thing.

    Here is a screenshot of the matlab generated biquad response.  taken with an AP.  Ignore the rolloff above 6k,  the EVM I was using  has a passive LPF to filter out of band noise when using at lower sampling rates.

    best regards,

    -Steve Wilson

  • hello Alexandr, 

    I just realized that when I generated my coefficients with the TIBQ, that I must've had Fs set to 44.1k, so my coefficients were incorrect, and that explains the shift.
    I thought that I had double check this,  but clearly I made a mistake.

    The TIBQ coefficients are right on,  There seems to be an error in the matlab script,  I will look it over more closely and get back to you. but for now you can trust the TIBQ

    I"ve attached a plot of response using the TIBQ generated coefficients for a 600hz f0, 100hz BW, 48k Fs, 10dB,  peak EQ VS the modified matlab script with same parameters.  You can see the MAtlab script response is not symmetrical  while the TIBQ is.  

    best regards,
    -Steve