public PoleZeroPair( Complex pole1, Complex zero1, Complex pole2, Complex zero2) { Poles = new ComplexPair(pole1, pole2); Zeros = new ComplexPair(zero1, zero2); }
public static void Main() { var a = new Complex(-1, 2); if (complextest.Conj(a) != Complex.Conjugate(a)) { throw new Exception("std::complex<double> test failed"); } if (complextest.Conjf(a) != Complex.Conjugate(a)) { throw new Exception("std::complex<float> test failed"); } var vec = new VectorStdCplx(); vec.Add(new Complex(1, 2)); vec.Add(new Complex(2, 3)); vec.Add(new Complex(4, 3)); vec.Add(new Complex(1, 0)); if (complextest.Copy_h(vec).Count != 2) { throw new Exception("vector<complex> test failed"); } var p = new ComplexPair(); p.z1 = new Complex(0, 1); p.z2 = new Complex(0, -1); if (Complex.Conjugate(p.z2) != p.z1) { throw new Exception("vector<complex> test failed"); } }
public static void BandPassTransform(double fc, double fw, Layout digital, Layout analog) { digital.Clear(); var ww = 2 * Math.PI * fw; // pre-calcs var wc2 = 2 * Math.PI * fc - (ww / 2); var wc = wc2 + ww; // what is this crap? if (wc2 < 1e-8) { wc2 = 1e-8; } if (wc > Math.PI - 1e-8) { wc = Math.PI - 1e-8; } var a = Math.Cos((wc + wc2) * 0.5) / Math.Cos((wc - wc2) * 0.5); var b = 1 / Math.Tan((wc - wc2) * 0.5); var a2 = a * a; var b2 = b * b; var ab = a * b; var ab_2 = 2 * ab; ComplexPair transform(Complex c) { if (c.IsInfinity()) { return(new ComplexPair(-1, 1)); } c = (1.0 + c) / (1.0 - c); // bilinear var v = Complex.Zero; v = AddMul(v, 4 * (b2 * (a2 - 1) + 1), c); v += 8 * (b2 * (a2 - 1) - 1); v *= c; v += 4 * (b2 * (a2 - 1) + 1); v = Complex.Sqrt(v); var u = -v; u = AddMul(u, ab_2, c); u += ab_2; v = AddMul(v, ab_2, c); v += ab_2; var d = Complex.Zero; d = AddMul(d, 2 * (b - 1), c) + 2 * (1 + b); return(new ComplexPair(u / d, v / d)); } var numPoles = analog.NumberOfPoles; var pairs = numPoles / 2; for (int i = 0; i < pairs; ++i) { var pair = analog[i]; var p1 = transform(pair.Poles.First); var z1 = transform(pair.Zeros.First); // // Optimize out the calculations for conjugates for Release builds // #if DEBUG ComplexPair p2 = transform(pair.Poles.Second); ComplexPair z2 = transform(pair.Zeros.Second); Debug.Assert(p2.First == Complex.Conjugate(p1.First)); Debug.Assert(p2.Second == Complex.Conjugate(p1.Second)); #endif digital.AddPoleZeroConjugatePairs(p1.First, z1.First); digital.AddPoleZeroConjugatePairs(p1.Second, z1.Second); } if ((numPoles & 1) != 0) { var poles = transform(analog[pairs].Poles.First); var zeros = transform(analog[pairs].Zeros.First); digital.Add(poles, zeros); } double wn = analog.NormalW; digital.NormalW = 2 * Math.Atan(Math.Sqrt(Math.Tan((wc + wn) * 0.5) * Math.Tan((wc2 + wn) * 0.5))); digital.NormalGain = analog.NormalGain; }