public void BandPass() { const double lowPassbandFreq = 2500 / _SamplingFrequency; const double lowStopbandFreq = 2000 / _SamplingFrequency; const double highPassbandFreq = 3000 / _SamplingFrequency; const double highStopbandFreq = 3500 / _SamplingFrequency; const double passbandRipple = 5; const double stopbandAttenuation = 6; var(eb, ea) = IirCoefficients.BandPass(lowStopbandFreq, lowPassbandFreq, highPassbandFreq, highStopbandFreq, passbandRipple, stopbandAttenuation); var b = eb.ToArray(); var a = ea.ToArray(); var desiredB = new double[] { 0.02602409840677345, 0, -0.02602409840677345 }; var desiredA = new double[] { 1, -1.770384034934973, 0.9479518031864529 }; 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 low and high frequencies in online processing scenarios. /// </summary> public static OnlineFilter CreateBandpass(ImpulseResponse mode, double sampleRate, double cutoffLowRate, double cutoffHighRate, int order) { if (mode == ImpulseResponse.Finite) { double[] c = FirCoefficients.BandPass(sampleRate, cutoffLowRate, cutoffHighRate, order >> 1); return(new OnlineFirFilter(c)); } if (mode == ImpulseResponse.Infinite) { double[] c = IirCoefficients.BandPass(sampleRate, cutoffLowRate, cutoffHighRate); return(new OnlineIirFilter(c)); } throw new ArgumentException("mode"); }