org.apache.commons.math.transform
Class FastCosineTransformer

java.lang.Object
  extended by org.apache.commons.math.transform.FastCosineTransformer
All Implemented Interfaces:
java.io.Serializable

public class FastCosineTransformer
extends java.lang.Object
implements java.io.Serializable

Implements the Fast Cosine Transform for transformation of one-dimensional data sets. For reference, see Fast Fourier Transforms, ISBN 0849371635, chapter 3.

FCT is its own inverse, up to a multiplier depending on conventions. The equations are listed in the comments of the corresponding methods.

Different from FFT and FST, FCT requires the length of data set to be power of 2 plus one. Users should especially pay attention to the function transformation on how this affects the sampling.

Since:
1.2
Version:
$Revision: 620312 $ $Date: 2008-02-10 12:28:59 -0700 (Sun, 10 Feb 2008) $
See Also:
Serialized Form

Field Summary
(package private) static long serialVersionUID
          serializable version identifier
 
Constructor Summary
FastCosineTransformer()
          Construct a default transformer.
 
Method Summary
protected  double[] fct(double[] f)
          Perform the FCT algorithm (including inverse).
 double[] inversetransform(double[] f)
          Inversely transform the given real data set.
 double[] inversetransform(UnivariateRealFunction f, double min, double max, int n)
          Inversely transform the given real function, sampled on the given interval.
 double[] inversetransform2(double[] f)
          Inversely transform the given real data set.
 double[] inversetransform2(UnivariateRealFunction f, double min, double max, int n)
          Inversely transform the given real function, sampled on the given interval.
 double[] transform(double[] f)
          Transform the given real data set.
 double[] transform(UnivariateRealFunction f, double min, double max, int n)
          Transform the given real function, sampled on the given interval.
 double[] transform2(double[] f)
          Transform the given real data set.
 double[] transform2(UnivariateRealFunction f, double min, double max, int n)
          Transform the given real function, sampled on the given interval.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
serializable version identifier

See Also:
Constant Field Values
Constructor Detail

FastCosineTransformer

public FastCosineTransformer()
Construct a default transformer.

Method Detail

transform

public double[] transform(double[] f)
                   throws MathException,
                          java.lang.IllegalArgumentException
Transform the given real data set.

The formula is $ F_n = (1/2) [f_0 + (-1)^n f_N] + \Sigma_{k=0}^{N-1} f_k \cos(\pi nk/N) $

Parameters:
f - the real data array to be transformed
Returns:
the real transformed array
Throws:
MathException - if any math-related errors occur
java.lang.IllegalArgumentException - if any parameters are invalid

transform

public double[] transform(UnivariateRealFunction f,
                          double min,
                          double max,
                          int n)
                   throws MathException,
                          java.lang.IllegalArgumentException
Transform the given real function, sampled on the given interval.

The formula is $ F_n = (1/2) [f_0 + (-1)^n f_N] + \Sigma_{k=0}^{N-1} f_k \cos(\pi nk/N) $

Parameters:
f - the function to be sampled and transformed
min - the lower bound for the interval
max - the upper bound for the interval
n - the number of sample points
Returns:
the real transformed array
Throws:
MathException - if any math-related errors occur
java.lang.IllegalArgumentException - if any parameters are invalid

transform2

public double[] transform2(double[] f)
                    throws MathException,
                           java.lang.IllegalArgumentException
Transform the given real data set.

The formula is $ F_n = \sqrt{1/2N} [f_0 + (-1)^n f_N] + \sqrt{2/N} \Sigma_{k=0}^{N-1} f_k \cos(\pi nk/N) $

Parameters:
f - the real data array to be transformed
Returns:
the real transformed array
Throws:
MathException - if any math-related errors occur
java.lang.IllegalArgumentException - if any parameters are invalid

transform2

public double[] transform2(UnivariateRealFunction f,
                           double min,
                           double max,
                           int n)
                    throws MathException,
                           java.lang.IllegalArgumentException
Transform the given real function, sampled on the given interval.

The formula is $ F_n = \sqrt{1/2N} [f_0 + (-1)^n f_N] + \sqrt{2/N} \Sigma_{k=0}^{N-1} f_k \cos(\pi nk/N) $

Parameters:
f - the function to be sampled and transformed
min - the lower bound for the interval
max - the upper bound for the interval
n - the number of sample points
Returns:
the real transformed array
Throws:
MathException - if any math-related errors occur
java.lang.IllegalArgumentException - if any parameters are invalid

inversetransform

public double[] inversetransform(double[] f)
                          throws MathException,
                                 java.lang.IllegalArgumentException
Inversely transform the given real data set.

The formula is $ f_k = (1/N) [F_0 + (-1)^k F_N] + (2/N) \Sigma_{n=0}^{N-1} F_n \cos(\pi nk/N) $

Parameters:
f - the real data array to be inversely transformed
Returns:
the real inversely transformed array
Throws:
MathException - if any math-related errors occur
java.lang.IllegalArgumentException - if any parameters are invalid

inversetransform

public double[] inversetransform(UnivariateRealFunction f,
                                 double min,
                                 double max,
                                 int n)
                          throws MathException,
                                 java.lang.IllegalArgumentException
Inversely transform the given real function, sampled on the given interval.

The formula is $ f_k = (1/N) [F_0 + (-1)^k F_N] + (2/N) \Sigma_{n=0}^{N-1} F_n \cos(\pi nk/N) $

Parameters:
f - the function to be sampled and inversely transformed
min - the lower bound for the interval
max - the upper bound for the interval
n - the number of sample points
Returns:
the real inversely transformed array
Throws:
MathException - if any math-related errors occur
java.lang.IllegalArgumentException - if any parameters are invalid

inversetransform2

public double[] inversetransform2(double[] f)
                           throws MathException,
                                  java.lang.IllegalArgumentException
Inversely transform the given real data set.

The formula is $ f_k = \sqrt{1/2N} [F_0 + (-1)^k F_N] + \sqrt{2/N} \Sigma_{n=0}^{N-1} F_n \cos(\pi nk/N) $

Parameters:
f - the real data array to be inversely transformed
Returns:
the real inversely transformed array
Throws:
MathException - if any math-related errors occur
java.lang.IllegalArgumentException - if any parameters are invalid

inversetransform2

public double[] inversetransform2(UnivariateRealFunction f,
                                  double min,
                                  double max,
                                  int n)
                           throws MathException,
                                  java.lang.IllegalArgumentException
Inversely transform the given real function, sampled on the given interval.

The formula is $ f_k = \sqrt{1/2N} [F_0 + (-1)^k F_N] + \sqrt{2/N} \Sigma_{n=0}^{N-1} F_n \cos(\pi nk/N) $

Parameters:
f - the function to be sampled and inversely transformed
min - the lower bound for the interval
max - the upper bound for the interval
n - the number of sample points
Returns:
the real inversely transformed array
Throws:
MathException - if any math-related errors occur
java.lang.IllegalArgumentException - if any parameters are invalid

fct

protected double[] fct(double[] f)
                throws MathException,
                       java.lang.IllegalArgumentException
Perform the FCT algorithm (including inverse).

Parameters:
f - the real data array to be transformed
Returns:
the real transformed array
Throws:
MathException - if any math-related errors occur
java.lang.IllegalArgumentException - if any parameters are invalid