Ejemplo n.º 1
0
        public void TestInterpolateComplex()
        {
            double[] x = { 1, 2, 3, 4 };

            Complex[] y =
            {
                Complex.FromPolarCoordinates(1, 1),
                Complex.FromPolarCoordinates(2, 2),
                Complex.FromPolarCoordinates(3, 3),
                Complex.FromPolarCoordinates(4, 4)
            };

            double[] x2 = { 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5 };

            var result = Dsp.InterpolateComplex(x, y, x2).ToReadOnlyList();

            Assert.That(result.Count == x2.Length);
            FilterAssert.ListIsMonotonouslyRising(result.Select(c => c.Magnitude));
            Assert.GreaterOrEqual(result[0].Magnitude, 0);
            Assert.GreaterOrEqual(result[result.Count - 1].Magnitude, 4);
            Assert.LessOrEqual(result[0].Magnitude, 1);
            Assert.LessOrEqual(result[result.Count - 1].Magnitude, 5);

            Assert.Throws <ArgumentNullException>(() => Dsp.InterpolateComplex(null, y, x2).ToReadOnlyList());
            Assert.Throws <ArgumentNullException>(() => Dsp.InterpolateComplex(x, null, x2).ToReadOnlyList());
            Assert.Throws <ArgumentNullException>(() => Dsp.InterpolateComplex(x, y, null).ToReadOnlyList());
            Assert.Catch <Exception>(() => Dsp.InterpolateComplex(x2, y, x2).ToReadOnlyList());
        }
Ejemplo n.º 2
0
        public void TestGenerateSlope()
        {
            var x = new[] { 1.0, 2, 3, 4, 5, 6, 7, 8 };

            var output = Dsp.GenerateSlope(x, 2, 7, -10, 20).ToReadOnlyList();

            Assert.That(output.Count == x.Length);
            Assert.That(output[0] == -10);
            Assert.That(output[output.Count - 1] == 20);
            FilterAssert.ListIsMonotonouslyRising(output);

            var output2 = Dsp.GenerateSlope(x, 7, 2, 20, -10).ToReadOnlyList();

            FilterAssert.ListsAreEqual(output, output2);

            Assert.That(Dsp.GenerateSlope(new List <double>(), 2, 7, 10, 20).ToReadOnlyList().Count == 0);
            Assert.Throws <ArgumentNullException>(() => Dsp.GenerateSlope(null, 2, 7, 10, 20).ToReadOnlyList());
        }
Ejemplo n.º 3
0
        public void TestAdaptiveInterpolationComplex()
        {
            var x = new[] { 0.0, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 3.0, 20.0 };
            var m = new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };

            double[] p =
            {
                0,
                Math.PI * 0.25,
                Math.PI * 0.5,
                Math.PI * 0.75,
                Math.PI,
                Math.PI * 1.25,
                Math.PI * 1.5,
                Math.PI * 1.75,
                Math.PI * 2,
                Math.PI * 2.25
            };

            var x2 = new[] { 0.0, 1.0, 2.0, 3, 4, 5, 6, 7, 8, 9, 10 };

            var y = m.Zip(p, Complex.FromPolarCoordinates).ToReadOnlyList();

            var y2 = Dsp.AdaptiveInterpolation(x, y, x2).ToReadOnlyList();

            Assert.That(y2.Count == x2.Length);
            Assert.That(y2[0] == y[0]);
            FilterAssert.ListIsMonotonouslyRising(y2.Select(c => c.Magnitude));
            Assert.Less(y2[y2.Count - 1].Magnitude, 9.0);
            Assert.Greater(y2[y2.Count - 1].Magnitude, 8.0);

            Assert.That(Dsp.AdaptiveInterpolation(x, y, new List <double>()).ToReadOnlyList().Count == 0);

            Assert.Throws <ArgumentNullException>(() => Dsp.AdaptiveInterpolation(x, y, null).ToReadOnlyList());
            Assert.Throws <ArgumentNullException>(() => Dsp.AdaptiveInterpolation(x, (IReadOnlyList <Complex>)null, x2).ToReadOnlyList());
            Assert.Throws <ArgumentNullException>(() => Dsp.AdaptiveInterpolation(null, y, x2).ToReadOnlyList());
            Assert.Throws <ArgumentException>(() => Dsp.AdaptiveInterpolation(x2, y, x2).ToReadOnlyList());
            Assert.Throws <ArgumentException>(() => Dsp.AdaptiveInterpolation(new List <double>(), new List <Complex>(), x2).ToReadOnlyList());
        }
Ejemplo n.º 4
0
        public void TestAdaptiveInterpolation()
        {
            var x  = new[] { 0.0, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 3.0, 20.0 };
            var y  = new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
            var x2 = new[] { 0.0, 1.0, 2.0, 3, 4, 5, 6, 7, 8, 9, 10 };

            var y2 = Dsp.AdaptiveInterpolation(x, y, x2).ToReadOnlyList();

            Assert.That(y2.Count == x2.Length);
            Assert.That(y2[0] == y[0]);
            FilterAssert.ListIsMonotonouslyRising(y2);
            Assert.Less(y2[y2.Count - 1], 9.0);
            Assert.Greater(y2[y2.Count - 1], 8.0);

            Assert.That(Dsp.AdaptiveInterpolation(x, y, new List <double>()).ToReadOnlyList().Count == 0);

            Assert.Throws <ArgumentNullException>(() => Dsp.AdaptiveInterpolation(x, y, null).ToReadOnlyList());
            Assert.Throws <ArgumentNullException>(() => Dsp.AdaptiveInterpolation(x, (IReadOnlyList <double>)null, x2).ToReadOnlyList());
            Assert.Throws <ArgumentNullException>(() => Dsp.AdaptiveInterpolation(null, y, x2).ToReadOnlyList());
            Assert.Throws <ArgumentException>(() => Dsp.AdaptiveInterpolation(x2, y, x2).ToReadOnlyList());
            Assert.Throws <ArgumentException>(() => Dsp.AdaptiveInterpolation(new List <double>(), new List <double>(), x2).ToReadOnlyList());
        }
Ejemplo n.º 5
0
        public void TestSmooth()
        {
            double[] x = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            double[] y = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            var result = Dsp.Smooth(x, y, 1).ToReadOnlyList();

            Assert.That(result.Count == x.Length);
            Assert.GreaterOrEqual(result[0], 1);
            Assert.LessOrEqual(result[result.Count - 1], 9);
            FilterAssert.ListIsMonotonouslyRising(result);

            FilterAssert.ListsAreReasonablyClose(Dsp.Smooth(x, y, 0).ToReadOnlyList(), y);

            Assert.Catch <ArgumentNullException>(() => Dsp.Smooth(null, y, 1).ToReadOnlyList());
            Assert.Catch <ArgumentNullException>(() => Dsp.Smooth(x, null, 1).ToReadOnlyList());
            Assert.Catch <ArgumentOutOfRangeException>(() => Dsp.Smooth(x, y, -1).ToReadOnlyList());
            Assert.Catch <ArgumentException>(() => Dsp.Smooth(new List <double> {
                1
            }, y, -1).ToReadOnlyList());
            Assert.Catch <ArgumentException>(() => Dsp.Smooth(new List <double>(), new List <double>(), -1).ToReadOnlyList());
        }