Skip to content

Commit

Permalink
add samples from NWaves repo; add DemoStereo
Browse files Browse the repository at this point in the history
  • Loading branch information
ar1st0crat committed Aug 21, 2021
1 parent d2f9bea commit 6a12713
Show file tree
Hide file tree
Showing 148 changed files with 23,808 additions and 1 deletion.
247 changes: 247 additions & 0 deletions NWaves.DemoForms/AdaptiveFiltersForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions NWaves.DemoForms/AdaptiveFiltersForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using NWaves.Filters.Adaptive;
using NWaves.Filters.Base;
using NWaves.Signals;
using NWaves.Signals.Builders;
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;

namespace NWaves.DemoForms
{
public partial class AdaptiveFiltersForm : Form
{
DiscreteSignal _s;
DiscreteSignal _noise;

public AdaptiveFiltersForm()
{
InitializeComponent();
}

private void adaptButton_Click(object sender, EventArgs e)
{
var mu = float.Parse(muTextBox.Text);

AdaptiveFilter filter;

if (nlmsRadioButton.Checked)
filter = new NlmsFilter(5, mu);
else if (lmfRadioButton.Checked)
filter = new LmfFilter(5, mu);
else if (rlsRadioButton.Checked)
filter = new RlsFilter(5, mu);
else
filter = new LmsFilter(5, mu);

var a = Enumerable.Range(0, _noise.Length)
.Select(i => filter.Process(_noise[i], _s[i]))
.ToArray();

linePlot1.Markline = a;

weightsListBox.DataSource = new BindingList<float>(filter.Kernel);
}

private void generateButton_Click(object sender, EventArgs e)
{
_noise = sinRadioButton.Checked ?
new SineBuilder()
.SetParameter("freq", 1000)
.OfLength(1000)
.SampledAt(16000)
.Build()
:
new WhiteNoiseBuilder()
.SetParameter("min", -0.5)
.SetParameter("max", 0.5)
.OfLength(1000)
.SampledAt(16000)
.Build();

var fir = new FirFilter(new[] { 0.2, 1, -0.5, 0.5, 0.9 });

_s = fir.ApplyTo(_noise);

linePlot1.Stride = 5;
linePlot1.Line = _s.Samples;
}
}
}
Loading

0 comments on commit 6a12713

Please sign in to comment.