/** * Computes a complex-to-complex dimension-1 fast Fourier transform. * Transforms a 2-D input array cx[n2][2*nfft] of n2*nfft complex numbers * to a 2-D output array cy[n2][2*nfft] of n2*nfft complex numbers. * @param sign the sign (1 or -1) of the exponent used in the FFT. * @param n2 the 2nd dimension of arrays. * @param cx the input array. * @param cy the output array. */ public void complexToComplex1(int sign, int n2, float[][] cx, float[][] cy) { checkSign(sign); checkArray(2*_nfft,n2,cx,"cx"); checkArray(2*_nfft,n2,cy,"cy"); for (int i2=0; i2<n2; ++i2) complexToComplex(sign,cx[i2],cy[i2]); }
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 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() { 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() { 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); } } } });
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); } } } });
/** * Applies a forward space-to-frequency transform of a 1D array. * @param f the array to be transformed, a sampled function of space. * @return the transformed array, a sampled function of frequency. */ public float[] applyForward(float[] f) { ensureSamplingX1(f); float[] fpad = pad(f); if (_complex) { _fft1c.complexToComplex(_sign1,fpad,fpad); } else { _fft1r.realToComplex(_sign1,fpad,fpad); } phase(fpad); center(fpad); return fpad; }
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); } }
/** * Applies an inverse frequency-to-space transform of a 1D array. * @param g the array to be transformed, a sampled function of frequency. * @return the transformed array, a sampled function of space. */ public float[] applyInverse(float[] g) { ensureSamplingK1(g); int nx1 = _sx1.getCount(); float[] gpad = (_overwrite)?g:copy(g); uncenter(gpad); unphase(gpad); if (_complex) { _fft1c.complexToComplex(-_sign1,gpad,gpad); _fft1c.scale(nx1,gpad); return ccopy(nx1,gpad); } else { _fft1r.complexToReal(-_sign1,gpad,gpad); _fft1r.scale(nx1,gpad); return copy(nx1,gpad); } }
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); } }
fft.complexToComplex( -1, tempIn, tempOut); else fft.complexToComplex( 1, tempIn, tempOut);
fftc.complexToComplex(1, tempIn, tempOut);
if (forward) fft.complexToComplex(-1, tempIn, tempOut); else fft.complexToComplex(1, tempIn, tempOut);
fftc.complexToComplex(1, tempIn, tempOut);
fftc.complexToComplex( -1, tempIn, tempOut);
fftc.complexToComplex( -1, tempIn, tempOut);