using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; /* @author Geir K. Nilsen (geir.kjetil.nilsen@gmail.com) 2017 */ namespace ParametricEqualizer { public class Filter { private List a; private List b; private List x_past; private List y_past; public Filter(List a, List b) { this.a = a; this.b = b; } public void apply(List x, out List y) { int ord = a.Count - 1; int np = x.Count - 1; if (np < ord) { for (int k = 0; k < ord - np; k++) x.Add(0.0); np = ord; } y = new List(); for (int k = 0; k < np + 1; k++) { y.Add(0.0); } if (x_past == null) { x_past = new List(); for (int s = 0; s < x.Count; s++) x_past.Add(0); } if (y_past == null) { y_past = new List(); for (int s = 0; s < y.Count; s++) y_past.Add(0); } for (int i = 0; i < np + 1; i++) { y[i] = 0.0; for (int j = 0; j < ord + 1; j++) { if (i - j < 0) y[i] = y[i] + b[j] * x_past[x_past.Count - j]; else y[i] = y[i] + b[j] * x[i - j]; } for (int j = 0; j < ord; j++) { if (i - j - 1 < 0) y[i] = y[i] - a[j + 1] * y_past[y_past.Count - j - 1]; else y[i] = y[i] - a[j + 1] * y[i - j - 1]; } y[i] = y[i] / a[0]; } x_past = x; y_past = y; } } }