function [A0,A1,A2,B0,B1,B2] = resample_filter(a1,a2,b0,b1,b2,Fs1,Fs2)
    // This function computes the coefficients of a second order IIR 
    // filter in the Z domain for a sample rate Fs2 different from the
    // original one, Fs1.
    // 
    // Usage
    //    [A0,A1,A2,B0,B1,B2] = resample_filter(a1,a2,b0,b1,b2,Fs1,Fs2)
    // where
    //    a1, a2:     original filter denominator coefficients (a0 = 1)
    //    b0, b1, b2: original filter numerator coefficients 
    //    A0, A1, A2: new filter denominator coefficients
    //    B0, B1, B2: new filter numerator coefficients
    //    Fs1:        original sample rate
    //    Fs2:        new sample rate
    //
    // NOTE: The coeficients are in decreasing order of powers of z.
    //
    // In order to change the sample rate we start from the bilinear 
    // transformation that allows converting from a Laplace-domain 
    // transfer function to its equivalent z-domain transfer function:
    //
    // s = 2/Ts * (z - 1) / (z + 1)
    //
    // where Ts = 1/Fs, or, equivalently, 
    //
    // z = (1 + Ts/2*s) / (1 - Ts/2*s)
    //
    // Using this with Fs1 we can get the s-domain transfer function,
    // and then convert back to the z-domain with Fs2. The resulting
    // coefficients are used here. 
    //
    // -------------------------------------
    // Author: Federico Miyara
    // Date: 2014-11-25


    q = Fs2/Fs1;

    A0 = 1 + 2*q + q^2 + a1*(1 - q^2) + a2*(1 - 2*q + q^2);
    A1 = 2*(1 - q^2) + 2*a1*(1 + q^2) + 2*a2*(1 - q^2);
    A2 = 1 - 2*q + q^2 + a1*(1 - q^2) + a2*(1 + 2*q + q^2);

    B0 = b0*(1 + 2*q + q^2) + b1*(1 - q^2) + b2*(1 - 2*q + q^2); 
    B1 = 2*b0*(1 - q^2) + 2*b1*(1 + q^2) + 2*b2*(1 - q^2); 
    B2 = b0*(1 - 2*q + q^2) + b1*(1 - q^2) + b2*(1 + 2*q + q^2); 

endfunction
