public void SmartAlphaBetaFilter_FilterFewSamples() { Sample sample = new Sample(0, 1); Sample filteredSample = new Sample(0, 0); SmartAlphaBetaFilter abf = new SmartAlphaBetaFilter(0.0033, 10); for (int i = 0; i < 50; i++) { filteredSample = abf.AddSample(new Sample(i * 0.5, -0.5 + (new Random()).NextDouble())); sample.Time++; } Assert.AreEqual(1, Math.Round(sample.Value)); }
private void GenerateChart() { if (csv == null) { return; } WaitingScreen.Visible = true; this.Refresh(); list1.Clear(); list2.Clear(); IFilter Filter; string FilterType = FilterSelector.Text; switch (FilterType) { case "FIR Filter": Filter = new FIRFilter(new List <double>() { 0.25, 0.25, 0.25, 0.25 }); break; case "Alpha Beta Filter": Filter = new AlphaBetaFilter(0.2, 0.3); break; case "Smart Alpha Beta Filter": Filter = new SmartAlphaBetaFilter(0.003307643036326, 200); break; default: Filter = null; break; } int PreviousProgress = 0; int Progress = 0; int i = 0; Integrator integrator = new Integrator(); foreach (KeyValuePair <double, List <double> > entry in csv.Data) { InertialNavigationSystem.Sample sample = new InertialNavigationSystem.Sample(entry.Key, entry.Value[ColumnSelector.SelectedIndex]); if (Filter != null) { sample = Filter.AddSample(sample); } list1.Add(sample.Time, sample.Value); integrator.AddSample(sample); if (DrawIntegral.Checked) { list2.Add(sample.Time, integrator.Value); } i++; Progress = i * 100 / csv.Data.Count; if (PreviousProgress != Progress) { ProgressIndicator.Value = Progress; Application.DoEvents(); } PreviousProgress = Progress; } Chart1.AxisChange(); Chart1.Refresh(); WaitingScreen.Visible = false; }