root/graph/JavaPopWeb/src/jp/ac/nime/computer/grpsimulator/ImgPr/FFT.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. FFT
  2. fft

package jp.ac.nime.computer.grpsimulator.ImgPr;

import java.util.*;
import java.lang.*;

/** FFTを計算するクラス
 * @author kikuchi
 * @version 1.0.0
 */
public class FFT {
        /** 一次元FFTの計算
         * @param flag 1:FFT変換 -1:逆変換
         * @param cf    変換データ
         * @param nMax  変換データの個数
         */
        public static void fft(int flag, ComplexF cf[], int nMax) {
                // 並べ替え
                int i = 0;
                int j = 0;
                int n2;
                for (i = 0; i < (nMax - 1); i ++) {
                        if (i < j) {
                                ComplexF.swap(cf[i], cf[j]);
                        }
                        n2 = nMax / 2;
                        while (j >= n2) {
                                j -= n2;
                                n2 /= 2;
                        }
                        j = j + n2;
                }
                // FFT
                int nJisu = 0;
                n2 = nMax;
                while (n2 != 1) {
                        nJisu ++;
                        n2 /= 2;
                }
                int np = 1;
                int np2;
                double rag, drag;
                double co, si;
                for (int k = 1; k <= nJisu; k ++) {
                        np *= 2;
                        np2 = np / 2;
                        drag = ((double)(-flag) * Math.PI) / np2;
                        rag = 0.0;
                        for (j = 0; j < np2; j ++) {
                                co = Math.cos(rag);
                                si = Math.sin(rag);
                                rag += drag;
                                for (i = j; i < nMax; i += np) {
                                        int ii = i + np2;
                                        ComplexF tcf = cf[ii].fftfunc(co, si);
                                        cf[ii] = ComplexF.sub(cf[i], tcf);
                                        cf[i].plus(tcf);
                                }
                        }
                }
                
                // FFTのときには、 nで割る
                if (flag == 1) {
                        for (i = 0; i < nMax; i ++) {
                                cf[i].scaleDown((double)nMax);
                        }
                }
        }
}

/* [<][>][^][v][top][bottom][index][help] */