/* Fast Fourier transform methods for 1-d and 2-d data, using Rocca's column FT routine for more efficiency. Adapted from Jon Claerbout's Imaging the Earth's Interior (1985) by John N. Louie, 24 November 1998. */ /* Include the usual classes */ import java.util.*; import java.io.*; import java.lang.Math; /* Declare a class to contain all the 2-d fft methods we will use. */ /* When you change the code in this file, make a copy to a new file with a new name like "ex6fttestc.java", and be sure to make the same change to the class name below - e.g. "class ex6fttestc" */ class fttestc { /* The main() method compiles into a file named "fttestc.class" that you run in the Java virtual machine as a stand-alone application with a command such as "java fttestc"; or whatever you have renamed the class and file. */ public static void main(String args[]) /* No runtime arguments needed */ { System.out.println("Starting fttestc..."); /* Declare variables */ int it, nt, ix, nx; /* Assign sizes: 64x64 is always quick; 1024x1024 takes several minutes and more than 40 Mb memory */ nx = 64; nt = 64; /* Declare and initialize planes to zero values */ FltPlane p = new FltPlane(nx, nt); ComplexPlane cp = new ComplexPlane(nx, nt); /* Insert a spike into the real part of the complex array. The class ComplexPlane has the method setElemReal(ix,it,val) as a shortcut for the statement: cp.vec[ix*cp.ne + it].re = val; */ cp.setElemReal(3,16,1F); cp.setElemReal(4,16,4F); cp.setElemReal(5,16,6F); cp.setElemReal(6,16,4F); cp.setElemReal(7,16,1F); cp.setElemReal(3,17,1F); cp.setElemReal(4,17,4F); cp.setElemReal(5,17,6F); cp.setElemReal(6,17,4F); cp.setElemReal(7,17,1F); /* Transform plane into the 2-d Fourier domain */ ft2dc(cp, 1F, 1F); /* Copy the real part of the transformed complex plane to a real plane to allow plotting */ cp.realtoFltPlane(p); /* Plot the real plane in a new window titled "fttestc", with the fastest-varying direction pointing down, no vertical exaggeration, using white color for negative amplitudes and black color for positive amplitudes with near-zero amplitudes gray (like looking at a WTVA wiggle-trace-variable-area plot from a distance), scaling from the maximum down to minus the maximum. */ p.viewinFrame("fttestc", true, 1F, RgCtab.vagray, false, -1F); /* All Done with fttestc's main() application method */ } /* 2-d FFT in-place method for class ComplexPlane data structures, using Rocca's columnwise FFT scheme */ static void ft2dc(ComplexPlane cp, float sign1, float sign2) { /* Declare local variables */ int n1, n2; int i1, i2; /* Obtain n1=nx and n2=nt from the input ComplexPlane class data structure, using RGData interface methods */ n1 = cp.getNMembofDim(1); /* Dim=1 is vectors, or rows */ n2 = cp.getNMembofDim(0); /* Dim=0 is fastest-varying, the elements */ /* Adding String objects concatenates them */ System.out.print("ft2dc: starting " + n2 + "x" + n1 + " 2-d FFT... "); /* Transform over the fast dimension, the rows */ /* Loop over n1, number of rows */ for (i1=0; i1 m-1) { j = j - m; m = m/2; if (m < 1) break; } j = j + m; } lstep = 1; do { istep = 2*lstep; cw.re = 1F; cw.im = 0F; arg = (float)(sign2*Math.PI/lstep); cdel.re = (float)(Math.cos((double)(arg))); cdel.im = (float)(Math.sin((double)(arg))); for (m=0; m m-1) { j = j - m; m = m/2; if (m < 1) break; } j = j + m; } do { istep = 2*k; for (m=0; m