|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math.transform.FastFourierTransformer
public class FastFourierTransformer
Implements the Fast Fourier Transform for transformation of one-dimensional data sets. For reference, see Applied Numerical Linear Algebra, ISBN 0898713897, chapter 6.
There are several conventions for the definition of FFT and inverse FFT, mainly on different coefficient and exponent. Here the equations are listed in the comments of the corresponding methods.
We require the length of data set to be power of 2, this greatly simplifies and speeds up the code. Users can pad the data with zeros to meet this requirement. There are other flavors of FFT, for reference, see S. Winograd, On computing the discrete Fourier transform, Mathematics of Computation, 32 (1978), 175 - 199.
Field Summary | |
---|---|
private Complex[] |
omega
array of the roots of unity |
private int |
omegaCount
|omegaCount| is the length of lasted computed omega[]. |
(package private) static long |
serialVersionUID
serializable version identifier |
Constructor Summary | |
---|---|
FastFourierTransformer()
Construct a default transformer. |
Method Summary | |
---|---|
protected void |
computeOmega(int n)
Calculate the n-th roots of unity. |
protected Complex[] |
fft(Complex[] data)
Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). |
protected Complex[] |
fft(double[] f,
boolean isInverse)
Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). |
Complex[] |
inversetransform(Complex[] f)
Inversely transform the given complex data set. |
Complex[] |
inversetransform(double[] f)
Inversely transform the given real data set. |
Complex[] |
inversetransform(UnivariateRealFunction f,
double min,
double max,
int n)
Inversely transform the given real function, sampled on the given interval. |
Complex[] |
inversetransform2(Complex[] f)
Inversely transform the given complex data set. |
Complex[] |
inversetransform2(double[] f)
Inversely transform the given real data set. |
Complex[] |
inversetransform2(UnivariateRealFunction f,
double min,
double max,
int n)
Inversely transform the given real function, sampled on the given interval. |
static boolean |
isPowerOf2(long n)
Returns true if the argument is power of 2. |
static double[] |
sample(UnivariateRealFunction f,
double min,
double max,
int n)
Sample the given univariate real function on the given interval. |
static Complex[] |
scaleArray(Complex[] f,
double d)
Multiply every component in the given complex array by the given real number. |
static double[] |
scaleArray(double[] f,
double d)
Multiply every component in the given real array by the given real number. |
Complex[] |
transform(Complex[] f)
Transform the given complex data set. |
Complex[] |
transform(double[] f)
Transform the given real data set. |
Complex[] |
transform(UnivariateRealFunction f,
double min,
double max,
int n)
Transform the given real function, sampled on the given interval. |
Complex[] |
transform2(Complex[] f)
Transform the given complex data set. |
Complex[] |
transform2(double[] f)
Transform the given real data set. |
Complex[] |
transform2(UnivariateRealFunction f,
double min,
double max,
int n)
Transform the given real function, sampled on the given interval. |
static void |
verifyDataSet(double[] d)
Verifies that the data set has length of power of 2. |
static void |
verifyDataSet(java.lang.Object[] o)
Verifies that the data set has length of power of 2. |
static void |
verifyInterval(double lower,
double upper)
Verifies that the endpoints specify an interval. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final long serialVersionUID
private Complex[] omega
private int omegaCount
Constructor Detail |
---|
public FastFourierTransformer()
Method Detail |
---|
public Complex[] transform(double[] f) throws MathException, java.lang.IllegalArgumentException
The formula is $ y_n = \Sigma_{k=0}^{N-1} e^{-2 \pi i nk/N} x_k $
f
- the real data array to be transformed
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] transform(UnivariateRealFunction f, double min, double max, int n) throws MathException, java.lang.IllegalArgumentException
The formula is $ y_n = \Sigma_{k=0}^{N-1} e^{-2 \pi i nk/N} x_k $
f
- the function to be sampled and transformedmin
- the lower bound for the intervalmax
- the upper bound for the intervaln
- the number of sample points
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] transform(Complex[] f) throws MathException, java.lang.IllegalArgumentException
The formula is $ y_n = \Sigma_{k=0}^{N-1} e^{-2 \pi i nk/N} x_k $
f
- the complex data array to be transformed
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] transform2(double[] f) throws MathException, java.lang.IllegalArgumentException
The formula is $y_n = (1/\sqrt{N}) \Sigma_{k=0}^{N-1} e^{-2 \pi i nk/N} x_k$
f
- the real data array to be transformed
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] transform2(UnivariateRealFunction f, double min, double max, int n) throws MathException, java.lang.IllegalArgumentException
The formula is $y_n = (1/\sqrt{N}) \Sigma_{k=0}^{N-1} e^{-2 \pi i nk/N} x_k$
f
- the function to be sampled and transformedmin
- the lower bound for the intervalmax
- the upper bound for the intervaln
- the number of sample points
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] transform2(Complex[] f) throws MathException, java.lang.IllegalArgumentException
The formula is $y_n = (1/\sqrt{N}) \Sigma_{k=0}^{N-1} e^{-2 \pi i nk/N} x_k$
f
- the complex data array to be transformed
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] inversetransform(double[] f) throws MathException, java.lang.IllegalArgumentException
The formula is $ x_k = (1/N) \Sigma_{n=0}^{N-1} e^{2 \pi i nk/N} y_n $
f
- the real data array to be inversely transformed
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] inversetransform(UnivariateRealFunction f, double min, double max, int n) throws MathException, java.lang.IllegalArgumentException
The formula is $ x_k = (1/N) \Sigma_{n=0}^{N-1} e^{2 \pi i nk/N} y_n $
f
- the function to be sampled and inversely transformedmin
- the lower bound for the intervalmax
- the upper bound for the intervaln
- the number of sample points
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] inversetransform(Complex[] f) throws MathException, java.lang.IllegalArgumentException
The formula is $ x_k = (1/N) \Sigma_{n=0}^{N-1} e^{2 \pi i nk/N} y_n $
f
- the complex data array to be inversely transformed
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] inversetransform2(double[] f) throws MathException, java.lang.IllegalArgumentException
The formula is $x_k = (1/\sqrt{N}) \Sigma_{n=0}^{N-1} e^{2 \pi i nk/N} y_n$
f
- the real data array to be inversely transformed
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] inversetransform2(UnivariateRealFunction f, double min, double max, int n) throws MathException, java.lang.IllegalArgumentException
The formula is $x_k = (1/\sqrt{N}) \Sigma_{n=0}^{N-1} e^{2 \pi i nk/N} y_n$
f
- the function to be sampled and inversely transformedmin
- the lower bound for the intervalmax
- the upper bound for the intervaln
- the number of sample points
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic Complex[] inversetransform2(Complex[] f) throws MathException, java.lang.IllegalArgumentException
The formula is $x_k = (1/\sqrt{N}) \Sigma_{n=0}^{N-1} e^{2 \pi i nk/N} y_n$
f
- the complex data array to be inversely transformed
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidprotected Complex[] fft(double[] f, boolean isInverse) throws MathException, java.lang.IllegalArgumentException
f
- the real data array to be transformedisInverse
- the indicator of forward or inverse transform
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidprotected Complex[] fft(Complex[] data) throws MathException, java.lang.IllegalArgumentException
data
- the complex data array to be transformed
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidprotected void computeOmega(int n) throws java.lang.IllegalArgumentException
The computed omega[] = { 1, w, w^2, ... w^(n-1) } where w = exp(-2 \pi i / n), i = sqrt(-1). Note n is positive for forward transform and negative for inverse transform.
n
- the integer passed in
java.lang.IllegalArgumentException
- if n = 0public static double[] sample(UnivariateRealFunction f, double min, double max, int n) throws MathException, java.lang.IllegalArgumentException
The interval is divided equally into N sections and sample points are taken from min to max-(max-min)/N. Usually f(x) is periodic such that f(min) = f(max) (note max is not sampled), but we don't require that.
f
- the function to be sampledmin
- the lower bound for the intervalmax
- the upper bound for the intervaln
- the number of sample points
MathException
- if any math-related errors occur
java.lang.IllegalArgumentException
- if any parameters are invalidpublic static double[] scaleArray(double[] f, double d)
f
- the real array to be scaledd
- the real scaling coefficient
public static Complex[] scaleArray(Complex[] f, double d)
f
- the complex array to be scaledd
- the real scaling coefficient
public static boolean isPowerOf2(long n)
n
- the number to test
public static void verifyDataSet(double[] d) throws java.lang.IllegalArgumentException
d
- the data array
java.lang.IllegalArgumentException
- if array length is not power of 2public static void verifyDataSet(java.lang.Object[] o) throws java.lang.IllegalArgumentException
o
- the data array
java.lang.IllegalArgumentException
- if array length is not power of 2public static void verifyInterval(double lower, double upper) throws java.lang.IllegalArgumentException
lower
- lower endpointupper
- upper endpoint
java.lang.IllegalArgumentException
- if not interval
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |