private static int estimateFilterOrder(int sampleRate,int frequency1,int frequency2,double passBandRipple,double stopBandRipple){
  double df=Math.abs(frequency2 - frequency1) / (double)sampleRate;
  double ddp=Math.log10(stopBandRipple <= passBandRipple ? passBandRipple : stopBandRipple);
  double dds=Math.log10(stopBandRipple <= passBandRipple ? stopBandRipple : passBandRipple);
  double a1=5.309e-3;
  double a2=7.114e-2;
  double a3=-4.761e-1;
  double a4=-2.66e-3;
  double a5=-5.941e-1;
  double a6=-4.278e-1;
  double b1=11.01217;
  double b2=0.5124401;
  double t1=a1 * ddp * ddp;
  double t2=a2 * ddp;
  double t3=a4 * ddp * ddp;
  double t4=a5 * ddp;
  double dinf=((t1 + t2 + a3) * dds) + (t3 + t4 + a6);
  double ff=b1 + b2 * (ddp - dds);
  double n=dinf / df - ff * df + 1.0;
  return (int)Math.ceil(n);
}

private static int estimateFilterOrder ( int sampleRate , int frequency1 , int frequency2 , double passBandRipple , double stopBandRipple ) { double df = Math . abs ( frequency2 - frequency1 ) / ( double ) sampleRate ; double ddp = Math . log10 ( stopBandRipple <= passBandRipple ? passBandRipple : stopBandRipple ) ; double dds = Math . log10 ( stopBandRipple <= passBandRipple ? stopBandRipple : passBandRipple ) ; double a1 = 5.309e-3 ; double a2 = 7.114e-2 ; double a3 = - 4.761e-1 ; double a4 = - 2.66e-3 ; double a5 = - 5.941e-1 ; double a6 = - 4.278e-1 ; double b1 = 11.01217 ; double b2 = 0.5124401 ; double t1 = a1 * ddp * ddp ; double t2 = a2 * ddp ; double t3 = a4 * ddp * ddp ; double t4 = a5 * ddp ; double dinf = ( ( t1 + t2 + a3 ) * dds ) + ( t3 + t4 + a6 ) ; double ff = b1 + b2 * ( ddp - dds ) ; double n = dinf / df - ff * df + 1.0 ; return ( int ) Math . ceil ( n ) ; }
estimates filter length for a two - band ( high or low pass ) fir filter . note : this estimator doesn ' t work well if the transition frequency is near 0 or samplerate / 2 from herrmann et al ( 1973 ) , practical design rules for optimum finite impulse response filters . bell system technical j . , 52 , 769 - 99
