示例#1
0
        public void HighPass()
        {
            const double passbandFreq        = 2500 / _SamplingFrequency;
            const double stopbandFreq        = 2000 / _SamplingFrequency;
            const double passbandRipple      = 5;
            const double stopbandAttenuation = 6;

            var(eb, ea) = IirCoefficients.HighPass(stopbandFreq, passbandFreq, passbandRipple, stopbandAttenuation);

            var b = eb.ToArray();
            var a = ea.ToArray();

            var desiredB = new double[] { 0.7736977585189119, -0.7736977585189119 };
            var desiredA = new double[] { 1, -0.5473955170378236 };

            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);
            }
        }
示例#2
0
        /// <summary>
        /// Create a filter to remove low frequencies in online processing scenarios.
        /// </summary>
        public static OnlineFilter CreateHighpass(ImpulseResponse mode, double sampleRate, double cutoffRate, int order)
        {
            if (mode == ImpulseResponse.Finite)
            {
                double[] c = FirCoefficients.HighPass(sampleRate, cutoffRate, order >> 1);
                return(new OnlineFirFilter(c));
            }

            if (mode == ImpulseResponse.Infinite)
            {
                // TODO: investigate (bandwidth)
                double[] c = IirCoefficients.HighPass(sampleRate, cutoffRate, cutoffRate);
                return(new OnlineIirFilter(c));
            }

            throw new ArgumentException("mode");
        }