Lab_interaccio/2024/smartcitizen-kit-21-dev/tools/Microphone/WEIGHTING/ac_weighting.m
2025-02-25 21:29:42 +01:00

1 line
1.1 KiB
Matlab

clc
clear all
close all
fs = 44100;
fftSize = 512;
freq=[0:fs/(fftSize):fs/2-fs/fftSize];
length(freq)
fA = 10^(2.45);
fL = 10^1.5;
fH = 10^3.9;
fr = 1000;
D = abs(sqrt(0.5));
b = (1/(1-D))*(fr^2+fL^2*fH^2/fr^2-D*(fL^2+fH^2));
c = fL^2*fH^2
f1 = ((-b-sqrt(b^2-4*c))/2)^0.5;
f4 = ((-b+sqrt(b^2-4*c))/2)^0.5;
f2 = (3-sqrt(5))/2*fA;
f3 = (3+sqrt(5))/2*fA;
A1000 = -2;
A1000 = -2;
C1000 = -0.062;
Atable = 20*log10((f4^2.*freq.^4)./(((freq.^2+f1^2).*(freq.^2+f2^2).^0.5).*((freq.^2+f3^2).^0.5).*(freq.^2+f4^2)))-A1000;
Atable_24bit = 10.^(Atable/20);
Ctable = 20*log10((f4^2.*freq.^2)./((freq.^2+f1^2).*(freq.^2+f4^2)))-C1000;
Ctable_24bit = 10.^(Ctable/20);
semilogx(freq,Atable,'b',freq,Ctable,'r');
grid
xlabel('Freq (Hz)')
ylabel('weighting (dB)');
legend ('A-weighthing','C-Weighting');
table = zeros(fftSize/2+1,3);
table(:,1) = freq(:);
table(:,2) = Atable(:);
table(:,3) = Atable_24bit(:);
csvwrite('aweightingtableNORM.csv', table);
table = zeros(fftSize/2+1,3);
table(:,1) = freq(:);
table(:,2) = Ctable(:);
table(:,3) = Ctable_24bit(:);
csvwrite('cweightingtableNORM.csv', table);