ts-scikit
Version:
A scientific toolkit written in Typescript
188 lines (187 loc) • 8.56 kB
TypeScript
/**
* A fast Fourier transform of real-valued arrays.
* <p>
* The FFT length nfft equals the number of <em>real</em> numbers
* transformed. The transform of nfft real numbers yields nfft/2+1 complex
* numbers. (The imaginary parts of the first and last complex numbers
* are always zero.) For real-to-complex and complex-to-real transforms, nfft
* is always an even number.
* <p>
* Complex numbers are packed into arrays of numbers as [real_0, imag_0,
* real_1, imag_1, ... ]. Here, real_k and imag_k correspond to the real and
* imaginary parts of the complex number with index k, respectively.
* <p>
* When input and output arrays are the same array, transforms are performed
* in-place. For example, an input array rx[nfft] of nfft real numbers may be
* the same as an output array cy[nfft+2] of nfft/2+1 complex numbers. By
* "the same array", we mean that rx === cy. In this case, both rx.length and
* cy.length equal nfft+2. When we write rx[nfft] (here and below), we imply
* that only the first nfft numbers in the input array rx are accessed.
* <p>
* Transforms may be performed for any dimension of a multi-dimensional
* array. For example, we may transform the 1st dimension of an input array
* rx[n2][nfft] of n2*nfft real numbers to an output array cy[n2][nfft+2] of
* n2*(nfft/2+1) complex numbers. Or, we may transform the 2nd dimension of
* an input array rx[nfft][n1] of nfft*n1 real numbers to an output array
* cy[nfft/2+1][2*n1] of (nfft/2+1)*n1 complex numbers. In either case, the
* input array rx and the output array cy may be the same array, such that
* the transform may be performed in-place.
* <p>
* In-place transforms are typically used to reduce memory consumption.
* Note, however, that memory consumption is reduced for only dimension-1
* in-place transformed. Dimension-2 (and higher) in-place transforms save
* no memory, because of the contiguous packing of real and imaginary parts
* of complex number in multi-dimensional array of numbers. (See above.)
* Therefore, dimension-1 transforms are best when performing real-to-complex
* of complex-to-real transforms of multi-dimensional arrays.
*
*/
export declare class FftReal {
private readonly _nfft;
/**
* Returns an FFT length optimized for memory.
* <p>
* The FFT length will be the smalled valid length that is not less than
* the specified length n.
* @param n the lower bound on FFT length.
* @returns the FFT length.
*/
static SmallNFFT(n: number): number;
/**
* Returns an FFT length optimized for speed.
* <p>
* 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.
* @returns the FFT length.
*/
static FastNFFT(n: number): number;
private static _checkSign;
private static _checkArray;
/**
* Constructs a new FFT with the specified length.
* <p>
* Valid FFT lengths an be obtained by calling the methods
* {@link SmallNFFT} and {@link FastNFFT}.
* @param nfft the FFT length, which must be valid.
*/
constructor(nfft: number);
/**
* The FFT length.
*/
get nfft(): number;
/**
* Computes a real-to-complex fast Fourier transform.
* <p>
* Transforms a 1-D input array rx[nfft] of nfft real numbers to
* a 1-D output array cy[nfft+2] of nfft/2 + 1 complex numbers.
* @param sign the sign (1 or -1) of the exponent used in the FFT.
* @param rx the input array.
* @param cy the output array.
*/
realToComplex(sign: number, rx: number[], cy: number[]): void;
/**
* Computes a complex-to-real fast Fourier transform.
* <p>
* Transforms a 1-D input array cx[nfft+2] of nfft/2+1 complex numbers
* to a 1-D output array cy[nfft] of nfft real numbers.
* @param sign the sign (1 or -1) of the exponent used in the FFT.
* @param cx the input array.
* @param ry the output array.
*/
complexToReal(sign: number, cx: number[], ry: number[]): void;
/**
* Computes a real-to-complex dimension-1 fast Fourier transform.
* <p>
* Transforms a 2-D input array rx[n2][nfft] of n2*nfft real numbers to
* a 2-D output array cy[n2][nfft+2] of n2*(nfft/2+1) complex numbers.
* @param sign the sign (1 or -1) of the exponent used in the FFT.
* @param rx the input array.
* @param cy the output array.
* @param n2 the 2nd dimension of arrays.
*/
realToComplex1(sign: number, rx: number[][], cy: number[][], n2: number): void;
/**
* Computes a real-to-complex dimension-1 fast Fourier transform.
* <p>
* Transforms a 3-D input array rx[n3][n2][nfft] of n3*n2*nfft real numbers to
* a 3-D output array cy[n3][n2][nfft+2] of n3*n2*(nfft/2+1) complex numbers.
* @param sign the sign (1 or -1) of the exponent used in the FFT.
* @param rx the input array.
* @param cy the output array.
* @param n2 the 2nd dimension of arrays.
* @param n3 the 3rd dimension of arrays.
*/
realToComplex1(sign: number, rx: number[][][], cy: number[][][], n2: number, n3?: number): void;
/**
* Computes a real-to-complex dimension-1 fast Fourier transform.
* <p>
* Transforms a 2-D input array cx[n2][nfft+2] of n2*(nfft/2+1) complex
* numbers to a 2-D output array ry[n2][nfft] of n2*nfft real 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 ry the output array.
*/
complexToReal1(sign: number, cx: number[][], ry: number[][], n2: number): void;
/**
* Computes a real-to-complex dimension-1 fast Fourier transform.
* <p>
* Transforms a 2-D input array cx[n2][nfft+2] of n2*(nfft/2+1) complex
* numbers to a 2-D output array ry[n2][nfft] of n2*nfft real 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 ry the output array.
*/
complexToReal1(sign: number, cx: number[][][], ry: number[][][], n2: number, n3: number): void;
/**
* Computes a real-to-complex dimension-2 fast Fourier transform.
* <p>
* Transform a 2-D input array rx[nfft][n1] of nfft*n1 real numbers to a
* 2-D output array cy[nfft/2+1][2*n1] of (nfft/2+1)*n1 complex number.
* @param sign the sign (1 or -1) of the exponent used in the FFT.
* @param n1 the 1st dimension of arrays.
* @param rx the input array.
* @param cy the output array.
*/
realToComplex2(sign: number, n1: number, rx: number[][], cy: number[][]): void;
/**
* Computes a complex-to-real dimension-2 fast Fourier transform.
* <p>
* Transforms a 2-D input array cx[nfft/2+1][2*n1] of (nfft/2+1)*n1 complex
* numbers to a 2-D output array ry[nfft][n1] of nfft*n1 real numbers.
* @param sign the sign (1 or -1) of the exponent used in the FFT.
* @param n1 the 1st dimension of arrays.
* @param cx the input array.
* @param ry the output array.
*/
complexToReal2(sign: number, n1: number, cx: number[][], ry: number[][]): void;
/**
* Scales n1 real numbers in the specified array by 1/nfft.
* The inverse of a real-to-complex FFT is a complex-to-real FFT
* (with opposite sign) followed by this scaling.
* @param n1 1st (only) dimension of the array rx.
* @param rx the input/output array[n1].
*/
scale(rx: number[], n1: number): void;
/**
* Scales n1*n2 real numbers in the specified array by 1/nfft.
* The inverse of a real-to-complex FFT is a complex-to-real FFT
* (with opposite sign) followed by this scaling.
* @param n1 the 1st dimension of the array rx.
* @param n2 the 2nd dimension of the array rx.
* @param rx the input/output array[n2][n1].
*/
scale(rx: number[][], n1: number, n2: number): void;
/**
* Scales n1*n2*n3 real numbers in the specified array by 1/nfft.
* The inverse of a real-to-complex FFT is a complex-to-real FFT
* (with opposite sign) followed by this scaling.
* @param n1 the 1st dimension of the array rx.
* @param n2 the 2nd dimension of the array rx.
* @param n3 the 3rd dimension of the array rx.
* @param rx the input/output array[n3][n2][n1].
*/
scale(rx: number[][][], n1: number, n2: number, n3: number): void;
}