public void BandStop() { const double lowPassbandFreq = 2000 / _SamplingFrequency; const double lowStopbandFreq = 2500 / _SamplingFrequency; const double highPassbandFreq = 3500 / _SamplingFrequency; const double highStopbandFreq = 3000 / _SamplingFrequency; const double passbandRipple = 5; const double stopbandAttenuation = 6; var(eb, ea) = IirCoefficients.BandStop(lowPassbandFreq, lowStopbandFreq, highStopbandFreq, highPassbandFreq, passbandRipple, stopbandAttenuation); var b = eb.ToArray(); var a = ea.ToArray(); var desiredB = new double[] { 0.8634280116150362, -1.569442492959457, 0.8634280116150361 }; var desiredA = new double[] { 1, -1.569442492959457, 0.7268560232300724 }; Assert.AreEqual(desiredB.Length, b.Length); Assert.AreEqual(desiredA.Length, a.Length); for (int i = 0; i < b.Length; i++) { Assert.AreEqual(desiredB[i], b[i], _Tolerance); } for (int i = 0; i < a.Length; i++) { Assert.AreEqual(desiredA[i], a[i], _Tolerance); } }
/// <summary> /// Create a filter to remove middle (all but low and high) frequencies in online processing scenarios. /// </summary> public static OnlineFilter CreateBandstop(ImpulseResponse mode, double sampleRate, double cutoffLowRate, double cutoffHighRate, int order) { if (mode == ImpulseResponse.Finite) { double[] c = FirCoefficients.BandStop(sampleRate, cutoffLowRate, cutoffHighRate, order >> 1); return(new OnlineFirFilter(c)); } if (mode == ImpulseResponse.Infinite) { double[] c = IirCoefficients.BandStop(sampleRate, cutoffLowRate, cutoffHighRate); return(new OnlineIirFilter(c)); } throw new ArgumentException("mode"); }