public void TestExtendAntisymmetricWholePoint() { var points = new double[] { 2, 6, 1, 6, 5, 4, 5, 3, 4 }; var extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.AntisymmetricWholePoint, 3); var expected = new double[] { -2, 3, -2, 2, 6, 1, 6, 5, 4, 5, 3, 4, 5, 3, 4 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 2, 6, 1 }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.AntisymmetricWholePoint, 1); expected = new double[] { -2, 2, 6, 1, -4 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 2 }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.AntisymmetricWholePoint, 1); expected = new double[] { -2, 2, -2 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.AntisymmetricWholePoint, 1); expected = new double[] { 0, 0 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 2, 6, 1, 6, 5, 0 }; SignalExtension.Extend(points, SignalExtension.ExtensionMode.AntisymmetricWholePoint, 8); }
/// <summary> /// Multilevel 1-D Discreete Wavelet Transform /// </summary> /// <param name="signal">The signal. Example: new Signal(5, 6, 7, 8, 1, 2, 3, 4)</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="extensionMode">Signal extension mode</param> /// <param name="convolutionMode">Defines what convolution function should be used</param> /// <returns></returns> public static List <DecompositionLevel> ExecuteDWT(Signal signal, MotherWavelet motherWavelet, int level, SignalExtension.ExtensionMode extensionMode = SignalExtension.ExtensionMode.SymmetricHalfPoint, ConvolutionModeEnum convolutionMode = ConvolutionModeEnum.ManagedFFT) { var levels = new List <DecompositionLevel>(); var approximation = (double[])signal.Samples.Clone(); var details = (double[])signal.Samples.Clone(); var realLength = signal.Samples.Length; for (var i = 1; i <= level; i++) { var extensionSize = motherWavelet.Filters.DecompositionLowPassFilter.Length - 1; approximation = SignalExtension.Extend(approximation, extensionMode, extensionSize); details = SignalExtension.Extend(details, extensionMode, extensionSize); approximation = WaveMath.Convolve(convolutionMode, approximation, motherWavelet.Filters.DecompositionLowPassFilter); approximation = WaveMath.DownSample(approximation); details = WaveMath.Convolve(convolutionMode, details, motherWavelet.Filters.DecompositionHighPassFilter); details = WaveMath.DownSample(details); realLength = realLength / 2; levels.Add(new DecompositionLevel { Signal = signal, Index = i - 1, Approximation = approximation, Details = details }); details = (double[])approximation.Clone(); } return(levels); }
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); }
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)); }
public void TestExtendAntisymmetricHalfPoint() { var points = new double[] { 2, 6, 1, 6, 5, 0, 4, 5, 3, 4 }; var extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.AntisymmetricHalfPoint, 3); var expected = new double[] { -1, -6, -2, 2, 6, 1, 6, 5, 0, 4, 5, 3, 4, -4, -3, -5 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 2, 6, 1 }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.AntisymmetricHalfPoint, 1); expected = new double[] { -2, 2, 6, 1, -1 }; Assert.IsTrue(extended.SequenceEqual(expected)); }
public void TestExtendSmoothPadding0() { var points = new double[] { 2, 6, 1, 6, 5, 0, 4, 5, 3, 4 }; var extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.SmoothPadding0, 3); var expected = new double[] { 2, 2, 2, 2, 6, 1, 6, 5, 0, 4, 5, 3, 4, 4, 4, 4 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 2, 6, 1 }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.SmoothPadding0, 1); expected = new double[] { 2, 2, 6, 1, 1 }; Assert.IsTrue(extended.SequenceEqual(expected)); }
public void TestExtendZeroPadding() { var points = new double[] { 2, 6, 1, 6, 5, 0, 4, 5, 3, 4 }; var extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.ZeroPadding, 3); var expected = new double[] { 0, 0, 0, 2, 6, 1, 6, 5, 0, 4, 5, 3, 4, 0, 0, 0 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 2, 6, 1 }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.ZeroPadding, 1); expected = new double[] { 0, 2, 6, 1, 0 }; Assert.IsTrue(extended.SequenceEqual(expected)); }
public void TestExtendSignal() { var points = new double[] { 2, 6, 1, 6, 5, 0, 4, 5, 3, 4 }; var signal = new Signal(points) { Start = 0, Finish = 9, SamplingRate = 1, SamplingInterval = 1 }; var expected = new double[] { 2, 2, 2, 2, 6, 1, 6, 5, 0, 4, 5, 3, 4, 4, 4, 4 }; SignalExtension.Extend(ref signal, SignalExtension.ExtensionMode.SmoothPadding0, 3, 3); Assert.IsTrue(signal.Samples.SequenceEqual(expected)); Assert.AreEqual(-3, signal.Start); Assert.AreEqual(12, signal.Finish); }
public void TestExtendSymmetricHalfPoint() { var points = new double[] { 2, 6, 1, 6, 5, 0, 4, 5, 3, 4 }; var extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.SymmetricHalfPoint, 3); var expected = new double[] { 1, 6, 2, 2, 6, 1, 6, 5, 0, 4, 5, 3, 4, 4, 3, 5 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 2, 6, 1 }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.SymmetricHalfPoint, 1); expected = new double[] { 2, 2, 6, 1, 1 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 2, 6, 1, 6, 5, 0 }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.SymmetricHalfPoint, 1); expected = new double[] { 2, 2, 6, 1, 6, 5, 0, 0 }; Assert.IsTrue(extended.SequenceEqual(expected)); }
public void TestExtendSmoothPadding1() { var points = new double[] { 2, 6, 1, 6, 5, 0, 4, 5, 3, 4 }; var extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.SmoothPadding1, 3); var expected = new double[] { -10, -6, -2, 2, 6, 1, 6, 5, 0, 4, 5, 3, 4, 5, 6, 7 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 7, 6, 1, 6, 5, 0, 4, 5, 3, 1 }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.SmoothPadding1, 3); expected = new double[] { 10, 9, 8, 7, 6, 1, 6, 5, 0, 4, 5, 3, 1, -1, -3, -5 }; Assert.IsTrue(extended.SequenceEqual(expected)); points = new double[] { 2, 6, 1 }; extended = SignalExtension.Extend(points, SignalExtension.ExtensionMode.SmoothPadding1, 1); expected = new double[] { -2, 2, 6, 1, -4 }; Assert.IsTrue(extended.SequenceEqual(expected)); }
/// <summary> /// Executes the block /// </summary> public override void Execute() { var connectingNode = InputNodes[0].ConnectingNode as BlockOutputNode; if (connectingNode == null || connectingNode.Object == null) { return; } int beforeSize = 0, afterSize = 0; if (ExtensionSize > 0) { beforeSize = ExtensionSize; afterSize = ExtensionSize; } OutputNodes[0].Object.Clear(); foreach (var signal in connectingNode.Object) { if (ExtensionSize <= 0) { var size = SignalExtension.NextPowerOf2(signal.Samples.Length); beforeSize = afterSize = (size - signal.Samples.Length) / 2; while (beforeSize + afterSize + signal.Samples.Length < size) { afterSize++; } } var output = signal.Clone(); SignalExtension.Extend(ref output, ExtensionMode, beforeSize, afterSize); OutputNodes[0].Object.Add(output); } if (Cascade && OutputNodes[0].ConnectingNode != null) { OutputNodes[0].ConnectingNode.Root.Execute(); } }