public void TestAddScalar()
        {
            var          array1   = new[] { 1.2, 2.3, 3.4, 4.5 };
            const double scalar   = 1.1;
            var          expected = new[] { 2.3, 3.4, 4.5, 5.6 };

            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.Add(array1, scalar)));
        }
        public void TestAddArrays()
        {
            var array1    = new[] { 1.2, 2.3, 3.4, 4.5 };
            var array2    = new[] { 1.1, 2.2, 3.3, 0 };
            var expected  = new[] { 2.3, 4.5, 6.7, 4.5 };
            var expected2 = new[] { 2.3, 4.5, 6.7, 0 };

            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.GetOperationFunction(WaveMath.OperationEnum.Sum)(array1, array2)));
            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.Add(array2, array1)));
            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.Add(array1, array2.SubArray(3))));
            Assert.IsTrue(TestUtils.SequenceEquals(expected2, WaveMath.Add(array1.SubArray(3), array2)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Multilevel inverse discrete 1-D wavelet transform
        /// </summary>
        /// <param name="decompositionLevels">The decomposition levels of the DWT</param>
        /// <param name="motherWavelet">The mother wavelet to be used. Example: CommonMotherWavelets.GetWaveletFromName("DB4") </param>
        /// <param name="level">The depth-level to perform the DWT</param>
        /// <param name="convolutionMode">Defines what convolution function should be used</param>
        /// <returns></returns>
        public static double[] ExecuteIDWT(List <DecompositionLevel> decompositionLevels, MotherWavelet motherWavelet, int level = 0, ConvolutionModeEnum convolutionMode = ConvolutionModeEnum.ManagedFFT)
        {
            if (level == 0 || level > decompositionLevels.Count)
            {
                level = decompositionLevels.Count;
            }
            if (level <= 0)
            {
                return(null);
            }
            var approximation = (double[])decompositionLevels[level - 1].Approximation.Clone();
            var details       = (double[])decompositionLevels[level - 1].Details.Clone();

            for (var i = level - 1; i >= 0; i--)
            {
                approximation = WaveMath.UpSample(approximation);
                approximation = WaveMath.Convolve(convolutionMode, approximation, motherWavelet.Filters.ReconstructionLowPassFilter, true, -1);

                details = WaveMath.UpSample(details);
                details = WaveMath.Convolve(convolutionMode, details, motherWavelet.Filters.ReconstructionHighPassFilter, true, -1);

                //sum approximation with details
                approximation = WaveMath.Add(approximation, details);

                if (i <= 0)
                {
                    continue;
                }
                if (approximation.Length > decompositionLevels[i - 1].Details.Length)
                {
                    approximation = SignalExtension.Deextend(approximation, decompositionLevels[i - 1].Details.Length);
                }

                details = (double[])decompositionLevels[i - 1].Details.Clone();
            }

            return(approximation);
        }