/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Fast Fourier Transformer.
*
* @author Karl Helgason
*/
public final class FFT {
private final double[] w;
private final int fftFrameSize;
private final int sign;
private final int[] bitm_array;
private final int fftFrameSize2;
// Sign = -1 is FFT, 1 is IFFT (inverse FFT)
// Data = Interlaced double array to be transformed.
// The order is: real (sin), complex (cos)
// Framesize must be power of 2
this.fftFrameSize = fftFrameSize;
// Pre-process Bit-Reversal
bitm_array = new int[fftFrameSize2];
int j;
int bitm;
if ((i & bitm) != 0)
j++;
j <<= 1;
}
bitm_array[i] = j;
}
}
}
int sign) {
int w_index = 0;
nstep <<= 1;
double wr = 1.0;
double wi = 0.0;
}
}
// PRECOMPUTATION of wwr1, wwi1 for factor 4 Decomposition (3 * complex
// operators and 8 +/- complex operators)
{
w_index = 0;
nstep *= 2;
}
}
}
return warray;
}
double[] w) {
int nstep = 2;
if (nstep >= fftFrameSize2)
return;
int i = nstep - 2;
if (sign == -1)
else
}
int nstep, double[] w) {
double wr = w[i++];
double wi = w[i++];
int m = n + jmax;
}
return;
}
// Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
// complex operators
int nstep, double[] w) {
// Factor-4 Decomposition
while (nstep < fftFrameSize2) {
// Goto Factor-4 Final Decomposition
// calcF4E(data, i, nstep, -1, w);
return;
}
if (nnstep == fftFrameSize2) {
// Factor-4 Decomposition not possible
return;
}
nstep <<= 2;
{
i += 2;
ii += 2;
iii += 2;
int m = n + jmax;
n += nnstep;
m += nnstep;
n -= nnstep;
m -= nnstep;
}
}
double wr = w[i++];
double wi = w[i++];
// double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
// precomputed!!!
// double wwi1 = wr * wi1 + wi * wr1;
for (int n = j; n < fftFrameSize2; n += nstep) {
int m = n + jmax;
n += nnstep;
m += nnstep;
n -= nnstep;
m -= nnstep;
}
}
i += jmax << 1;
}
}
// Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
// complex operators
int nstep, double[] w) {
// Factor-4 Decomposition
while (nstep < fftFrameSize2) {
// Goto Factor-4 Final Decomposition
// calcF4E(data, i, nstep, 1, w);
return;
}
if (nnstep == fftFrameSize2) {
// Factor-4 Decomposition not possible
return;
}
nstep <<= 2;
{
i += 2;
ii += 2;
iii += 2;
int m = n + jmax;
n += nnstep;
m += nnstep;
n -= nnstep;
m -= nnstep;
}
}
double wr = w[i++];
double wi = w[i++];
// double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
// precomputed!!!
// double wwi1 = wr * wi1 + wi * wr1;
for (int n = j; n < fftFrameSize2; n += nstep) {
int m = n + jmax;
n += nnstep;
m += nnstep;
n -= nnstep;
m -= nnstep;
}
}
i += jmax << 1;
}
}
// Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
// complex operators
int nstep, double[] w) {
// Factor-4 Decomposition
while (nstep < fftFrameSize2) {
if (nnstep == fftFrameSize2) {
// Factor-4 Decomposition not possible
return;
}
nstep <<= 2;
double wr = w[i++];
double wi = w[i++];
// double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
// precomputed!!!
// double wwi1 = wr * wi1 + wi * wr1;
int m = n + jmax;
n += nnstep;
m += nnstep;
n -= nnstep;
m -= nnstep;
}
i += jmax << 1;
}
}
// Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
// complex operators
int nstep, double[] w) {
// Factor-4 Decomposition
while (nstep < fftFrameSize2) {
if (nnstep == fftFrameSize2) {
// Factor-4 Decomposition not possible
return;
}
nstep <<= 2;
double wr = w[i++];
double wi = w[i++];
// double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
// precomputed!!!
// double wwi1 = wr * wi1 + wi * wr1;
int m = n + jmax;
n += nnstep;
m += nnstep;
n -= nnstep;
m -= nnstep;
}
i += jmax << 1;
}
}
if (fftFrameSize < 4)
return;
int j = bitm_array[i];
// Performing Bit-Reversal, even v.s. even, O(2N)
if (i < j) {
int n = i;
int m = j;
// COMPLEX: SWAP(data[n], data[m])
// Real Part
// Imagery Part
n++;
m++;
n = inverse - i;
m = inverse - j;
// COMPLEX: SWAP(data[n], data[m])
// Real Part
// Imagery Part
n++;
m++;
}
// Performing Bit-Reversal, odd v.s. even, O(N)
int m = j + fftFrameSize; // bitm_array[i+2];
// COMPLEX: SWAP(data[n], data[m])
// Real Part
int n = i + 2;
// Imagery Part
n++;
m++;
}
}
}