/// <summary> /// Executes the block /// </summary> public override void Execute() { var inputNode1 = InputNodes[0].ConnectingNode as BlockOutputNode; var inputNode2 = InputNodes[1].ConnectingNode as BlockOutputNode; if (inputNode1 == null || inputNode1.Object == null || inputNode2 == null || inputNode2.Object == null) { return; } OutputNodes[0].Object.Clear(); var approximations = inputNode1.Object; var details = inputNode2.Object; var tempLevels = new List <DecompositionLevel>(); var outputs = new List <Signal>(); var currentName = ""; for (var i = 0; i < approximations.Count; i++) { var name = approximations[i].Name != null ? approximations[i].Name.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries)[0] : Resources.Signal; if (name != currentName && currentName != "") { outputs.Add(new Signal(DWT.ExecuteIDWT(tempLevels, _motherWavelet, Level)) { Name = name }); tempLevels = new List <DecompositionLevel>(); } currentName = name; if (approximations[i].Samples != null && i < details.Count && details[i].Samples != null) { var level = new DecompositionLevel { Approximation = approximations[i].Samples, Details = details[i].Samples, Index = i }; tempLevels.Add(level); } if (i != approximations.Count - 1) { continue; } outputs.Add(new Signal(DWT.ExecuteIDWT(tempLevels, _motherWavelet, Level)) { Name = name }); } OutputNodes[0].Object = outputs; if (Cascade && OutputNodes[0].ConnectingNode != null) { OutputNodes[0].ConnectingNode.Root.Execute(); } }
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)); }
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); }
/// <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(); } }