function [yA, yC] = Afilter(x, Fs)
    // This function computes the A-weighted and the C-weighted
    // version of a signal according to IEC 61672-1
    //
    // Usage:
    //        [yA, yC] = Afilter(x, Fs)
    //
    // where
    //        x:  sampled signal
    //        Fs: sample rate
    //        yA: A-weighted signal
    //        yC: C-weighted signal  
    // 
    // Note that no provision is given as regards calibration.
    // The user should provide a calibrated signal in order to 
    // get a meaningful signal.
    // 
    // -------------------------
    // Author:    Federico Miyara
    // Date:      2010-03-26
    // Revision:  2010-04-05
    //            2010-05-19
    //            2020-08-11
    //            2023-11-01

    // Window size
    N = 32768;

    // Vector containing uniformly spaced frequencies according to
    // FFT resolution
    f = [1:N/2-1]*Fs/N;

    // IEC 61672-1:2014 parameters (Annex E)
    fr = 1000;
    fL = 10^1.5;
    fH = 10^3.9;
    fA = 10^2.45;
    D = sqrt(1/2);
    b = (fr^2 + fL^2*fH^2/fr^2 - D*(fL^2 + fH^2)) / (1 - D);
    c = fL^2*fH^2;
    // Poles
    f1 = sqrt((-b - sqrt(b^2 - 4*c))/2)
    f2 = (3 - sqrt(5))/2*fA
    f3 = (3 + sqrt(5))/2*fA
    f4 = sqrt((-b + sqrt(b^2 - 4*c))/2)

    // Design of the A-weighting and C-wighting filtering windows 
    C =  f4^2 * f.^2 ./ (f.^2 + f1^2) ./ (f.^2 + f4^2);
    A = f.^2 .* C ./ sqrt(f.^2 + f2^2) ./ sqrt(f.^2 + f3^2);
    C = 1.007152170092135312629 * C;
    A = 1.2588754864185065507343 * A;

    // A-filtering by means of an FFT overlap-add filtering technique
    exec fftfilter.sci;
    yA = real(fftfilter(x, A, N));

    // C-filtering by means of an FFT overlap-add filtering technique
    // (if requested)
    if argn(1)==2
        yC = real(fftfilter(x, C, N));
    end
    
    // NOTE: The rather large window size could be reduced by
    //       predistorting the filtering window to increase 
    //       attenuation at the low frequency end. This can 
    //       compensate the frequency response increase at low
    //       frequencies due to low spectral resolution issues
    //       when N is smaller.

endfunction
