public void TestTfToSos() { var zs = new ComplexDiscreteSignal(1, new[] { 1, 0.5, -0.3, 0.2, 0.5, 0.2 }, new[] { 0, 0.2, 0, -0.9, -0.2, 0.9 }); var ps = new ComplexDiscreteSignal(1, new[] { 1, 0.2, 0.5, -0.9, 0.6, 0.1, -0.9 }, new[] { 0, 0, 0, 0.2, 0, 0, -0.2 }); var sos = DesignFilter.TfToSos(new TransferFunction(zs, ps)); Assert.Multiple(() => { Assert.That(sos[0].Numerator, Is.EqualTo(new[] { 1, -0.4, 0.85 }).Within(1e-10)); Assert.That(sos[0].Denominator, Is.EqualTo(new[] { 1, -0.1, 0 }).Within(1e-10)); Assert.That(sos[1].Numerator, Is.EqualTo(new[] { 1, -1, 0.29 }).Within(1e-10)); Assert.That(sos[1].Denominator, Is.EqualTo(new[] { 1, -0.7, 0.1 }).Within(1e-10)); Assert.That(sos[2].Numerator, Is.EqualTo(new[] { 1, 0.3, 0 }).Within(1e-10)); Assert.That(sos[2].Denominator, Is.EqualTo(new[] { 1, 1.8, 0.85 }).Within(1e-10)); Assert.That(sos[3].Numerator, Is.EqualTo(new[] { 1, -1, 0 }).Within(1e-10)); Assert.That(sos[3].Denominator, Is.EqualTo(new[] { 1, -1.6, 0.6 }).Within(1e-10)); Assert.That(sos.Length, Is.EqualTo(4)); }); }
public void TestTfToSos() { var zeros = new Complex[6] { new Complex(1, 0), new Complex(0.5, 0.2), new Complex(-0.3, 0), new Complex(0.2, -0.9), new Complex(0.5, -0.2), new Complex(0.2, 0.9) }; var poles = new Complex[7] { new Complex(1, 0), new Complex(0.2, 0), new Complex(0.5, 0), new Complex(-0.9, 0.2), new Complex(0.6, 0), new Complex(0.1, 0), new Complex(-0.9, -0.2) }; var sos = DesignFilter.TfToSos(new TransferFunction(zeros, poles)); Assert.Multiple(() => { Assert.That(sos[0].Numerator, Is.EqualTo(new[] { 1, -0.4, 0.85 }).Within(1e-10)); Assert.That(sos[0].Denominator, Is.EqualTo(new[] { 1, -0.1, 0 }).Within(1e-10)); Assert.That(sos[1].Numerator, Is.EqualTo(new[] { 1, -1, 0.29 }).Within(1e-10)); Assert.That(sos[1].Denominator, Is.EqualTo(new[] { 1, -0.7, 0.1 }).Within(1e-10)); Assert.That(sos[2].Numerator, Is.EqualTo(new[] { 1, 0.3, 0 }).Within(1e-10)); Assert.That(sos[2].Denominator, Is.EqualTo(new[] { 1, 1.8, 0.85 }).Within(1e-10)); Assert.That(sos[3].Numerator, Is.EqualTo(new[] { 1, -1, 0 }).Within(1e-10)); Assert.That(sos[3].Denominator, Is.EqualTo(new[] { 1, -1.6, 0.6 }).Within(1e-10)); Assert.That(sos.Length, Is.EqualTo(4)); }); }