Пример #1
0
        public static float[] MakeLowPassKernel(double sampleRate, double passband, double stopband, double ripple, double attenuation)
        {
            double num  = 2.0 * passband / sampleRate;
            double num2 = 2.0 * stopband / sampleRate;
            int    num3 = (int)((double)FilterBuilder.EstimateOrder(num, num2, ripple, attenuation) * 1.4) | 1;
            int    num4 = Math.Max(1, num3 - 20);
            int    num5 = num4 + 40;

            for (int i = num4; i < num5; i += 2)
            {
                int    num6 = 50;
                double num7 = 0.0;
                for (int j = 0; j < 100; j++)
                {
                    double  normalizedCutoff = (num * (double)num6 + num2 * (double)(100 - num6)) / 100.0;
                    float[] array            = FilterBuilder.MakeChebychevLowPass(i, normalizedCutoff, attenuation + num7);
                    double  num8;
                    double  num9;
                    FilterBuilder.GetFilterSpecs(array, num, num2, out num8, out num9);
                    if (num8 <= ripple && num9 >= attenuation)
                    {
                        return(array);
                    }
                    num6 += Math.Sign(ripple - num8);
                    num7 += (double)Math.Sign(attenuation - num9) * 0.15 - (double)Math.Sign(ripple - num8) * 2.5;
                    if (num7 < -20.0)
                    {
                        num7 = -20.0;
                    }
                    if (num7 > 20.0)
                    {
                        num7 = 20.0;
                    }
                    if (num6 < 0)
                    {
                        num6 = 0;
                    }
                    if (num6 > 100)
                    {
                        num6 = 100;
                    }
                }
            }
            return(null);
        }