public override IEnumerable <double> ProcessOverride(IEnumerable <double> signal) { return(Dsp.IirFilter(signal, this.A, this.B)); }
public void TestIirFilter() { var a = new[] { 1.005324035839730, -1.979734945559880, 0.994675964160273 }; var b = new[] { 1.009467623312100, -1.979734945559880, 0.990532376687905 }; var input = new[] { 0.011902069501241, 0.337122644398882, 0.162182308193243, 0.794284540683907, 0.311215042044805, 0.528533135506213, 0.165648729499781, 0.601981941401637, 0.262971284540144, 0.654079098476782 }; var target = new[] { 0.011951125590942, 0.338608747553482, 0.165679682794458, 0.801585643285872, 0.322746670917094, 0.542922698153360, 0.181975922148892, 0.620199851895649, 0.283093784100937, 0.675895116230680, 0.021967963324124, 0.018979594184005, 0.015640291287202, 0.012021084391531, 0.008197893160596, 0.004249945003087, 0.000258142993172, -0.003696582700258, -0.007534906469386, -0.011180689296962 }; var result = Dsp.IirFilter(input, a, b).Take(20).ToReadOnlyList(); FilterAssert.ListsAreReasonablyClose(target, result); FilterAssert.ListContainsPlausibleValues(Dsp.IirFilter(input, new[] { 1.0 }, b).Take(20).ToReadOnlyList()); FilterAssert.ListContainsOnlyZeroes(Dsp.IirFilter(Enumerable.Empty <double>(), a, b).Take(10).ToReadOnlyList()); FilterAssert.ListContainsOnlyZeroes(Dsp.IirFilter(input, a, Enumerable.Empty <double>().ToReadOnlyList()).Take(10).ToReadOnlyList()); Assert.Throws <ArgumentNullException>(() => Dsp.IirFilter(null, a, b).Take(20).ToReadOnlyList()); Assert.Throws <ArgumentNullException>(() => Dsp.IirFilter(input, null, b).Take(20).ToReadOnlyList()); Assert.Throws <ArgumentNullException>(() => Dsp.IirFilter(input, a, null).Take(20).ToReadOnlyList()); Assert.Throws <Exception>(() => Dsp.IirFilter(input, Enumerable.Empty <double>().ToReadOnlyList(), b).Take(20).ToReadOnlyList()); Assert.Throws <Exception>(() => Dsp.IirFilter(input, new[] { 0.0 }, b).Take(20).ToReadOnlyList()); }