All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.mines.jtk.dsp.FftComplex Maven / Gradle / Ivy

/****************************************************************************
Copyright 2005, Colorado School of Mines and others.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
****************************************************************************/
package edu.mines.jtk.dsp;

import static edu.mines.jtk.util.ArrayMath.*;
import edu.mines.jtk.util.Check;

/**
 * Fast Fourier transform of complex-valued arrays. The FFT length 
 * nfft equals the number of complex numbers transformed. 
 * The transform of nfft complex numbers yields nfft complex numbers. 
 * Those complex numbers are packed into arrays of floats as [real_0, 
 * imag_0, real_1, imag_1, ...]. Here, real_k and imag_k correspond to 
 * the real and imaginary parts, respectively, of the complex number 
 * with array index k.
 * 

* When input and output arrays are the same array, transforms are * performed in-place. For example, an input array cx[2*nfft] of nfft * complex numbers may be the same as an output array cy[2*nfft] of * nfft complex numbers. By "the same array", we mean that cx==cy. *

* Transforms may be performed for any dimension of a multi-dimensional * array. For example, we may transform the 1st dimension of an input * array cx[n2][2*nfft] of n2*nfft complex numbers to an output array * cy[n2][2*nfft] of n2*nfft complex numbers. Or, we may transform the * 2nd dimension of an input array cx[nfft][2*n1] of nfft*n1 complex * numbers to an output array cy[nfft][2*n1] of nfft*n1 complex numbers. * In either case, the input array cx and the output array cy may be the * same array, such that the transform may be performed in-place. * @author Dave Hale, Colorado School of Mines * @version 2005.03.21 */ public class FftComplex { /** * Constructs a new FFT, with specified length. Valid FFT lengths * can be obtained by calling the methods {@link #nfftSmall(int)} * and {@link #nfftFast(int)}. * @param nfft the FFT length, which must be valid. */ public FftComplex(int nfft) { Check.argument(Pfacc.nfftValid(nfft),"nfft="+nfft+" is valid FFT length"); _nfft = nfft; } /** * Returns an FFT length optimized for memory. The FFT length will be the * smallest valid length that is not less than the specified length n. * @param n the lower bound on FFT length. * @return the FFT length. * @exception IllegalArgumentException if the specified length n exceeds * the maximum length supported by this implementation. Currently, the * maximum length is 720,720. */ public static int nfftSmall(int n) { Check.argument(n<=720720,"n does not exceed 720720"); return Pfacc.nfftSmall(n); } /** * Returns an FFT length optimized for speed. The FFT length will be the * fastest valid length that is not less than the specified length n. * @param n the lower bound on FFT length. * @return the FFT length. * @exception IllegalArgumentException if the specified length n exceeds * the maximum length supported by this implementation. Currently, the * maximum length is 720,720. */ public static int nfftFast(int n) { Check.argument(n<=720720,"n does not exceed 720720"); return Pfacc.nfftFast(n); } /** * Gets the FFT length for this FFT. * @return the FFT length. */ public int getNfft() { return _nfft; } /** * Computes a complex-to-complex fast Fourier transform. * Transforms a 1-D input array cx[2*nfft] of nfft complex numbers * to a 1-D output array cy[2*nfft] of nfft complex numbers. * @param sign the sign (1 or -1) of the exponent used in the FFT. * @param cx the input array. * @param cy the output array. */ public void complexToComplex(int sign, float[] cx, float[] cy) { checkSign(sign); checkArray(2*_nfft,cx,"cx"); checkArray(2*_nfft,cy,"cy"); if (cx!=cy) ccopy(_nfft,cx,cy); Pfacc.transform(sign,_nfft,cy); } /** * 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=0) cx[n] *= s; } /** * Scales n1*n2 complex numbers in the specified array by 1/nfft. * The inverse of a complex-to-complex FFT is a complex-to-complex * FFT (with opposite sign) followed by this scaling. * @param n1 the 1st dimension of the array cx. * @param n2 the 2nd dimension of the array cx. * @param cx the input/output array[n2][2*n1]. */ public void scale(int n1, int n2, float[][] cx) { for (int i2=0; i2=n,"dimensions of "+name+" are valid"); } private static void checkArray(int n1, int n2, float[][] a, String name) { boolean ok = a.length>=n2; for (int i2=0; i2=n1; Check.argument(ok,"dimensions of "+name+" are valid"); } private static void checkArray( int n1, int n2, int n3, float[][][] a, String name) { boolean ok = a.length>=n3; for (int i3=0; i3=n2; for (int i2=0; i2=n1; } } Check.argument(ok,"dimensions of "+name+" are valid"); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy