예제 #1
0
        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);
        }
예제 #2
0
        public void TestConvolve()
        {
            var signal    = new double[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var filter    = new double[] { 1, 2, 3 };
            var convolved = WaveMath.Convolve(ConvolutionModeEnum.Normal, signal, filter);
            var expected  = new double[] { 10, 16, 22, 28, 34, 40 };

            Assert.IsTrue(convolved.SequenceEqual(expected));

            signal    = new double[] { 1, 2, 3 };
            filter    = new double[] { 1, 2, 3, 4, 5 };
            convolved = WaveMath.ConvolveNormal(signal, filter);
            expected  = new double[] { 10, 16, 22 };
            Assert.IsTrue(convolved.SequenceEqual(expected));

            signal    = new double[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            filter    = new double[] { 1, 2, 3, 4 };
            convolved = WaveMath.ConvolveNormal(signal, filter, false);
            expected  = new double[] { 1, 4, 10, 20, 30, 40, 50, 60, 61, 52, 32 };
            Assert.IsTrue(convolved.SequenceEqual(expected));
        }