/// <devdoc> /// Evaluates the transfer function of a Bessel filter. The gain is normalized to 1 for DC. /// It returns a complex number that corresponds to the gain and phase of the filter output. /// </devdoc> private static Complex TransferFunction(double[] besselPolynomialCoefficients, Complex frequency) { var f = new Polynomials.RationalFraction { Top = new double[] { besselPolynomialCoefficients[besselPolynomialCoefficients.Length - 1] }, // to normalize gain at DC Bottom = besselPolynomialCoefficients }; return(Polynomials.Evaluate(f, frequency)); }
/// <devdoc> /// Given the z-plane poles and zeros, compute the rational fraction (the top and bottom polynomial coefficients) /// of the filter transfer function in Z. /// </devdoc> private static Polynomials.RationalFraction ComputeTransferFunction(PolesAndZeros zPlane) { var topCoeffsComplex = Polynomials.Expand(zPlane.Zeros); var bottomCoeffsComplex = Polynomials.Expand(zPlane.Poles); // If the GetRealPart() conversion fails because the coffficients are not real numbers, the poles // and zeros are not complex conjugates. return new Polynomials.RationalFraction { Top = topCoeffsComplex.Select(x => GetRealPart(x)).ToArray(), Bottom = bottomCoeffsComplex.Select(x => GetRealPart(x)).ToArray(), }; }
private static double ComputeGainAt(Polynomials.RationalFraction tf, Complex w) { return Complex.Abs(Polynomials.Evaluate(tf, w)); }