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)
