public void run() { float[] tempIn = new float[depth * 2]; float[] tempOut; FftComplex fftc = new FftComplex(depth); int myNumber = ai.getAndIncrement(); for (int y = 0; y < height; y++) if (y % numThreads == myNumber) for (int x = 0; x < complexWidth / 2; x++) { tempOut = new float[depth * 2]; for (int z = 0; z < depth; z++) { tempIn[z * 2] = result.get(x * 2, y, z); tempIn[z * 2 + 1] = result.get(x * 2 + 1, y, z); } fftc.complexToComplex( -1, tempIn, tempOut); for (int z = 0; z < depth; z++) { result.set(tempOut[z * 2], x * 2, y, z); result.set(tempOut[z * 2 + 1], x * 2 + 1, y, z); } } } });
public void run() { float[] tempIn = new float[height * 2]; float[] tempOut; FftComplex fftc = new FftComplex(height); int myNumber = ai.getAndIncrement(); for (int z = 0; z < depth; z++) if (z % numThreads == myNumber) for (int x = 0; x < complexWidth / 2; x++) { tempOut = new float[height * 2]; for (int y = 0; y < height; y++) { tempIn[y * 2] = result.get(x * 2, y, z); tempIn[y * 2 + 1] = result.get(x * 2 + 1, y, z); } fftc.complexToComplex( -1, tempIn, tempOut); for (int y = 0; y < height; y++) { result.set(tempOut[y * 2], x * 2, y, z); result.set(tempOut[y * 2 + 1], x * 2 + 1, y, z); } } } });
public void run() { float[] tempIn = new float[height * 2]; float[] tempOut; FftComplex fftc = new FftComplex(height); int myNumber = ai.getAndIncrement(); for (int z = 0; z < depth; z++) if (z % numThreads == myNumber) for (int x = 0; x < complexWidth / 2; x++) { tempOut = new float[height * 2]; for (int y = 0; y < height; y++) { tempIn[y * 2] = values.get(x * 2, y, z); tempIn[y * 2 + 1] = values.get(x * 2 + 1, y, z); } fftc.complexToComplex(1, tempIn, tempOut); for (int y = 0; y < height; y++) { values.set(tempOut[y * 2], x * 2, y, z); values.set(tempOut[y * 2 + 1], x * 2 + 1, y, z); } } } });
@Override public void run() { int myNumber = ai.getAndIncrement(); float[] tempIn = new float[depth * 2]; float[] tempOut; FftComplex fftc = new FftComplex(depth); for (int y = 0; y < height; y++) if (y % numThreads == myNumber) for (int x = 0; x < complexWidth / 2; x++) { tempOut = new float[complexWidth]; tempOut = new float[depth * 2]; for (int z = 0; z < depth; z++) { tempIn[z * 2] = values.get(x * 2, y, z); tempIn[z * 2 + 1] = values.get(x * 2 + 1, y, z); } fftc.complexToComplex(1, tempIn, tempOut); for (int z = 0; z < depth; z++) { values.set(tempOut[z * 2], x * 2, y, z); values.set(tempOut[z * 2 + 1], x * 2 + 1, y, z); } } } });
public void run() { int myNumber = ai.getAndIncrement(); float[] tempIn = new float[depth * 2]; float[] tempOut; FftComplex fftc = new FftComplex(depth); for (int y = 0; y < height; y++) if (y % numThreads == myNumber) for (int x = 0; x < complexWidth / 2; x++) { tempOut = new float[complexWidth]; tempOut = new float[depth * 2]; for (int z = 0; z < depth; z++) { tempIn[z * 2] = values.get(x * 2, y, z); tempIn[z * 2 + 1] = values.get(x * 2 + 1, y, z); } fftc.complexToComplex(1, tempIn, tempOut); for (int z = 0; z < depth; z++) { values.set(tempOut[z * 2], x * 2, y, z); values.set(tempOut[z * 2 + 1], x * 2 + 1, y, z); } } } });
@Override public void run() { float[] tempIn = new float[height * 2]; float[] tempOut; FftComplex fftc = new FftComplex(height); int myNumber = ai.getAndIncrement(); for (int z = 0; z < depth; z++) if (z % numThreads == myNumber) for (int x = 0; x < complexWidth / 2; x++) { tempOut = new float[height * 2]; for (int y = 0; y < height; y++) { tempIn[y * 2] = result.get(x * 2, y, z); tempIn[y * 2 + 1] = result.get(x * 2 + 1, y, z); } fftc.complexToComplex(-1, tempIn, tempOut); for (int y = 0; y < height; y++) { result.set(tempOut[y * 2], x * 2, y, z); result.set(tempOut[y * 2 + 1], x * 2 + 1, y, z); } } } });
@Override public void run() { float[] tempIn = new float[depth * 2]; float[] tempOut; FftComplex fftc = new FftComplex(depth); int myNumber = ai.getAndIncrement(); for (int y = 0; y < height; y++) if (y % numThreads == myNumber) for (int x = 0; x < complexWidth / 2; x++) { tempOut = new float[depth * 2]; for (int z = 0; z < depth; z++) { tempIn[z * 2] = result.get(x * 2, y, z); tempIn[z * 2 + 1] = result.get(x * 2 + 1, y, z); } fftc.complexToComplex(-1, tempIn, tempOut); for (int z = 0; z < depth; z++) { result.set(tempOut[z * 2], x * 2, y, z); result.set(tempOut[z * 2 + 1], x * 2 + 1, y, z); } } } });
@Override public void run() { float[] tempIn = new float[height * 2]; float[] tempOut; FftComplex fftc = new FftComplex(height); int myNumber = ai.getAndIncrement(); for (int z = 0; z < depth; z++) if (z % numThreads == myNumber) for (int x = 0; x < complexWidth / 2; x++) { tempOut = new float[height * 2]; for (int y = 0; y < height; y++) { tempIn[y * 2] = values.get(x * 2, y, z); tempIn[y * 2 + 1] = values.get(x * 2 + 1, y, z); } fftc.complexToComplex(1, tempIn, tempOut); for (int y = 0; y < height; y++) { values.set(tempOut[y * 2], x * 2, y, z); values.set(tempOut[y * 2 + 1], x * 2 + 1, y, z); } } } });
private void updateSampling3() { if (_sx3==null) return; int nx = _sx3.getCount(); double dx = _sx3.getDelta(); int npad = nx+_padding3; int nfft = FftComplex.nfftSmall(npad); double dk = 1.0/(nfft*dx); double fk; int nk; if (_center3) { boolean even = nfft%2==0; nk = even?nfft+1:nfft; fk = even?-0.5/dx:-0.5/dx+0.5*dk; } else { nk = nfft; fk = 0.0; } if (_fft3==null || _nfft3!=nfft) { _fft3 = new FftComplex(nfft); _nfft3 = nfft; } _sk3 = new Sampling(nk,dk,fk); //trace("sk3: nfft="+nfft+" nk="+nk+" dk="+dk+" fk="+fk); }
private void updateSampling2() { if (_sx2==null) return; int nx = _sx2.getCount(); double dx = _sx2.getDelta(); int npad = nx+_padding2; int nfft = FftComplex.nfftSmall(npad); double dk = 1.0/(nfft*dx); double fk; int nk; if (_center2) { boolean even = nfft%2==0; nk = even?nfft+1:nfft; fk = even?-0.5/dx:-0.5/dx+0.5*dk; } else { nk = nfft; fk = 0.0; } if (_fft2==null || _nfft2!=nfft) { _fft2 = new FftComplex(nfft); _nfft2 = nfft; } _sk2 = new Sampling(nk,dk,fk); //trace("sk2: nfft="+nfft+" nk="+nk+" dk="+dk+" fk="+fk); } private void updateSampling3() {
private void updateFfts(int nx1, int nx2) { if (_fft2==null || _h2fft==null || _nx1!=nx1 || _nx2!=nx2) { _nx1 = nx1; _nx2 = nx2; _nx3 = 0; _nfft1 = FftReal.nfftFast(_nx1+_nh1); _nfft2 = FftComplex.nfftFast(_nx2+_nh2); _fft1 = new FftReal(_nfft1); _fft2 = new FftComplex(_nfft2); _fft3 = null; _h1fft = null; _h2fft = new float[_nfft2][_nfft1+2]; _h3fft = null; float scale = 1.0f/(float)_nfft1/(float)_nfft2; for (int ih2=0; ih2<_nh2; ++ih2) { int jh2 = ih2-_kh2; if (jh2<0) jh2 += _nfft2; for (int ih1=0; ih1<_nh1; ++ih1) { int jh1 = ih1-_kh1; if (jh1<0) jh1 += _nfft1; _h2fft[jh2][jh1] = scale*_h2[ih2][ih1]; } } _fft1.realToComplex1(-1,_nfft2,_h2fft,_h2fft); _fft2.complexToComplex2(-1,_nfft1/2+1,_h2fft,_h2fft); } }
private static double time(int nfft) { double maxtime = 2.0; FftComplex fft = new FftComplex(nfft); float[] cx = crandfloat(nfft); int count; Stopwatch sw = new Stopwatch(); sw.start(); for (count=0; sw.time()<maxtime; ++count) { fft.complexToComplex(-1,cx,cx); fft.complexToComplex( 1,cx,cx); fft.scale(nfft,cx); } sw.stop(); double time = sw.time()/(float)count; return time; } }
public void test3Random() { int n1 = 11; int n2 = 12; int n3 = 13; int n1fft = FftComplex.nfftSmall(n1); int n2fft = FftComplex.nfftSmall(n2); int n3fft = FftComplex.nfftSmall(n3); FftComplex fft1 = new FftComplex(n1fft); FftComplex fft2 = new FftComplex(n2fft); FftComplex fft3 = new FftComplex(n3fft); float[][][] cr = crandfloat(n1fft,n2fft,n3fft); float[][][] cx = ccopy(cr); fft1.complexToComplex1( 1,n2fft,n3fft,cx,cx); fft2.complexToComplex2( 1,n1fft,n3fft,cx,cx); fft3.complexToComplex3( 1,n1fft,n2fft,cx,cx); fft1.complexToComplex1(-1,n2fft,n3fft,cx,cx); fft2.complexToComplex2(-1,n1fft,n3fft,cx,cx); fft3.complexToComplex3(-1,n1fft,n2fft,cx,cx); fft1.scale(n1fft,n2fft,n3fft,cx); fft2.scale(n1fft,n2fft,n3fft,cx); fft3.scale(n1fft,n2fft,n3fft,cx); assertEqual(cr,cx); }
/** * Applies forward 2D Fourier transform. * @param level level number. * @param x input 2D image. * @return a 2D complex array, which is the forward 2D Fourier transform of * the input image. */ private float[][] ftForward(int level, float[][] x) { FftReal fft1; FftComplex fft2; int ny2 = x.length; int ny1 = x[0].length; int mpad = round(20.0f/(1.0f+(float)level)); int lfactor = (int)pow(2.0,(double)level); int nl2 = (n2-1)/lfactor+1; int nl1 = (n1-1)/lfactor+1; int nf1 = FftReal.nfftSmall(nl1+mpad*2); int nf1c = nf1/2+1; int nf2 = FftComplex.nfftSmall(nl2+mpad*2); float[][] xr = zerofloat(nf1,nf2); copy(ny1,ny2,0,0,x,mpad,mpad,xr); float[][] cx = czerofloat(nf1c,nf2); fft1 = new FftReal(nf1); fft2 = new FftComplex(nf2); fft1.realToComplex1(1,nf2,xr,cx); flipSign(2,cx); fft2.complexToComplex2(1,nf1c,cx,cx); return cx; }
public void test2Random() { int n1max = 26; int n2max = 26; for (int n2=2; n2<n2max; ++n2) { int n2fft = FftComplex.nfftSmall(n2); FftComplex fft2 = new FftComplex(n2fft); for (int n1=2; n1<n1max; ++n1) { int n1fft = FftComplex.nfftSmall(n1); FftComplex fft1 = new FftComplex(n1fft); float[][] cr = crandfloat(n1fft,n2fft); float[][] cx = ccopy(cr); float[][] cy = czerofloat(n1fft,n2fft); fft1.complexToComplex1( 1,n2fft,cx,cy); fft2.complexToComplex2( 1,n1fft,cy,cy); fft1.complexToComplex1(-1,n2fft,cy,cx); fft2.complexToComplex2(-1,n1fft,cx,cx); fft1.scale(n1fft,n2fft,cx); fft2.scale(n1fft,n2fft,cx); assertEqual(cr,cx); } } }
public void test1Random() { int nmax = 1000; for (int n=2; n<nmax; ++n) { int nfft = FftComplex.nfftSmall(n); FftComplex fft = new FftComplex(nfft); float[] cr = crandfloat(nfft); float[] cx = ccopy(cr); float[] cy = czerofloat(nfft); fft.complexToComplex( 1,cx,cy); fft.complexToComplex(-1,cy,cx); fft.scale(nfft,cx); assertEqual(cr,cx); } }
public void test2() { int n1max = 26; int n2max = 26; for (int n2=2; n2<n2max; ++n2) { int n2fft = FftComplex.nfftSmall(n2); FftComplex fft2 = new FftComplex(n2fft); for (int n1=2; n1<n1max; ++n1) { int n1fft = FftComplex.nfftSmall(n1); FftComplex fft1 = new FftComplex(n1fft); float[][] c1 = czerofloat(n1fft,n2fft); c1[1][2] = 1.0f; float[][] cx = ccopy(c1); fft1.complexToComplex1(1,n2fft,cx,cx); fft2.complexToComplex2(1,n1fft,cx,cx); float ra = 0.0f; float rb1 = 2.0f*FLT_PI/(float)n1fft; float rb2 = 2.0f*FLT_PI/(float)n2fft; float[][] amp = fillfloat(1.0f,n1fft,n2fft); float[][] phs = rampfloat(ra,rb1,rb2,n1fft,n2fft); float[][] cc = polar(amp,phs); assertEqual(cc,cx); fft1.complexToComplex1(-1,n2fft,cx,cx); fft2.complexToComplex2(-1,n1fft,cx,cx); fft1.scale(n1fft,n2fft,cx); fft2.scale(n1fft,n2fft,cx); assertEqual(c1,cx); } } }
public void test1() { int nmax = 1000; for (int n=2; n<nmax; ++n) { int nfft = FftComplex.nfftSmall(n); FftComplex fft = new FftComplex(nfft); float[] c1 = czerofloat(nfft); c1[2] = 1.0f; float[] cx = ccopy(c1); fft.complexToComplex(1,cx,cx); float ra = 0.0f; float rb = 2.0f*FLT_PI/(float)nfft; float[] amp = fillfloat(1.0f,nfft); float[] phs = rampfloat(ra,rb,nfft); float[] cc = polar(amp,phs); assertEqual(cc,cx); fft.complexToComplex(-1,cx,cx); fft.scale(nfft,cx); assertEqual(c1,cx); } }
public void test21Random() { int n1max = 26; int n2max = 26; for (int n2=2; n2<n2max; ++n2) { int n2fft = FftReal.nfftSmall(n2); FftReal fft2 = new FftReal(n2fft); int nw = n2fft/2+1; for (int n1=2; n1<n1max; ++n1) { int n1fft = FftComplex.nfftSmall(n1); FftComplex fft1 = new FftComplex(n1fft); float[][] rr = randfloat(n1,n2fft); float[][] rx = copy(rr); float[][] cy = czerofloat(n1fft,nw); fft2.realToComplex2( 1,n1,rx,cy); fft1.complexToComplex1( 1,nw,cy,cy); fft1.complexToComplex1(-1,nw,cy,cy); fft1.scale(n1,nw,cy); fft2.complexToReal2(-1,n1,cy,rx); fft2.scale(n1,n2,rx); assertRealEqual(n1,n2,rr,rx); } } }
public void test12Random() { int n1max = 26; int n2max = 26; for (int n2=2; n2<n2max; ++n2) { int n2fft = FftComplex.nfftSmall(n2); FftComplex fft2 = new FftComplex(n2fft); for (int n1=2; n1<n1max; ++n1) { int n1fft = FftReal.nfftSmall(n1); FftReal fft1 = new FftReal(n1fft); int nw = n1fft/2+1; float[][] rr = randfloat(n1fft,n2); float[][] rx = copy(rr); float[][] cy = czerofloat(nw,n2fft); fft1.realToComplex1( 1,n2,rx,cy); fft2.complexToComplex2( 1,nw,cy,cy); fft2.complexToComplex2(-1,nw,cy,cy); fft2.scale(nw,n2,cy); fft1.complexToReal1(-1,n2,cy,rx); fft1.scale(n1,n2,rx); assertRealEqual(n1,n2,rr,rx); } } }