public void TestExportToCSVBlockExecute()
        {
            var signalBlock = new GenerateSignalBlock {
                Offset = 1.2, TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var exportBlock = new ExportToCSVBlock {
                ColumnSeparator = "|", DecimalPlaces = 1, IncludeSignalNameInFirstColumn = true
            };

            exportBlock.Execute();

            Assert.IsNotNull(exportBlock.Name);
            Assert.IsNotNull(exportBlock.FilePath);
            Assert.IsNotNull(exportBlock.Description);
            Assert.IsNotNull(exportBlock.ProcessingType);
            signalBlock.ConnectTo(exportBlock);
            signalBlock.Execute();
            var lines = File.ReadAllLines(Path.Combine(Utils.AssemblyDirectory, "output.csv"));

            Assert.AreEqual(1, lines.Length);
            Assert.AreEqual("|1.2|2.2|1.2|2.2|1.2", lines[0]);

            var exportBlock2 = (ExportToCSVBlock)exportBlock.Clone();

            signalBlock.Cascade = false;
            signalBlock.ConnectTo(exportBlock2);
            signalBlock.Execute();
            Assert.AreEqual(0, exportBlock2.OutputNodes.Count);

            signalBlock.Cascade = true;
            signalBlock.OutputNodes[0].Object = null;
            exportBlock2.Execute();
            Assert.AreEqual(0, exportBlock2.OutputNodes.Count);
        }
示例#2
0
        public void TestDownSampleBlockExecute()
        {
            var signalBlock = new GenerateSignalBlock {
                Offset = 1.2, TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var downSampleBlock = new DownSampleBlock();

            downSampleBlock.Execute();

            signalBlock.OutputNodes[0].ConnectTo(downSampleBlock.InputNodes[0]);
            Assert.IsNotNull(downSampleBlock.Name);
            Assert.IsNotNull(downSampleBlock.Description);
            Assert.IsNotNull(downSampleBlock.ProcessingType);

            signalBlock.Execute();
            Assert.AreEqual("1.2 1.2 1.2", downSampleBlock.OutputNodes[0].Object.ToString(1));

            var downSampleBlock2 = (DownSampleBlock)downSampleBlock.Clone();

            downSampleBlock.OutputNodes[0].ConnectTo(downSampleBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual("1.2 1.2", downSampleBlock2.OutputNodes[0].Object.ToString(1));

            downSampleBlock.Cascade = false;
            downSampleBlock2        = (DownSampleBlock)downSampleBlock.Clone();
            downSampleBlock.OutputNodes[0].ConnectTo(downSampleBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual(0, downSampleBlock2.OutputNodes[0].Object.Count);
        }
示例#3
0
        public void TestFFTBlockExecute()
        {
            //Test with periodic signal
            var signalBlock = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 7, SamplingRate = 1, Offset = 1.1
            };
            var fftBlock = new FFTBlock();

            fftBlock.Execute();

            signalBlock.OutputNodes[0].ConnectTo(fftBlock.InputNodes[0]);
            Assert.IsNotNull(fftBlock.Name);
            Assert.IsNotNull(fftBlock.Description);
            Assert.IsNotNull(fftBlock.ProcessingType);

            signalBlock.Execute();
            Assert.AreEqual("3.2 0.0 0.0 0.0", fftBlock.OutputNodes[0].Object.ToString(1));

            //Test cascade
            var scalarBlock = new ScalarOperationBlock {
                Value = 1, Operation = WaveMath.OperationEnum.Sum
            };

            fftBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual("4.2 1.0 1.0 1.0", scalarBlock.OutputNodes[0].Object.ToString(1));

            //Test when cascade is false
            fftBlock.Cascade = false;
            var fftBlock2 = (FFTBlock)fftBlock.Clone();

            fftBlock.OutputNodes[0].ConnectTo(fftBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual(0, fftBlock2.OutputNodes[0].Object.Count);
        }
        public void TestConnection()
        {
            var signalBlock = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var sumBlock = new ScalarOperationBlock {
                Operation = WaveMath.OperationEnum.Sum, Value = 1.5
            };
            var multBlock = new ScalarOperationBlock {
                Operation = WaveMath.OperationEnum.Multiply, Value = 2
            };

            var signalOutputNode = signalBlock.OutputNodes[0];
            var sumInputNode     = sumBlock.InputNodes[0];
            var sumOutputNode    = sumBlock.OutputNodes[0];
            var multInputNode    = multBlock.InputNodes[0];
            var multOutputNode   = multBlock.OutputNodes[0];

            signalOutputNode.ConnectTo(ref sumInputNode);
            sumOutputNode.ConnectTo(ref multInputNode);

            signalBlock.Execute();

            var outputText = multOutputNode.Object.ToString(0);

            Assert.AreEqual("3 5 3 5 3", outputText);
        }
        public void CompareConvolveMethods()
        {
            const int signalLength = 32000;
            const int filterLength = 128;

            //Creates signal and filter by sine wave
            var signalBlock = new GenerateSignalBlock {
                TemplateName = "Sine", Start = 0, Finish = 1, SamplingRate = signalLength, IgnoreLastSample = true
            };

            signalBlock.Execute();
            var signal = signalBlock.OutputNodes[0].Object[0].Samples;
            var filter = new double[filterLength];

            Array.Copy(signal, filter, filterLength);

            //Run Normal convolution and show time
            var stopWatch = new System.Diagnostics.Stopwatch();

            stopWatch.Start();
            var convolvedNormal = WaveMath.ConvolveNormal(signal, filter);

            stopWatch.Stop();
            Console.WriteLine("Normal Convolve {0} samples - {1} ms", convolvedNormal.Length, stopWatch.ElapsedMilliseconds);

            //Run ManagedFFT convolution and show time
            WaveMath.ConvolveManagedFFT(signal, filter);
            stopWatch.Reset();
            stopWatch.Start();
            var convolvedFFT = WaveMath.ConvolveManagedFFT(signal, filter);

            stopWatch.Stop();
            Console.WriteLine("FFT Convolve {0} samples - {1} ms", convolvedFFT.Length, stopWatch.ElapsedMilliseconds);
        }
示例#6
0
        public void TestGenerateSignalBlockExecute()
        {
            var signalBlock = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };

            signalBlock.Execute();

            var newSignal = (GenerateSignalBlock)signalBlock.Clone();

            newSignal.Finish = 6;
            newSignal.Execute();

            Assert.IsNotNull(signalBlock.Name);
            Assert.AreEqual("Binary", signalBlock.GetAssemblyClassName());
            Assert.AreEqual("A=1, F=60, φ=0, D=0; x=0...5, fs=1", signalBlock.Description);
            Assert.IsNotNull(signalBlock.ProcessingType);

            Assert.AreNotSame(signalBlock.OutputNodes[0], newSignal.OutputNodes[0]);
            Assert.AreNotSame(signalBlock.OutputNodes[0].Object, newSignal.OutputNodes[0].Object);

            Assert.AreEqual("0.0 1.0 0.0 1.0 0.0 1.0", newSignal.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual("0.0 1.0 0.0 1.0 0.0", signalBlock.OutputNodes[0].Object.ToString(1));

            signalBlock.Cascade = false;
            var scalarBlock = new ScalarOperationBlock {
                Operation = WaveMath.OperationEnum.Sum, Value = 1.5
            };

            signalBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual(0, scalarBlock.OutputNodes[0].Object.Count);

            try
            {
                //force exception
                signalBlock.TemplateName = "Nonono";
                Assert.Fail("Exception not thrown!");
            }
            catch (Exception)
            {
                Assert.IsTrue(true, "Exception thrown! Yeay!");
            }
        }
示例#7
0
        public void TestIFFTBlockExecute()
        {
            var signalBlock = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 31, SamplingRate = 1, Offset = 1.1
            };
            var fftBlock  = new FFTBlock();
            var ifftBlock = new IFFTBlock();

            ifftBlock.Execute();

            signalBlock.OutputNodes[0].ConnectTo(fftBlock.InputNodes[0]);
            fftBlock.OutputNodes[1].ConnectTo(ifftBlock.InputNodes[0]);
            Assert.IsNotNull(ifftBlock.Name);
            Assert.IsNotNull(ifftBlock.Description);
            Assert.IsNotNull(ifftBlock.ProcessingType);

            signalBlock.Execute();
            Assert.AreEqual("1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1 1.1 2.1", ifftBlock.OutputNodes[0].Object.ToString(1));

            //Test cascade
            var scalarBlock = new ScalarOperationBlock {
                Value = 1, Operation = WaveMath.OperationEnum.Sum
            };

            ifftBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual("2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1 2.1 3.1", scalarBlock.OutputNodes[0].Object.ToString(1));

            //Test when cascade is false
            fftBlock.Cascade = false;
            var ifftBlock2 = (IFFTBlock)ifftBlock.Clone();

            ifftBlock.OutputNodes[0].ConnectTo(ifftBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual(0, ifftBlock2.OutputNodes[0].Object.Count);

            ifftBlock2.Cascade = false;
            ifftBlock2.Execute();
            Assert.IsNotNull(ifftBlock2.OutputNodes[0].Object[0]);
        }
        public void TestScalarOperationBlockExecute()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");

            var signalBlock = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var scalarBlock = new ScalarOperationBlock
            {
                Operation = WaveMath.OperationEnum.Sum, Value = 1.5
            };

            scalarBlock.Execute();

            signalBlock.OutputNodes[0].ConnectTo(scalarBlock.InputNodes[0]);
            Assert.IsNotNull(scalarBlock.Name);
            Assert.IsNotNull(scalarBlock.Description);
            Assert.IsNotNull(scalarBlock.ProcessingType);

            signalBlock.Execute();
            Assert.AreEqual("1.5 2.5 1.5 2.5 1.5", scalarBlock.OutputNodes[0].Object.ToString(1));

            scalarBlock.Operation = WaveMath.OperationEnum.Multiply;
            signalBlock.Execute();
            Assert.AreEqual("0.0 1.5 0.0 1.5 0.0", scalarBlock.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual("ScalarMultiply", scalarBlock.GetAssemblyClassName());

            scalarBlock.Operation = WaveMath.OperationEnum.Subtract;
            signalBlock.Execute();
            Assert.AreEqual("-1.5 -0.5 -1.5 -0.5 -1.5", scalarBlock.OutputNodes[0].Object.ToString(1));

            scalarBlock.Operation = WaveMath.OperationEnum.Divide;
            signalBlock.Execute();
            Assert.AreEqual("0.00 0.67 0.00 0.67 0.00", scalarBlock.OutputNodes[0].Object.ToString(2));

            var scalarBlock2 = (ScalarOperationBlock)scalarBlock.Clone();

            scalarBlock2.Operation = WaveMath.OperationEnum.Sum;
            scalarBlock2.Value     = 3.1;
            scalarBlock.OutputNodes[0].ConnectTo(scalarBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual("3.10 3.77 3.10 3.77 3.10", scalarBlock2.OutputNodes[0].Object.ToString(2));

            scalarBlock.Cascade = false;
            scalarBlock2        = (ScalarOperationBlock)scalarBlock.Clone();
            scalarBlock.OutputNodes[0].ConnectTo(scalarBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual(0, scalarBlock2.OutputNodes[0].Object.Count);
        }
示例#9
0
        public void TestBlockList()
        {
            var signalBlock1 = new GenerateSignalBlock {
                Cascade = false, Offset = 1, TemplateName = "Binary", Start = 0, Finish = 3, SamplingRate = 1
            };
            var signalBlock2 = new GenerateSignalBlock {
                Cascade = false, Offset = 2, TemplateName = "Binary", Start = 0, Finish = 3, SamplingRate = 1
            };
            var signalBlock3 = new GenerateSignalBlock {
                Offset = 3, TemplateName = "Binary", Start = 0, Finish = 3, SamplingRate = 1
            };
            var convolutionBlock1 = new ConvolutionBlock();
            var convolutionBlock2 = new ConvolutionBlock();
            var blockList         = new BlockList {
                signalBlock1, signalBlock2, signalBlock3, convolutionBlock1, convolutionBlock2
            };

            signalBlock1.ConnectTo(convolutionBlock1);
            signalBlock2.ConnectTo(convolutionBlock1);
            convolutionBlock1.ConnectTo(convolutionBlock2);
            signalBlock2.ConnectTo(convolutionBlock2);
            blockList.ExecuteAll();

            Assert.AreEqual("4 20 45 78 111 114 103 74 33 18", convolutionBlock2.OutputNodes[0].Object.ToString(0));

            convolutionBlock1 = new ConvolutionBlock();
            convolutionBlock1.InputNodes.Clear();
            signalBlock1.ConnectTo(convolutionBlock1);
            signalBlock1.Execute();
            Assert.AreEqual(0, convolutionBlock1.OutputNodes[0].Object.Count);

            convolutionBlock1 = new ConvolutionBlock();
            signalBlock1      = new GenerateSignalBlock();
            signalBlock2.OutputNodes.Clear();
            signalBlock2.ConnectTo(convolutionBlock1);
            signalBlock1.ConnectTo(convolutionBlock1);
            signalBlock1.Execute();
            Assert.AreEqual(0, convolutionBlock1.OutputNodes[0].Object.Count);
        }
示例#10
0
        public void TestSampleBasedOperationBlockExecute()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
            var signalBlock1 = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var signalBlock2 = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var block = new LogicOperationBlock {
                Operation = WaveMath.LogicalOperationEnum.Or
            };

            block.Execute();

            signalBlock1.OutputNodes[0].ConnectTo(block.InputNodes[0]);
            signalBlock2.OutputNodes[0].ConnectTo(block.InputNodes[1]);
            Assert.IsNotNull(block.Name);
            Assert.IsNotNull(block.Description);
            Assert.IsNotNull(block.ProcessingType);
            Assert.AreEqual("Or", block.GetAssemblyClassName());

            signalBlock1.Execute();
            signalBlock2.Execute();
            Assert.AreEqual("0 1 0 1 0", block.OutputNodes[0].Object.ToString(0));

            var block2 = (LogicOperationBlock)block.Clone();

            block2.Operation = WaveMath.LogicalOperationEnum.NotOr;
            block.OutputNodes[0].ConnectTo(block2.InputNodes[0]);
            signalBlock2.OutputNodes[0].ConnectTo(block2.InputNodes[1]);
            signalBlock1.Execute();
            signalBlock2.Execute();
            Assert.AreEqual("1 0 1 0 1", block2.OutputNodes[0].Object[0].ToString(0));

            block.Cascade = false;
            block2        = (LogicOperationBlock)block.Clone();
            block.OutputNodes[0].ConnectTo(block2.InputNodes[0]);
            signalBlock1.Execute();
            Assert.AreEqual(0, block2.OutputNodes[0].Object.Count);
            Assert.AreEqual("", block2.OutputNodes[0].Object.ToString(0));

            signalBlock1 = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 3, SamplingRate = 1, IgnoreLastSample = true
            };
            signalBlock2 = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            signalBlock1.OutputNodes[0].ConnectTo(block.InputNodes[0]);
            signalBlock2.OutputNodes[0].ConnectTo(block.InputNodes[1]);
            signalBlock1.Execute();
            signalBlock2.Execute();
            signalBlock2.OutputNodes[0].Object.Add(new Signal(new double[] { 1, 2, 3, 4 }));
            block.Execute();
            Assert.AreEqual("0 1 0 0 0", block.OutputNodes[0].Object[0].ToString(0));
            Assert.AreEqual("1 1 1 0", block.OutputNodes[0].Object[1].ToString(0));

            signalBlock2.OutputNodes[0].Object.Clear();
            block.Execute();
            Assert.AreEqual(1, block.OutputNodes[0].Object.Count);
            Assert.AreEqual("0 1 0", block.OutputNodes[0].Object[0].ToString(0));
        }
        public void TestRelationalOperatorBlockTest()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
            var signalBlock1 = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var signalBlock2 = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, Phase = 0.5, SamplingRate = 1, IgnoreLastSample = true
            };
            var block = new RelationalOperatorBlock {
                Operation = WaveMath.RelationalOperatorEnum.GreaterThan
            };

            block.Execute();
            signalBlock1.Execute();
            signalBlock2.Execute();

            signalBlock1.OutputNodes[0].ConnectTo(block.InputNodes[0]);
            signalBlock2.OutputNodes[0].ConnectTo(block.InputNodes[1]);
            Assert.IsNotNull(block.Name);
            Assert.IsNotNull(block.Description);
            Assert.IsNotNull(block.ProcessingType);
            Assert.AreEqual("GreaterThan", block.GetAssemblyClassName());

            block.Operand = RelationalOperatorBlock.OperandEnum.Signal;
            block.Execute();
            Assert.AreEqual("0 1 0 1 0", block.OutputNodes[0].Object.ToString(0));

            block.Operand   = RelationalOperatorBlock.OperandEnum.PreviousSample;
            block.Operation = WaveMath.RelationalOperatorEnum.LessThan;
            block.Execute();
            Assert.AreEqual("0 0 1 0 1", block.OutputNodes[0].Object.ToString(0));

            block.Operand   = RelationalOperatorBlock.OperandEnum.NextSample;
            block.Operation = WaveMath.RelationalOperatorEnum.LessThan;
            block.Execute();
            Assert.AreEqual("1 0 1 0 0", block.OutputNodes[0].Object.ToString(0));

            block.Operand     = RelationalOperatorBlock.OperandEnum.StaticValue;
            block.Operation   = WaveMath.RelationalOperatorEnum.GreaterOrEqualsThan;
            block.ScalarValue = 1;
            block.Execute();
            Assert.AreEqual("0 1 0 1 0", block.OutputNodes[0].Object.ToString(0));

            var block2 = (RelationalOperatorBlock)block.Clone();

            block2.Operation = WaveMath.RelationalOperatorEnum.GreaterOrEqualsThan;
            block.OutputNodes[0].ConnectTo(block2.InputNodes[0]);
            signalBlock2.OutputNodes[0].ConnectTo(block2.InputNodes[1]);
            signalBlock1.Execute();
            signalBlock2.Execute();
            Assert.AreEqual("0 1 0 1 0", block2.OutputNodes[0].Object[0].ToString(0));

            block.Cascade = false;
            block2        = (RelationalOperatorBlock)block.Clone();
            block.OutputNodes[0].ConnectTo(block2.InputNodes[0]);
            block.Operand = RelationalOperatorBlock.OperandEnum.Signal;
            signalBlock1.Execute();
            Assert.AreEqual(0, block2.OutputNodes[0].Object.Count);
            Assert.AreEqual("", block2.OutputNodes[0].Object.ToString(0));

            signalBlock1 = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 3, SamplingRate = 1, IgnoreLastSample = true
            };
            signalBlock2 = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            signalBlock1.OutputNodes[0].ConnectTo(block.InputNodes[0]);
            signalBlock2.OutputNodes[0].ConnectTo(block.InputNodes[1]);
            signalBlock1.Execute();
            signalBlock2.Execute();
            signalBlock2.OutputNodes[0].Object.Add(new Signal(new double[] { 1, 2, 3, 4 }));
            block.Execute();
            Assert.AreEqual("1 1 1 0 0", block.OutputNodes[0].Object[0].ToString(0));

            signalBlock2.OutputNodes[0].Object.Clear();
            block.Execute();
            Assert.AreEqual(1, block.OutputNodes[0].Object.Count);
            Assert.AreEqual("1 1 1", block.OutputNodes[0].Object[0].ToString(0));

            block2.InputNodes[1].ConnectingNode = null;
            block2.Operand = RelationalOperatorBlock.OperandEnum.Signal;
            block2.Execute();
            Assert.AreEqual(0, block2.OutputNodes[0].Object.Count);

            block2         = (RelationalOperatorBlock)block.Clone();
            block2.Operand = RelationalOperatorBlock.OperandEnum.Signal;
            block.ConnectTo(block2);
            signalBlock1.ConnectTo(block2);
            block2.Operand = RelationalOperatorBlock.OperandEnum.Signal;
            block2.Execute();
            Assert.AreEqual("1 1 1", block2.OutputNodes[0].Object[0].ToString(0));

            ((BlockOutputNode)block2.InputNodes[0].ConnectingNode).Object.Add(signalBlock1.OutputNodes[0].Object[0].Clone());
            block2.Execute();
            Assert.AreEqual("1 1 1", block2.OutputNodes[0].Object[0].ToString(0));
            Assert.AreEqual("1 1 1", block2.OutputNodes[0].Object[1].ToString(0));
        }
        public void TestConvolutionBlockExecute()
        {
            var signalBlock1 = new GenerateSignalBlock {
                Offset = 1.2, TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var signalBlock2 = new GenerateSignalBlock {
                Offset = 2.3, TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var convolutionBlock = new ConvolutionBlock {
                ReturnOnlyValid = true
            };

            convolutionBlock.Execute();

            signalBlock1.OutputNodes[0].ConnectTo(convolutionBlock.InputNodes[0]);
            signalBlock2.OutputNodes[0].ConnectTo(convolutionBlock.InputNodes[1]);
            Assert.IsNotNull(convolutionBlock.Name);
            Assert.IsNotNull(convolutionBlock.Description);
            Assert.IsNotNull(convolutionBlock.ProcessingType);

            signalBlock1.Execute();
            Assert.AreEqual("1.2 2.2 1.2 2.2 1.2", convolutionBlock.Output[0].ToString(1));

            signalBlock2.Execute();
            Assert.IsNotNull(convolutionBlock.OutputNodes[0].Object);
            Assert.AreEqual("22.80", convolutionBlock.Output[0].ToString(2));

            convolutionBlock.ReturnOnlyValid = false;
            signalBlock1.Execute();
            Assert.AreEqual("2.76 9.02 12.78 18.04 22.80 18.04 12.78 9.02 2.76", convolutionBlock.Output[0].ToString(2));

            var convolutionBlock2 = (ConvolutionBlock)convolutionBlock.Clone();

            convolutionBlock.OutputNodes[0].ConnectTo(convolutionBlock2.InputNodes[0]);
            signalBlock2.OutputNodes[0].ConnectTo(convolutionBlock2.InputNodes[1]);
            signalBlock2.Execute();
            Assert.AreEqual("6.348 29.854 65.508 113.520 177.480 221.144 230.292 221.144 177.480 113.520 65.508 29.854 6.348",
                            convolutionBlock2.Output[0].ToString(3));

            signalBlock1.OutputNodes[0].Object.Add(new Signal(new double[] { 1, 2, 3, 4 }));
            convolutionBlock.Execute();
            Assert.AreEqual("2.300 7.900 15.800 27.000 29.000 23.700 20.100 0.000", convolutionBlock.Output[0, 1].ToString(3));

            convolutionBlock2        = (ConvolutionBlock)convolutionBlock.Clone();
            convolutionBlock.Cascade = false;
            convolutionBlock.OutputNodes[0].ConnectTo(convolutionBlock2.InputNodes[0]);
            convolutionBlock.Execute();
            Assert.AreEqual(0, convolutionBlock2.OutputNodes[0].Object.Count);

            convolutionBlock.Cascade = true;
            convolutionBlock.OutputNodes[0].ConnectTo(convolutionBlock2.InputNodes[0]);
            signalBlock2.OutputNodes[0].ConnectTo(convolutionBlock2.InputNodes[1]);
            convolutionBlock.Execute();
            Assert.IsNotNull(convolutionBlock2.OutputNodes[0].Object);

            convolutionBlock.Cascade = true;
            convolutionBlock2.OutputNodes[0].Object        = null;
            convolutionBlock.OutputNodes[0].ConnectingNode = null;
            signalBlock2.OutputNodes[0].ConnectingNode     = null;
            convolutionBlock.Execute();
            Assert.IsNull(convolutionBlock2.OutputNodes[0].Object);
        }
示例#13
0
        public void TestScaleBlockExecute()
        {
            var signalBlock = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 5, SamplingRate = 1, IgnoreLastSample = true
            };
            var scaleBlock = new ScaleBlock
            {
                TimeScalingFactor      = 2,
                AmplitudeScalingFactor = 0.5
            };

            scaleBlock.Execute();

            signalBlock.OutputNodes[0].ConnectTo(scaleBlock.InputNodes[0]);
            Assert.IsNotNull(scaleBlock.Name);
            Assert.IsNotNull(scaleBlock.Description);
            Assert.IsNotNull(scaleBlock.ProcessingType);

            signalBlock.Execute();
            Assert.AreEqual("0.0 0.5 0.0 0.5 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual(0, scaleBlock.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(10, scaleBlock.OutputNodes[0].Object[0].Finish);

            scaleBlock.TimeScalingFactor = 1;
            signalBlock.Execute();
            Assert.AreEqual("0.0 0.5 0.0 0.5 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual("ScaleBlock", scaleBlock.GetAssemblyClassName());
            Assert.AreEqual(0, scaleBlock.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(5, scaleBlock.OutputNodes[0].Object[0].Finish);

            scaleBlock.AmplitudeScalingFactor = 1;
            signalBlock.Execute();
            Assert.AreEqual("0.0 1.0 0.0 1.0 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));

            scaleBlock.TimeScalingFactor = -1;
            Assert.AreEqual(0, scaleBlock.TimeScalingFactor);
            signalBlock.Execute();
            Assert.AreEqual("0.0 1.0 0.0 1.0 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));

            scaleBlock.AmplitudeScalingFactor = -1;
            Assert.AreEqual(0, scaleBlock.AmplitudeScalingFactor);
            signalBlock.Execute();
            Assert.AreEqual("0.0 0.0 0.0 0.0 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual(0, scaleBlock.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(5, scaleBlock.OutputNodes[0].Object[0].Finish);

            scaleBlock.AmplitudeScalingFactor = 5;
            scaleBlock.TimeScalingFactor      = 2;
            signalBlock.Execute();
            Assert.AreEqual("0.0 5.0 0.0 5.0 0.0", scaleBlock.OutputNodes[0].Object.ToString(1));
            Assert.AreEqual(0, scaleBlock.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(10, scaleBlock.OutputNodes[0].Object[0].Finish);

            var scaleBlock2 = (ScaleBlock)scaleBlock.Clone();

            scaleBlock2.AmplitudeScalingFactor = 3;
            scaleBlock2.TimeScalingFactor      = 2;
            scaleBlock.OutputNodes[0].ConnectTo(scaleBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual("0.00 15.00 0.00 15.00 0.00", scaleBlock2.OutputNodes[0].Object.ToString(2));
            Assert.AreEqual(0, scaleBlock2.OutputNodes[0].Object[0].Start);
            Assert.AreEqual(20, scaleBlock2.OutputNodes[0].Object[0].Finish);

            scaleBlock.Cascade = false;
            scaleBlock2        = (ScaleBlock)scaleBlock.Clone();
            scaleBlock.OutputNodes[0].ConnectTo(scaleBlock2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual(0, scaleBlock2.OutputNodes[0].Object.Count);
        }
示例#14
0
        public void TestWaveletBlockExecute()
        {
            var signalBlock = new GenerateSignalBlock {
                TemplateName = "Binary", Start = 0, Finish = 10, SamplingRate = 1, IgnoreLastSample = true
            };
            var waveletBlock = new DWTBlock
            {
                WaveletName   = "db4|Daubechies 4",
                Level         = 2,
                ExtensionMode = SignalExtension.ExtensionMode.SymmetricHalfPoint
            };

            waveletBlock.Execute();
            Assert.IsTrue(waveletBlock.WaveletNameList.Count > 0);
            Assert.AreEqual("db4|Daubechies 4", waveletBlock.WaveletName);

            signalBlock.OutputNodes[0].ConnectTo(waveletBlock.InputNodes[0]);
            Assert.IsNotNull(waveletBlock.Name);
            Assert.IsNotNull(waveletBlock.Description);
            Assert.IsNotNull(waveletBlock.ProcessingType);

            signalBlock.Execute();
            Assert.AreEqual("0.7 0.9 0.2 0.7 0.7 0.8 0.5 1.2", waveletBlock.OutputNodes[0].Object[0].ToString(1));
            Assert.AreEqual("1.0 0.8 1.1 0.8 1.0 0.8 1.6", waveletBlock.OutputNodes[0].Object[1].ToString(1));
            Assert.AreEqual("-0.2 -0.8 -0.7 -0.7 -0.7 0.2 0.8 0.7", waveletBlock.OutputNodes[1].Object[0].ToString(1));
            Assert.AreEqual("-0.1 -0.4 0.0 -0.3 0.1 0.2 0.1", waveletBlock.OutputNodes[1].Object[1].ToString(1));
            Assert.AreEqual(signalBlock.OutputNodes[0].Object.ToString(1), waveletBlock.OutputNodes[2].Object[0].ToString(1));
            Assert.AreEqual(5, waveletBlock.OutputNodes[3].Object.Count);
            Assert.AreEqual("0.7 0.9 0.2 0.7 0.7 0.8 0.5 1.2", waveletBlock.OutputNodes[3].Object[0].ToString(1));
            Assert.AreEqual("-0.2 -0.8 -0.7 -0.7 -0.7 0.2 0.8 0.7", waveletBlock.OutputNodes[3].Object[1].ToString(1));
            Assert.AreEqual("1.0 0.8 1.1 0.8 1.0 0.8 1.6", waveletBlock.OutputNodes[3].Object[2].ToString(1));
            Assert.AreEqual("-0.1 -0.4 0.0 -0.3 0.1 0.2 0.1", waveletBlock.OutputNodes[3].Object[3].ToString(1));
            Assert.AreEqual(signalBlock.OutputNodes[0].Object.ToString(1), waveletBlock.OutputNodes[3].Object[4].ToString(1));

            var block2 = (DWTBlock)waveletBlock.Clone();

            block2.WaveletName = "db4";
            signalBlock.OutputNodes[0].ConnectTo(block2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual("0.7 0.9 0.2 0.7 0.7 0.8 0.5 1.2", block2.OutputNodes[0].Object[0].ToString(1));

            waveletBlock.Cascade = false;
            block2 = (DWTBlock)waveletBlock.Clone();
            waveletBlock.OutputNodes[0].ConnectTo(block2.InputNodes[0]);
            signalBlock.Execute();
            Assert.AreEqual(0, block2.OutputNodes[0].Object.Count);

            waveletBlock.Cascade = true;
            signalBlock.ConnectTo(waveletBlock);
            waveletBlock.ConnectTo(block2);
            waveletBlock.Execute();
            Assert.AreEqual(4, block2.OutputNodes[0].Object.Count);

            try
            {
                waveletBlock.WaveletName = "nonono";
                Assert.Fail("Exception not thrown!");
            }
            catch (Exception)
            {
                Assert.IsTrue(true, "Exception thrown! Yeay!");
            }
        }