private void test1( boolean complex, boolean overwrite, boolean center, int padding, int n1, double d1, double f1) { if (n1<=0) return; Sampling s1 = new Sampling(n1,d1,f1); Fft fft = new Fft(s1); fft.setComplex(complex); fft.setOverwrite(overwrite); fft.setCenter(center); fft.setPadding(padding); float[] f = (complex)?crandfloat(n1):randfloat(n1); float[] g = fft.applyForward(f); float[] h = fft.applyInverse(g); if (complex) assertComplexEqual(n1,f,h); else assertRealEqual(n1,f,h); } private void test2(
public void testFrequencyResponse() { int n = 501; double sigma = 4.0; float[] x = new float[n]; x[n/2] = 1.0f; float[] ye = new float[n]; float[] yg = new float[n]; RecursiveExponentialFilter ref = new RecursiveExponentialFilter(sigma); RecursiveGaussianFilter rgf = new RecursiveGaussianFilter(sigma); ref.apply(x,ye); rgf.apply0(x,yg); Fft fft = new Fft(n); fft.setCenter(true); Sampling sf = fft.getFrequencySampling1(); int i0 = sf.indexOfNearest(0.0); float[] ae = cabs(fft.applyForward(ye)); float[] ag = cabs(fft.applyForward(yg)); float e0 = ae[i0]; float e1 = (ae[i0+1]-ae[i0-1])/2.0f; float e2 = ae[i0+1]-2.0f*ae[i0]+ae[i0-1]; float g0 = ag[i0]; float g1 = (ag[i0+1]-ag[i0-1])/2.0f; float g2 = ag[i0+1]-2.0f*ag[i0]+ag[i0-1]; assertEquals(e0,g0,0.0001); assertEquals(e1,g1,0.0001); assertEquals(e2,g2,0.01*abs(g2)); }