diff --git a/OxyPlotExample/GettingStarted/Filter/HighPassFilter.cs b/OxyPlotExample/GettingStarted/Filter/HighPassFilter.cs index 6d43bed..3c79dfd 100644 --- a/OxyPlotExample/GettingStarted/Filter/HighPassFilter.cs +++ b/OxyPlotExample/GettingStarted/Filter/HighPassFilter.cs @@ -12,12 +12,14 @@ namespace GettingStarted.Filter private double _previousOutput; private double _previouseInput; - public HighPassFilter(double alpha) + public HighPassFilter(double cutoffFreq, double dt) { - if (alpha < 0.0 || alpha > 1.0) - throw new ArgumentException(nameof(alpha), "Alpha must be between 0 and 1."); + if (cutoffFreq <= 0.0 || dt <= 0.0) + throw new ArgumentException("Cutoff frequency and dt must be greater than 0."); + + double rc = 1.0 / (2 * Math.PI * cutoffFreq); + _alpha = rc / (rc + dt); - _alpha = alpha; _previousOutput = 0.0; _previouseInput = 0.0; } diff --git a/OxyPlotExample/GettingStarted/Filter/LowPassFilter.cs b/OxyPlotExample/GettingStarted/Filter/LowPassFilter.cs index 40c0fd5..06eb62d 100644 --- a/OxyPlotExample/GettingStarted/Filter/LowPassFilter.cs +++ b/OxyPlotExample/GettingStarted/Filter/LowPassFilter.cs @@ -11,12 +11,14 @@ namespace GettingStarted.Filter private double _alpha; private double _previousOutput; - public LowPassFilter(double alpha) + public LowPassFilter(double cutoffFreq, double dt) { - if (alpha < 0.0 || alpha > 1.0) - throw new ArgumentException(nameof(alpha), "Alpha must be between 0 and 1."); + if (cutoffFreq <= 0.0 || dt <= 0.0) + throw new ArgumentException("Cutoff frequency and dt must be greater than 0."); + + double rc = 1.0 / (2 * Math.PI * cutoffFreq); + _alpha = dt / (rc + dt); - _alpha = alpha; _previousOutput = 0.0; } diff --git a/OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.cs b/OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.cs index d590c20..96131e5 100644 --- a/OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.cs +++ b/OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.cs @@ -16,6 +16,8 @@ namespace GettingStarted.ViewModels { internal partial class MainViewModel3 : ObservableObject { + private readonly double DT = 0.01; + [ObservableProperty] private PlotModel _myModel; @@ -40,7 +42,7 @@ namespace GettingStarted.ViewModels LineSeries = new LineSeries() { Title = "Dynamic Data" }; LpfSeries = new LineSeries() { Title = "Filtered" }; - _filter = new HighPassFilter(0.5); + _filter = new LowPassFilter(5d, DT); DateTimeAxis timeAxis = new DateTimeAxis() { @@ -67,7 +69,7 @@ namespace GettingStarted.ViewModels CutOffSecond = 10d; _timer = new System.Timers.Timer(); - _timer.Interval = 10; + _timer.Interval = DT * 1000; _timer.Elapsed -= _timer_Elapsed; _timer.Elapsed += _timer_Elapsed; }