Ejemplo n.º 1
0
        private static Signal RescaleSignal(Signal decomposition, Signal signal, DecompositionLevel level)
        {
            var rescaled = WaveMath.InterpolateCubic(decomposition, (uint)Math.Pow(2, level.Index + 1));

            if (rescaled.SamplesCount < signal.SamplesCount)
            {
                var extensionSize = signal.SamplesCount - rescaled.SamplesCount;
                int right;
                var left = right = extensionSize / 2;
                if (left + right != extensionSize)
                {
                    left++;
                }

                SignalExtension.Extend(ref rescaled, SignalExtension.ExtensionMode.SmoothPadding0, left, right);
            }
            else
            {
                rescaled.Samples = SignalExtension.Deextend(rescaled.Samples, signal.SamplesCount);
            }
            rescaled.CustomPlot       = null;
            rescaled.Finish           = signal.Finish;
            rescaled.SamplingRate     = signal.SamplingRate;
            rescaled.SamplingInterval = signal.SamplingInterval;
            return(rescaled);
        }
Ejemplo n.º 2
0
        public void TestDeextend()
        {
            var points     = new double[] { 2, 6, 1, 6, 5, 0, 4, 5, 3, 4 };
            var extended   = SignalExtension.Extend(points, SignalExtension.ExtensionMode.SymmetricHalfPoint, 100);
            var deextended = SignalExtension.Deextend(extended, points.Length);

            Assert.IsTrue(deextended.SequenceEqual(points));

            points     = new double[] { 1, 2 };
            deextended = SignalExtension.Deextend(points, 1);
            Assert.IsTrue(deextended.SequenceEqual(points));
        }
Ejemplo 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);
        }