function A = Aweighting(f)
   // A weighting for given frequencies
   // Computes the A weighting in dB corresponding to an
   // A filter according to IEC 61672
   //
   // Usage:
   //       A = Aweighting(f)
   // where
   //       f: frequency in Hz. May be scalar or array
   //       A: Value to be added to the sound pressure
   //          level at a narrow band centered at f
   //
   // Reference IEC 61672
   //
   // -------------------------
   // Author: Federico Miyara
   // Date:   2022-07-15
   
   // Constant 
   K = 1.2589049*12194^2*(2*%pi)^2; 
   // Poles
   p1 = -20.60*2*%pi;
   p2 = -107.7*2*%pi;
   p3 = -737.9*2*%pi;
   p4 = -12200*2*%pi;

   // Numerator
   Anum = poly([ 0 0 0 0 K], 's', 'coeff' );
   // Denominator
   Aden = poly([p1 p1 p2 p3 p4 p4], 's');
   // Transfer function
   HA = Anum/Aden;
   
   // A weighting
   s = 2*%pi*%i*f;
   A = 20*log10(abs(horner(HA,s)));
   
endfunction
