public void TestGetNoDisturbances()
        {
            var signal       = new Signal(0, 0, 0, 0, 0, 0, 0, 0);
            var levels       = DWT.ExecuteDWT(signal, CommonMotherWavelets.GetWaveletFromName("db4"), 1);
            var disturbances = levels[0].GetDisturbances(0.01, 2);

            Assert.AreEqual(0, disturbances.Count);
        }
        public void TestGetDisturbances()
        {
            var signal       = new Signal(1, 1, 1, 1, 1, 1, 1, 0.5, 2, 1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 1, 1, 1, 4, 5, 4, 5, 1);
            var levels       = DWT.ExecuteDWT(signal, CommonMotherWavelets.GetWaveletFromName("haar"), 1);
            var disturbances = levels[0].GetDisturbances(0.01, 2);

            Assert.AreEqual(3, disturbances.Count);
        }
        public void TestGetDisturbancesSag()
        {
            var samples = ReadFile("sag.csv");
            var signal  = new Signal(samples);
            var levels  = DWT.ExecuteDWT(signal, CommonMotherWavelets.GetWaveletFromName("db10"), 2);

            var disturbances = levels[1].GetDisturbances(0.001, 10);

            Assert.AreEqual(4, disturbances.Count);
        }
        public void TestGetDisturbances2Levels()
        {
            var signal = new Signal(-10, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 5, 1, 1, 1, 1, 1, 1, 6, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.1, -0.5, 2, -1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1.5, 1.9, 0.2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 10, -11, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 2, 2, 2, -12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 5, -1, 2, 3, 11, 12, -4, -1, -1, 1, 3, 2, 8, 7, 4, 6, 6, 7);
            var levels = DWT.ExecuteDWT(signal, CommonMotherWavelets.GetWaveletFromName("haar"), 2);

            var disturbances = levels[0].GetDisturbances(0.05);

            Assert.AreEqual(10, disturbances.Count);

            disturbances = levels[1].GetDisturbances(0.05);
            Assert.AreEqual(7, disturbances.Count);
        }
示例#5
0
        public void TestIDwtWithManagedFFT()
        {
            var points  = new[] { 5, 6, 7, 8, 1, 2, 3, 4, 2.444, 1.1234 };
            var signal  = new Signal(points, 1);
            var wavelet = MotherWavelet.LoadFromName("haar");
            var levels  = DWT.ExecuteDWT(signal, wavelet, 2, SignalExtension.ExtensionMode.SymmetricWholePoint);
            var output  = DWT.ExecuteIDWT(levels, wavelet);

            Assert.IsTrue(TestUtils.SequenceEquals(output, signal.Samples));

            levels = DWT.ExecuteDWT(signal, wavelet, 3, SignalExtension.ExtensionMode.SymmetricWholePoint);
            output = DWT.ExecuteIDWT(levels, wavelet, 10);
            Assert.IsTrue(TestUtils.SequenceEquals(output, signal.Samples));
        }
示例#6
0
        public void TestDwtTwoLevelsPeriodicPadding()
        {
            var signal  = new Signal(new double[] { 5, 6, 7, 8, 1, 2, 3, 4 }, 1);
            var wavelet = MotherWavelet.LoadFromName("db4");
            var output  = DWT.ExecuteDWT(signal, wavelet, 2, SignalExtension.ExtensionMode.PeriodicPadding); //ppd

            var expectedA1 = new[] { 7.5694222332566481, 2.8360543142223662, 5.4861965643864492, 9.564171098531471, 7.5694222332566481, 2.8360543142223662, 5.4861965643864492 };
            var expectedA2 = new[] { 10.254795056347346, 8.000805703744021, 8.7589053589221, 5.7365738310078322, 12.03931261636461, 6.8935291108651908, 6.79029828331375 };
            var expectedD1 = new[] { -0.34784327691960071, 0.000000040022243075199526, -3.8757500875627819, 1.3951662234727382, -0.34784327691960071, 0.000000040022243075199526, -3.8757500875627819 };
            var expectedD2 = new[] { 2.7173723736570405, 0.48069973385706888, -0.87632966992803074, 1.9614893811889251, -3.7742274826859972, 2.9640617322585006, -3.4730659923310214 };

            Assert.IsTrue(TestUtils.SequenceEquals(output[0].Approximation, expectedA1));
            Assert.IsTrue(TestUtils.SequenceEquals(output[0].Details, expectedD1));
            Assert.IsTrue(TestUtils.SequenceEquals(output[1].Approximation, expectedA2));
            Assert.IsTrue(TestUtils.SequenceEquals(output[1].Details, expectedD2));
        }
示例#7
0
        public void TestDwtTwoLevelsZeroPadding()
        {
            var signal  = new Signal(new double[] { 5, 6, 7, 8, 1, 2, 3, 4 }, 1);
            var wavelet = MotherWavelet.LoadFromName("db4");
            var output  = DWT.ExecuteDWT(signal, wavelet, 2, SignalExtension.ExtensionMode.ZeroPadding);

            var expectedA1 = new[] { 0.10083065061313592, -0.60472387194825949, 1.9356768454450775, 9.564171098531471, 7.4685915826435121, 3.4407781861706259, 3.5505197189413709 };
            var expectedA2 = new[] { 0.0097241173965646223, -0.075213839644193592, 0.22259435703234348, -0.62953234901526167, 11.234286021898358, 6.4201808643834335, 0.81796094874626823 };
            var expectedD1 = new[] { 2.1919660244229693, -0.76429990403022541, -3.712425832764648, 1.3951662234727382, -2.53980930134257, 0.76429994405246893, -0.16332425479813378 };
            var expectedD2 = new[] { 0.21139340497972126, -0.44097376814889744, -1.6517956385039554, 2.0257051634726118, 0.439518138572961, -0.082787884460846284, -0.0376262841822663 };

            Assert.IsTrue(TestUtils.SequenceEquals(output[0].Approximation, expectedA1));
            Assert.IsTrue(TestUtils.SequenceEquals(output[0].Details, expectedD1));
            Assert.IsTrue(TestUtils.SequenceEquals(output[1].Approximation, expectedA2));
            Assert.IsTrue(TestUtils.SequenceEquals(output[1].Details, expectedD2));
        }
示例#8
0
        public void TestDwt()
        {
            var signal  = new Signal(5, 6, 7, 8, 1, 2, 3, 4);
            var wavelet = MotherWavelet.LoadFromName("haar");
            var output  = DWT.ExecuteDWT(signal, wavelet, 1);
            var expectedApproximation = new[] { 7.7781745930520172, 10.606601717798206, 2.1213203435596411, 4.9497474683058291 };
            var expectedDetails       = new[] { -0.707106781186547, -0.707106781186547, -0.707106781186547, -0.707106781186547 };

            foreach (var level in output)
            {
                Console.WriteLine(level.Approximation.ToString());
                Console.WriteLine(level.Details.ToString());
            }

            Assert.IsTrue(TestUtils.SequenceEquals(output[0].Approximation, expectedApproximation));
            Assert.IsTrue(TestUtils.SequenceEquals(output[0].Details, expectedDetails));
        }
示例#9
0
        public async Task <double[][][]> PerformDWT(double[] inputData, MotherWavelet inputWavelet, int maxDecompLevel)
        {
            Signal        signal  = new Signal(inputData);
            MotherWavelet wavelet = inputWavelet;

            double[][][] output = new double[3][][];

            double[][] reconstrData;
            double[][] detailData;
            double[][] approxData;

            detailData   = new double[maxDecompLevel][];
            approxData   = new double[maxDecompLevel][];
            reconstrData = new double[maxDecompLevel][];

            for (int r = 1; r <= maxDecompLevel; r++)
            {
                dwt = DWT.ExecuteDWT(signal, wavelet, r, SignalExtension.ExtensionMode.SymmetricWholePoint, WaveletStudio.Functions.ConvolutionModeEnum.Normal);

                detailData[r - 1] = new double[signal.SamplesCount];
                approxData[r - 1] = new double[signal.SamplesCount];

                reconstrData[r - 1] = new double[signal.SamplesCount];
                reconstrData[r - 1] = DWT.ExecuteIDWT(dwt, wavelet, r, WaveletStudio.Functions.ConvolutionModeEnum.Normal);
            }

            for (int d = 0; d < dwt.Count; d++)
            {
                approxData[d] = dwt[d].Approximation;
                detailData[d] = dwt[d].Details;
            }

            output[0] = detailData;
            output[1] = approxData;
            output[2] = reconstrData;

            return(output);
        }
示例#10
0
        /// <summary>
        /// Executes the block
        /// </summary>
        public override void Execute()
        {
            var connectingNode = InputNodes[0].ConnectingNode as BlockOutputNode;

            if (connectingNode == null || connectingNode.Object == null)
            {
                return;
            }
            var signalIndex = 0;

            OutputNodes[0].Object.Clear();
            OutputNodes[1].Object.Clear();
            OutputNodes[2].Object.Clear();
            OutputNodes[3].Object.Clear();
            foreach (var signal in connectingNode.Object)
            {
                signalIndex++;
                var name = signal.Name;
                if (!string.IsNullOrEmpty(name))
                {
                    name += " - ";
                }
                else
                {
                    name = Resources.Signal + " " + signalIndex + " - ";
                }
                var decompositionLevels = DWT.ExecuteDWT(signal, _motherWavelet, Level, ExtensionMode);
                foreach (var level in decompositionLevels)
                {
                    var apxSignal = signal.Copy();
                    apxSignal.Name    = name + Resources.ApproximationLevel + " " + (level.Index + 1);
                    apxSignal.Samples = level.Approximation;
                    OutputNodes[0].Object.Add(apxSignal);
                    if (Rescale)
                    {
                        var rescaledApx = RescaleSignal(apxSignal, signal, level);
                        OutputNodes[3].Object.Add(rescaledApx);
                    }
                    else
                    {
                        OutputNodes[3].Object.Add(apxSignal);
                    }

                    var detSignal = signal.Copy();
                    detSignal.Name    = name + Resources.DetailsLevel + " " + (level.Index + 1);
                    detSignal.Samples = level.Details;
                    OutputNodes[1].Object.Add(detSignal);
                    if (Rescale)
                    {
                        var rescaledDet = RescaleSignal(detSignal, signal, level);
                        OutputNodes[3].Object.Add(rescaledDet);
                    }
                    else
                    {
                        OutputNodes[3].Object.Add(detSignal);
                    }
                }
                var reconstruction = DWT.ExecuteIDWT(decompositionLevels, _motherWavelet, Level);
                var recSignal      = signal.Copy();
                recSignal.Name    = name + Resources.Reconstruction;
                recSignal.Samples = reconstruction;
                OutputNodes[2].Object.Add(recSignal);
                OutputNodes[3].Object.Add(recSignal);
            }
            if (!Cascade)
            {
                return;
            }
            foreach (var output in OutputNodes.Where(output => output.ConnectingNode != null))
            {
                output.ConnectingNode.Root.Execute();
            }
        }