private void ensureLowpassFilter(double kmax) { if (_lpf==null || _kmax!=kmax) { _kmax = kmax; double kdelta = 0.5-kmax; double kupper = kmax+0.5*kdelta; _lpf = new BandPassFilter(0.0,kupper,kdelta,0.01); _lpf.setExtrapolation(BandPassFilter.Extrapolation.ZERO_SLOPE); _lpf.setFilterCaching(false); } }
private static double h2(double r) { return (r==0.0)?PIO4:besselJ1(PI*r)/(2.0*r); } private static double besselJ1(double x) {
private void updateFilter1() { if (_ff1==null) { KaiserWindow kw = KaiserWindow.fromErrorAndWidth(_aerror,_kwidth); int nh = ((int)kw.getLength()+1)/2*2+1; int nh1 = nh; int kh1 = (nh1-1)/2; _h1 = new float[nh1]; double kus = 2.0*_kupper; double kls = 2.0*_klower; for (int i1=0; i1<nh1; ++i1) { double x1 = i1-kh1; double w1 = kw.evaluate(x1); double r = x1; double kur = 2.0*_kupper*r; double klr = 2.0*_klower*r; _h1[i1] = (float)(w1*(kus*h1(kur)-kls*h1(klr))); } _ff1 = new FftFilter(_h1); _ff1.setExtrapolation(ffExtrap(_extrapolation)); _ff1.setFilterCaching(_filterCaching); } }
private void updateFilter2() { if (_ff2==null) { KaiserWindow kw = KaiserWindow.fromErrorAndWidth(_aerror,_kwidth); int nh = ((int)kw.getLength()+1)/2*2+1; int nh1 = nh; int nh2 = nh; int kh1 = (nh1-1)/2; int kh2 = (nh2-1)/2; _h2 = new float[nh2][nh1]; double kus = 4.0*_kupper*_kupper; double kls = 4.0*_klower*_klower; for (int i2=0; i2<nh2; ++i2) { double x2 = i2-kh2; double w2 = kw.evaluate(x2); for (int i1=0; i1<nh1; ++i1) { double x1 = i1-kh1; double w1 = kw.evaluate(x1); double r = sqrt(x1*x1+x2*x2); double kur = 2.0*_kupper*r; double klr = 2.0*_klower*r; _h2[i2][i1] = (float)(w1*w2*(kus*h2(kur)-kls*h2(klr))); } } _ff2 = new FftFilter(_h2); _ff2.setExtrapolation(ffExtrap(_extrapolation)); _ff2.setFilterCaching(_filterCaching); } }
private void smoothL(double kmax, float[][] x, float[][] y) { ensureLowpassFilter(kmax); _lpf.apply(x,y); } private void smoothL(double kmax, float[][][] x, float[][][] y) {
/** * Applies this filter. * Input and output arrays may be the same array. * @param x input array. * @param y output filtered array. */ public void apply(float[] x, float[] y) { updateFilter1(); _ff1.apply(x,y); }
private void smoothL(double kmax, float[][][] x, float[][][] y) { ensureLowpassFilter(kmax); _lpf.apply(x,y); } private void ensureLowpassFilter(double kmax) {
/** * Gets the 1D array of coefficients for this filter. * The origin of the filter is at the center of the array. * @return the array of filter coefficients. */ public float[] getCoefficients1() { updateFilter1(); return copy(_h1); }