protected internal override IOnlineFilter CreateBandStop(FilterDesignSettings settings, double lowFrequency, double highFrequency)
 {
     return Create(Design(FilterKind.BandStop, settings.Order,
         CalculateRipple(settings),
         settings.NormalizeFrequency(lowFrequency),
         settings.NormalizeFrequency(highFrequency)));
 }
        protected internal override IOnlineFilter CreateNotch(FilterDesignSettings settings, double frequency)
        {
            const double notchHalfWidth = 0.5; // Hz

            return Create(Design(FilterKind.BandStop, settings.Order,
                CalculateRipple(settings),
                settings.NormalizeFrequency(frequency - notchHalfWidth),
                settings.NormalizeFrequency(frequency + notchHalfWidth)));
        }
        protected internal override IOnlineFilter CreateOther(FilterDesignSettings settings)
        {
            int windowSize = settings.Order > 0 ? settings.Order : MedianFilterDesignSettings.DefaultWindowSize;

            var medianSettings = settings as MedianFilterDesignSettings;

            if (medianSettings != null)
            {
                windowSize = medianSettings.WindowSize;
            }

            return(new Filter(windowSize));
        }
Exemple #4
0
        private static T Resolve <T>(FilterDesignSettings settings, Func <RbjFilterDesignSettings, T> selector, T defaultValue)
        {
            Debug.Assert(selector != null);

            var rbjSettings = settings as RbjFilterDesignSettings;

            if (rbjSettings != null)
            {
                return(selector(rbjSettings));
            }

            return(defaultValue);
        }
Exemple #5
0
        protected internal override IOnlineFilter CreateNotch(FilterDesignSettings settings, double frequency)
        {
            Debug.Assert(settings != null);
            Debug.Assert(settings.SamplingRate > 0);

            double omega = (2 * Math.PI) * (frequency / settings.SamplingRate);
            double tsin  = Math.Sin(omega);
            double tcos  = Math.Cos(omega);
            double alpha = tsin / (2 * Resolve(settings, x => x.Quality, RbjFilterDesignSettings.DefaultQuality));

            double b0 = 1;
            double b1 = -2 * tcos;
            double b2 = 1;
            double a0 = 1 + alpha;
            double a1 = -2 * tcos;
            double a2 = 1 - alpha;

            return(CreateCascade(settings.Order, new IirFilterCoefficients {
                B = new double[] { b0, b1, b2 }, A = new double[] { a0, a1, a2 }
            }));
        }
Exemple #6
0
        protected internal override IOnlineFilter CreateHighShelf(FilterDesignSettings settings, double frequency)
        {
            Debug.Assert(settings != null);
            Debug.Assert(settings.SamplingRate > 0);

            double omega = (2 * Math.PI) * (frequency / settings.SamplingRate);
            double tsin  = Math.Sin(omega);
            double tcos  = Math.Cos(omega);
            double alpha = tsin / (2 * Resolve(settings, x => x.Quality, RbjFilterDesignSettings.DefaultQuality));
            double a     = Math.Pow(10, Resolve(settings, x => x.Gain, RbjFilterDesignSettings.DefaultGain) / 40);
            double w0    = Math.PI * 2 * frequency / settings.SamplingRate;

            double b0 = a * ((a + 1) + (a - 1) * Math.Cos(w0) + 2 * Math.Sqrt(a) * alpha);
            double b1 = -2 * a * ((a - 1) + (a + 1) * Math.Cos(w0));
            double b2 = a * ((a + 1) + (a - 1) * Math.Cos(w0) - 2 * Math.Sqrt(a) * alpha);
            double a0 = (a + 1) - (a - 1) * Math.Cos(w0) + 2 * Math.Sqrt(a) * alpha;
            double a1 = 2 * ((a - 1) - (a + 1) * Math.Cos(w0));
            double a2 = (a + 1) - (a - 1) * Math.Cos(w0) - 2 * Math.Sqrt(a) * alpha;

            return(CreateCascade(settings.Order, new IirFilterCoefficients {
                B = new double[] { b0, b1, b2 }, A = new double[] { a0, a1, a2 }
            }));
        }
Exemple #7
0
        protected internal override IOnlineFilter CreateBandStop(FilterDesignSettings settings, double lowFrequency, double highFrequency)
        {
            Debug.Assert(settings != null);
            Debug.Assert(settings.SamplingRate > 0);

            double frequency = CalculateCenterFrequency(lowFrequency, highFrequency);
            double q         = CalculateQ(lowFrequency, highFrequency);
            double omega     = (2 * Math.PI) * (frequency / settings.SamplingRate);
            double tsin      = Math.Sin(omega);
            double tcos      = Math.Cos(omega);
            double alpha     = tsin / (2 * q);

            double b0 = 1;
            double b1 = -2 * tcos;
            double b2 = 1;
            double a0 = 1 + alpha;
            double a1 = -2 * tcos;
            double a2 = 1 - alpha;

            return(CreateCascade(settings.Order, new IirFilterCoefficients {
                B = new double[] { b0, b1, b2 }, A = new double[] { a0, a1, a2 }
            }));
        }
 protected virtual double CalculateRipple(FilterDesignSettings settings)
 {
     // Default to 0 because most filters don't use Ripple
     return 0;
 }
 protected internal override IOnlineFilter CreateHighPass(FilterDesignSettings settings, double frequency)
 {
     return Create(Design(FilterKind.HighPass, settings.Order,
         CalculateRipple(settings),
         settings.NormalizeFrequency(frequency)));
 }
Exemple #10
0
 protected internal override IOnlineFilter CreateOther(FilterDesignSettings settings)
 {
     throw new NotImplementedException();
 }
 protected override double CalculateRipple(FilterDesignSettings settings)
 {
     return(settings.GetOrDefault <ChebyshevFilterDesignSettings, double>(x => x.MaximumRipple ?? -10, -10));
 }