private void LoadPlot(object param) { SignalRepresentation signalRepresentation; switch (param.ToString()) { case "1": signalRepresentation = FirstChart.SignalRepresentation; FirstChart.SelectedIndex = -1; break; case "2": signalRepresentation = SecondChart.SignalRepresentation; SecondChart.SelectedIndex = -1; break; default: throw new ArgumentException(); } Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog { Filter = "*All Files | *.xD" }; if (dlg.ShowDialog() == false) { return; } using (BinaryReader reader = new BinaryReader(File.Open(dlg.FileName, FileMode.Open))) { SignalImplementation signalImplementation = new SignalImplementation { Points = new List <Tuple <double, Complex> >() }; while (reader.BaseStream.Position != reader.BaseStream.Length) { double xCoordinate = reader.ReadDouble(); Complex value = new Complex { Real = reader.ReadDouble(), Imaginary = reader.ReadDouble() }; signalImplementation.Points.Add(new Tuple <double, Complex>(xCoordinate, value)); } signalImplementation.StartingMoment = signalImplementation.Points[0].Item1; signalImplementation.EndingMoment = signalImplementation.Points[signalImplementation.Points.Count - 1].Item1; signalImplementation.CalculateTraits(); signalRepresentation.Signal = signalImplementation; } }
private void CombineSignals(Func <ISignal, ISignal, SignalImplementation> func, SignalTextProperties textTraits) { SignalImplementation outputSignal = func(firstChart.SignalRepresentation.Signal, secondChart.SignalRepresentation.Signal); realPlotModel.Axes.Clear(); imaginaryPlotModel.Axes.Clear(); realCombinedSeries = new ScatterSeries(); imaginaryCombinedSeries = new ScatterSeries(); realCombinedSeries.MarkerType = MarkerType.Circle; imaginaryCombinedSeries.MarkerType = MarkerType.Circle; realCombinedSeries.MarkerFill = OxyColors.Purple; imaginaryCombinedSeries.MarkerFill = OxyColors.Purple; realCombinedSeries.MarkerSize = 1; imaginaryCombinedSeries.MarkerSize = 1; foreach (Tuple <double, Complex> tuple in outputSignal.Points) { realCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Real)); imaginaryCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Imaginary)); } ClearPlot(); outputSignal.StartingMoment = outputSignal.Points[0].Item1; outputSignal.EndingMoment = outputSignal.Points[outputSignal.Points.Count - 1].Item1; outputSignal.CalculateTraits(); combinedSignal.Signal = outputSignal; textTraits.AverageValueText = combinedSignal.Signal.AverageValue.ToString("N3"); textTraits.AbsouluteAverageValueText = combinedSignal.Signal.AbsouluteAverageValue.ToString("N3"); textTraits.AveragePowerText = combinedSignal.Signal.AveragePower.ToString("N3"); textTraits.VarianceText = combinedSignal.Signal.Variance.ToString("N3"); textTraits.EffectiveValueText = combinedSignal.Signal.EffectiveValue.ToString("N3"); OnPropertyChanged("TextProperties3"); realPlotModel.Series.Add(realCombinedSeries); imaginaryPlotModel.Series.Add(imaginaryCombinedSeries); realPlotModel.InvalidatePlot(true); imaginaryPlotModel.InvalidatePlot(true); double min = outputSignal.Points.Min(d => d.Item2.Real); double max = outputSignal.Points.Max(d => d.Item2.Real); double universumWidth = max - min; double intervalWidth = universumWidth / NumberOfIntervals; int[] histogramUniversum = new int[NumberOfIntervals]; for (int k = 0; k < outputSignal.Points.Count; k++) { int interval = (int)Math.Floor((outputSignal.Points[k].Item2.Real - min) / (intervalWidth + 0.0001)); histogramUniversum[interval]++; } List <int> realHisogramUniversum = histogramUniversum.ToList(); realCombinedHistogramSeries = new ColumnSeries(); foreach (int elem in realHisogramUniversum) { realCombinedHistogramSeries.Items.Add(new ColumnItem(elem)); } realHistogramPlotModel.Axes.Clear(); realHistogramPlotModel.Series.Clear(); realCombinedHistogramSeries.FillColor = OxyColors.Purple; realHistogramPlotModel.Series.Add(realCombinedHistogramSeries); realHistogramPlotModel.InvalidatePlot(true); firstChart.SignalRepresentation.Signal = null; secondChart.SignalRepresentation.Signal = null; }
private void Reconstruct(object param) { string frequencyToReconstructText = ""; ReconstructWindow dialog = new ReconstructWindow(); if (dialog.ShowDialog() == true) { frequencyToReconstructText = dialog.FrequencyToReconstruct; } if (!double.TryParse(frequencyToReconstructText, out double frequencyToReconstruct)) { return; } ISignal signal; switch (param.ToString()) { case "1": if (combinedSignal.Signal.Points.Count != 0) { signal = combinedSignal.Signal; } else { signal = FirstChart.SignalRepresentation.Signal; } break; default: throw new ArgumentException(); } SignalImplementation reconstructedSignal = Quantizator.ExtrapolationZeroOrderHold(signal, frequencyToReconstruct); reconstructedSignal.StartingMoment = reconstructedSignal.Points[0].Item1; reconstructedSignal.EndingMoment = reconstructedSignal.Points[reconstructedSignal.Points.Count - 1].Item1; reconstructedSignal.CalculateTraits(); combinedSignal.Signal = reconstructedSignal; combinedTextProperties.AverageValueText = combinedSignal.Signal.AverageValue.ToString("N3"); combinedTextProperties.AbsouluteAverageValueText = combinedSignal.Signal.AbsouluteAverageValue.ToString("N3"); combinedTextProperties.AveragePowerText = combinedSignal.Signal.AveragePower.ToString("N3"); combinedTextProperties.VarianceText = combinedSignal.Signal.Variance.ToString("N3"); combinedTextProperties.EffectiveValueText = combinedSignal.Signal.EffectiveValue.ToString("N3"); OnPropertyChanged("CombinedTextProperties"); realCombinedSeries = new ScatterSeries(); imaginaryCombinedSeries = new ScatterSeries(); foreach (Tuple <double, Complex> tuple in reconstructedSignal.Points) { realCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Real)); imaginaryCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Imaginary)); } realCombinedSeries.MarkerType = MarkerType.Circle; imaginaryCombinedSeries.MarkerType = MarkerType.Circle; realCombinedSeries.MarkerSize = 1; imaginaryCombinedSeries.MarkerSize = 1; realCombinedSeries.MarkerFill = OxyColors.Black; imaginaryCombinedSeries.MarkerFill = OxyColors.Black; realPlotModel.Series.Add(realCombinedSeries); imaginaryPlotModel.Series.Add(imaginaryCombinedSeries); realPlotModel.InvalidatePlot(true); imaginaryPlotModel.InvalidatePlot(true); }
private void Transform(object param) { SignalTransform transform = null; bool absoluteValue = false; TransformWindow dialog = new TransformWindow(); if (dialog.ShowDialog() == true) { transform = dialog.SelectedTransform; absoluteValue = dialog.AbsoluteValue; } if (transform == null) { return; } ISignal signal; switch (param.ToString()) { case "1": signal = FirstChart.SignalRepresentation.Signal; break; case "2": signal = SecondChart.SignalRepresentation.Signal; break; case "3": signal = combinedSignal.Signal; break; default: throw new ArgumentException(); } DateTime start = DateTime.Now; SignalImplementation transformedSignal = transform.TransformSignal(signal); if (absoluteValue) { transformedSignal = SignalOperations.GetAbsoluteSignal(transformedSignal); } TimeSpan elapsedTime = DateTime.Now - start; MessageBox.Show("Czas wykonania algorytmu: " + elapsedTime.Minutes + "m " + elapsedTime.Seconds + "s " + elapsedTime.Milliseconds + "ms"); transformedSignal.StartingMoment = transformedSignal.Points[0].Item1; transformedSignal.EndingMoment = transformedSignal.Points[transformedSignal.Points.Count - 1].Item1; transformedSignal.CalculateTraits(); combinedSignal.Signal = transformedSignal; combinedTextProperties.AverageValueText = combinedSignal.Signal.AverageValue.ToString("N3"); combinedTextProperties.AbsouluteAverageValueText = combinedSignal.Signal.AbsouluteAverageValue.ToString("N3"); combinedTextProperties.AveragePowerText = combinedSignal.Signal.AveragePower.ToString("N3"); combinedTextProperties.VarianceText = combinedSignal.Signal.Variance.ToString("N3"); combinedTextProperties.EffectiveValueText = combinedSignal.Signal.EffectiveValue.ToString("N3"); OnPropertyChanged("CombinedTextProperties"); realCombinedSeries = new ScatterSeries(); imaginaryCombinedSeries = new ScatterSeries(); foreach (Tuple <double, Complex> tuple in transformedSignal.Points) { realCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Real)); imaginaryCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Imaginary)); } ClearPlot(); realCombinedSeries.MarkerType = MarkerType.Circle; imaginaryCombinedSeries.MarkerType = MarkerType.Circle; realCombinedSeries.MarkerSize = 2; imaginaryCombinedSeries.MarkerSize = 2; realCombinedSeries.MarkerFill = OxyColors.Green; imaginaryCombinedSeries.MarkerFill = OxyColors.Green; realPlotModel.Series.Add(realCombinedSeries); imaginaryPlotModel.Series.Add(imaginaryCombinedSeries); realPlotModel.InvalidatePlot(true); imaginaryPlotModel.InvalidatePlot(true); }
private void Filter(object param) { string filterDegreeText = ""; string cutoffFrequencyText = ""; IWindow windowFunction = null; Filter filter = null; FilterWindow dialog = new FilterWindow(); if (dialog.ShowDialog() == true) { filterDegreeText = dialog.FilterDegree; cutoffFrequencyText = dialog.CutoffFrequency; windowFunction = dialog.SelectedWindowFunction; filter = dialog.SelectedFilter; } if (!int.TryParse(filterDegreeText, out int filterDegree)) { return; } if (!double.TryParse(cutoffFrequencyText, out double cutoffFrequency)) { return; } if (windowFunction == null) { return; } if (filter == null) { return; } ISignal signal; switch (param.ToString()) { case "1": signal = FirstChart.SignalRepresentation.Signal; break; case "2": signal = SecondChart.SignalRepresentation.Signal; break; case "3": signal = combinedSignal.Signal; break; default: throw new ArgumentException(); } filter.InitFilter(cutoffFrequency, filterDegree, windowFunction); SignalImplementation filteredSignal = filter.FilterSignal(signal); filteredSignal.StartingMoment = filteredSignal.Points[0].Item1; filteredSignal.EndingMoment = filteredSignal.Points[filteredSignal.Points.Count - 1].Item1; filteredSignal.CalculateTraits(); combinedSignal.Signal = filteredSignal; combinedTextProperties.AverageValueText = combinedSignal.Signal.AverageValue.ToString("N3"); combinedTextProperties.AbsouluteAverageValueText = combinedSignal.Signal.AbsouluteAverageValue.ToString("N3"); combinedTextProperties.AveragePowerText = combinedSignal.Signal.AveragePower.ToString("N3"); combinedTextProperties.VarianceText = combinedSignal.Signal.Variance.ToString("N3"); combinedTextProperties.EffectiveValueText = combinedSignal.Signal.EffectiveValue.ToString("N3"); OnPropertyChanged("CombinedTextProperties"); realCombinedSeries = new ScatterSeries(); imaginaryCombinedSeries = new ScatterSeries(); foreach (Tuple <double, Complex> tuple in filteredSignal.Points) { realCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Real)); imaginaryCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Imaginary)); } ClearPlot(); realCombinedSeries.MarkerType = MarkerType.Circle; imaginaryCombinedSeries.MarkerType = MarkerType.Circle; realCombinedSeries.MarkerSize = 1; imaginaryCombinedSeries.MarkerSize = 1; realCombinedSeries.MarkerFill = OxyColors.Green; imaginaryCombinedSeries.MarkerFill = OxyColors.Green; realPlotModel.Series.Add(realCombinedSeries); imaginaryPlotModel.Series.Add(imaginaryCombinedSeries); realPlotModel.InvalidatePlot(true); imaginaryPlotModel.InvalidatePlot(true); }
private void Quantize(object param) { string samplingText = ""; string levelsText = ""; QuantizeWindow dialog = new QuantizeWindow(); if (dialog.ShowDialog() == true) { samplingText = dialog.SamplingFrequency; levelsText = dialog.LevelsOfQuantization; } if (!double.TryParse(samplingText, out double samplingFrequency)) { return; } if (!int.TryParse(levelsText, out int levelsOfQuantization)) { return; } ISignal signal; switch (param.ToString()) { case "1": signal = FirstChart.SignalRepresentation.Signal; break; default: throw new ArgumentException(); } SignalImplementation quantizedSignal = Quantizator.Quantize(Quantizator.SampleSignal(signal, samplingFrequency), levelsOfQuantization); quantizedSignal.StartingMoment = quantizedSignal.Points[0].Item1; quantizedSignal.EndingMoment = quantizedSignal.Points[quantizedSignal.Points.Count - 1].Item1; quantizedSignal.CalculateTraits(); combinedSignal.Signal = quantizedSignal; combinedTextProperties.AverageValueText = combinedSignal.Signal.AverageValue.ToString("N3"); combinedTextProperties.AbsouluteAverageValueText = combinedSignal.Signal.AbsouluteAverageValue.ToString("N3"); combinedTextProperties.AveragePowerText = combinedSignal.Signal.AveragePower.ToString("N3"); combinedTextProperties.VarianceText = combinedSignal.Signal.Variance.ToString("N3"); combinedTextProperties.EffectiveValueText = combinedSignal.Signal.EffectiveValue.ToString("N3"); OnPropertyChanged("CombinedTextProperties"); realCombinedSeries = new ScatterSeries(); imaginaryCombinedSeries = new ScatterSeries(); foreach (Tuple <double, Complex> tuple in quantizedSignal.Points) { realCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Real)); imaginaryCombinedSeries.Points.Add(new ScatterPoint(tuple.Item1, tuple.Item2.Imaginary)); } realCombinedSeries.MarkerType = MarkerType.Circle; imaginaryCombinedSeries.MarkerType = MarkerType.Circle; realCombinedSeries.MarkerSize = 2; imaginaryCombinedSeries.MarkerSize = 2; realCombinedSeries.MarkerFill = OxyColors.Green; imaginaryCombinedSeries.MarkerFill = OxyColors.Green; realPlotModel.Series.Add(realCombinedSeries); imaginaryPlotModel.Series.Add(imaginaryCombinedSeries); realPlotModel.InvalidatePlot(true); imaginaryPlotModel.InvalidatePlot(true); }