Пример #1
0
        /// <summary>
        /// Executes the block
        /// </summary>
        public override void Execute()
        {
            var inputNode = InputNodes[0].ConnectingNode as BlockOutputNode;

            if (inputNode == null || inputNode.Object == null)
            {
                return;
            }

            OutputNodes[0].Object.Clear();
            OutputNodes[1].Object.Clear();
            foreach (var inputSignal in inputNode.Object)
            {
                var fft = WaveMath.UpSample(inputSignal.Samples);
                ManagedFFT.Instance.FFT(ref fft, true, Mode);
                var abs = WaveMath.AbsFromComplex(fft, 0, fft.Length / 2);
                abs = WaveMath.Normalize(abs, abs.Length);

                var absSignal = new Signal(abs)
                {
                    Start  = 0,
                    Finish = abs.Length - 1
                };
                var fftSignal = new Signal(fft)
                {
                    Start            = 0,
                    Finish           = fft.Length - 1,
                    IsComplex        = true,
                    SamplingInterval = fft.Length
                };

                OutputNodes[0].Object.Add(absSignal);
                OutputNodes[1].Object.Add(fftSignal);
            }

            if (Cascade && OutputNodes[0].ConnectingNode != null)
            {
                OutputNodes[0].ConnectingNode.Root.Execute();
            }
            if (Cascade && OutputNodes[1].ConnectingNode != null)
            {
                OutputNodes[1].ConnectingNode.Root.Execute();
            }
        }
Пример #2
0
        public void TestAbsFromComplex()
        {
            var input    = new[] { 2.1, 3.2, 1, -1.3, -100, 145, -2 };
            var expected = new[] { 3.8275318418009276, 1.6401219466856727, 176.13914953808538, 2 };

            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.AbsFromComplex(input)));

            var signal = new Signal(input)
            {
                IsComplex = true
            };

            WaveMath.Abs(ref signal, input);
            Assert.IsTrue(TestUtils.SequenceEquals(expected, signal.Samples));

            input    = new double[] { };
            expected = new double[] { };
            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.AbsFromComplex(input)));
        }