fix alpha formula

main
syneffort 11 months ago
parent a56e1eb1b4
commit 493a1a61d8
  1. 10
      OxyPlotExample/GettingStarted/Filter/HighPassFilter.cs
  2. 10
      OxyPlotExample/GettingStarted/Filter/LowPassFilter.cs
  3. 6
      OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.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;
}

@ -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;
}

@ -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;
}

Loading…
Cancel
Save