Exemplo n.º 1
0
        public void TestCalculateGroupDelay()
        {
            double[] phase =
            {
                221.651357700633e-003,
                236.404025345054e-003,
                251.454348329399e-003,
                265.834661679128e-003,
                277.712938087876e-003,
                283.814953936594e-003,
                278.669273726763e-003,
                254.100812809699e-003,
                200.484690747697e-003,
                112.629294062348e-003,
                967.819685380718e-015,
                -111.610456260826e-003,
                -197.701817968959e-003,
                -250.729276954184e-003,
                -276.409200554505e-003,
                -283.872819775752e-003,
                -280.637306255616e-003,
                -271.705281042254e-003,
                -260.095771586513e-003,
                -247.532299129978e-003,
                -234.956640702564e-003
            };

            double[] frequencies =
            {
                900,
                910,
                920,
                930,
                940,
                950,
                960,
                970,
                980,
                990,
                1000,
                1010,
                1020,
                1030,
                1040,
                1050,
                1060,
                1070,
                1080,
                1090,
                1100
            };

            double[] target =
            {
                -229.465918533212e-006,
                -238.926661113766e-006,
                -237.668739549207e-006,
                -215.364054404027e-006,
                -154.259961127109e-006,
                -25.6450909504240e-006,
                211.328302694609e-006,
                597.714355880440e-006,
                1.12595107555368e-003,
                1.64674321357226e-003,
                1.86404323386552e-003,
                1.61855652428749e-003,
                1.10370485752431e-003,
                602.389383386658e-006,
                240.470529725761e-006,
                17.1697415512031e-006,
                -107.072059136385e-006,
                -169.426100432009e-006,
                -195.679681710948e-006,
                -201.814527319348e-006,
                -197.237014407641e-006
            };

            var result = Dsp.CalculateGroupDelay(frequencies, phase).ToReadOnlyList();

            FilterAssert.ListsAreReasonablyClose(target, result, 1e-4);

            var p2 = new[] { 4.0, 5, 6, 7 };

            result = Dsp.CalculateGroupDelay(frequencies, p2).ToReadOnlyList();
            Assert.That(result.Count == p2.Length);

            Assert.That(Dsp.CalculateGroupDelay(new List <double>(), phase).ToReadOnlyList().Count == 0);
            Assert.That(Dsp.CalculateGroupDelay(frequencies, new List <double>()).ToReadOnlyList().Count == 0);

            Assert.Throws <ArgumentNullException>(() => Dsp.CalculateGroupDelay(frequencies, null).ToReadOnlyList());
            Assert.Throws <ArgumentNullException>(() => Dsp.CalculateGroupDelay(null, phase).ToReadOnlyList());
        }