# Auditory filter A-weighting , B, C, D

## Introduction

There are a few types of auditory filter, such as A-weighting(dB(A)), B-weighting, C-weighting, and D-weighting. These filters  are commonly known by mechanical engineer.

However, do you know these filters can be modeled by the formula?

If you want to see all my lessons in English, please see below.

TopPage 振動騒音 研究所
MATLABとNVH(Noise, Vibration and Harshness)をこよなく愛する人生の先輩、それが私（MATLABパイセン）です。NVHを極めるにあたり、周辺の知識も網羅的に勉強することになり、その知識を共有すべく、本HPを運営しています。日本の製造業を応援すべく、機械エンジニアの「車輪の再開発」の防止と業務効率化の手助けをモットーに活動。専門である振動騒音工学や音響工学について、プログラムを示しながら解説。大学の授業よりもわかりやすく説明することを目指す。質問頂ければ、回答したいと思います。

## Auditory filter

The formula is introduced in Wikipedia.

A-weighting - Wikipedia

## MATLAB code

#### Executable code

clear all;close all
freq=10:10*10^3;
filter_A=Audio_weighting_filter(freq,'A');
filter_B=Audio_weighting_filter(freq,'B');
filter_C=Audio_weighting_filter(freq,'C');
filter_D=Audio_weighting_filter(freq,'D');
figure
semilogx(freq,20*log10(filter_A),'b','linewidth',4)
grid on
hold on
semilogx(freq,20*log10(filter_B),'y','linewidth',4)
semilogx(freq,20*log10(filter_C),'r','linewidth',4)
semilogx(freq,20*log10(filter_D),'k','linewidth',4)
legend('A-weighting','B-weighting','C-weighting','D-weighting')
xlabel('Freq. Hz')
ylabel('Gain dB')


#### function file

Personally, I wrote the code cleaner than usual because of the possibility of using auditory correction filters, which may be helpful for MATLAB beginners.

function filter=Audio_weighting_filter(freq,option)

switch option
case 'A'
filter=A_filter(freq);
case 'B'
filter=B_filter(freq);
case 'C'
filter=C_filter(freq);
case 'D'
filter=D_filter(freq);
end

end

function filter=A_filter(freq)
RA=12194^2*freq.^4./.................
( (freq.^2+20.6^2).*( (freq.^2 + 107.7^2).*(freq.^2 + 737.9^2) ).^(1/2).*(freq.^2 + 12194^2) );
RA_1000=12194^2*1000.^4./.................
( (1000.^2+20.6^2).*( (1000.^2 + 107.7^2).*(1000.^2 + 737.9^2) ).^(1/2).*(1000.^2 + 12194^2) );
filter=RA./RA_1000;
end

function filter=B_filter(freq)
RB=12194^2*freq.^3./.................
( (freq.^2+20.6^2).*( (freq.^2 + 158.5^2) ).^(1/2).*(freq.^2 + 12194^2) );
RB_1000=12194^2*1000.^3./.................
( (1000.^2+20.6^2).*( (1000.^2 + 158.5^2) ).^(1/2).*(1000.^2 + 12194^2) );
filter=RB./RB_1000;
end

function filter=C_filter(freq)
RC=12194^2*freq.^2./.................
( (freq.^2+20.6^2).*(freq.^2 + 12194^2) );
RC_1000=12194^2*1000.^2./.................
( (1000.^2+20.6^2).*(1000.^2 + 12194^2) );
filter=RC./RC_1000;
end

function filter=D_filter(freq)
h=( (1037918.48 -freq.^2).^2 + 1080768.16*freq.^2 )./..................
( (9837328 - freq.^2).^2 + 11723776*freq.^2 );
filter=freq./(6.8966888496476*10^-5).*......................
sqrt( h./( (freq.^2+79919.29).*(freq.^2+1345600) ) );
end



MATLABパイセンが教える振動・騒音・音響・機械工学