示例#1
0
        public void SamplesProcessorFunctions_GetDifferenceEquationsTest()
        {
            // Testa a função exponencial
            var func = SamplesProcessorFunctions.GetDifferenceEquationSolver(
                x => 0,
                0.0,
                new double[] { },
                new double[] { 2.0 },
                new double[] { },
                new double[] { 1.0 });
            var expected = 2.0;
            var actual   = func.Invoke(1.0);

            Assert.AreEqual(expected, actual);
            while (expected < 10)
            {
                expected *= 2.0;
                actual    = func.Invoke(expected); // A função de entrada é constante
                Assert.AreEqual(expected, actual);
            }

            // y[n] = 2 * x[n] + 3 * x[n-1] - 2 * y[n-1]
            // x[0] = 0, y[0] = 0
            func = SamplesProcessorFunctions.GetDifferenceEquationSolver(
                x => x,
                2.0,
                new double[] { 3.0 },
                new double[] { 2.0 },
                new double[] { 0.0 },
                new double[] { 0.0 });

            var expectedArray = new double[] { 3.0, 1.0, 13.0, -9.0, 55.0 };

            var t = 1.0;

            for (var i = 0; i < expectedArray.LongLength; ++i)
            {
                expected = expectedArray[i];
                actual   = func.Invoke(t);
                t       += 1;
            }
        }
示例#2
0
        public void SamplesProcessorFunctions_GetFeedbackCompositeTest()
        {
            // y[n] = x[n] + x[n-1] + 0.5 * x[n-2] - y[n-1]
            Func <double, double> func   = x => x;
            Func <double, double> delay1 = SamplesProcessorFunctions.GetDelay(
                func,
                1.0);
            Func <double, double> delay2 = SamplesProcessorFunctions.GetDelay(
                func,
                1.0);
            Func <double, double> delay3 = SamplesProcessorFunctions.GetDelay(
                x => delay2.Invoke(x),
                2.0);
            Func <double, double> xMain = x => x + delay1.Invoke(x) + 0.5 * delay3.Invoke(x);

            var comp = SamplesProcessorFunctions.GetFeedbackComposite(
                (x, ix) => xMain.Invoke(x) - ix,
                1.0);

            // Comparação com o solucionador de equações às diferenças
            var diffSolv = SamplesProcessorFunctions.GetDifferenceEquationSolver(
                func,
                1.0,
                new double[] { 1.0, 0.5 },
                new double[] { -1.0 },
                new double[] { 1.0, 2.0 },
                new double[] { 1.0 });

            var t = 0.0;

            while (t < 100)
            {
                var expected = diffSolv.Invoke(t);
                var actual   = comp.Invoke(t);
                Assert.AreEqual(expected, actual);

                t += 1.0;
            }
        }