/* * Copyright 2006-2007 Columbia University. * * This file is part of MEAPsoft. * * MEAPsoft is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * MEAPsoft 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 for more details. * * You should have received a copy of the GNU General Public License * along with MEAPsoft; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * See the file "COPYING" for the text of the license. */ package com.mantz_it.rfanalyzer; public class FFT { int n, m; // Lookup tables. Only need to recompute when size of FFT changes. float[] cos; float[] sin; float[] window; public FFT(int n) { this.n = n; this.m = (int)(Math.log(n) / Math.log(2)); // Make sure n is a power of 2 if(n != (1<= n1 ) { j = j - n1; n1 = n1/2; } j = j + n1; if (i < j) { t1 = x[i]; x[i] = x[j]; x[j] = t1; t1 = y[i]; y[i] = y[j]; y[j] = t1; } } // FFT n1 = 0; n2 = 1; for (i=0; i < m; i++) { n1 = n2; n2 = n2 + n2; a = 0; for (j=0; j < n1; j++) { c = cos[a]; s = sin[a]; a += 1 << (m-i-1); for (k=j; k < n; k=k+n2) { t1 = c*x[k+n1] - s*y[k+n1]; t2 = s*x[k+n1] + c*y[k+n1]; x[k+n1] = x[k] - t1; y[k+n1] = y[k] - t2; x[k] = x[k] + t1; y[k] = y[k] + t2; } } } } }