org.apache.commons.math3.transform

## Class FastCosineTransformer

• All Implemented Interfaces:
Serializable, RealTransformer

```public class FastCosineTransformer
extends Object
implements RealTransformer, Serializable```

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

There are several variants of the discrete cosine transform. The present implementation corresponds to DCT-I, with various normalization conventions, which are specified by the parameter `DctNormalization`.

DCT-I is equivalent to DFT of an even extension of the data series. More precisely, if x0, …, xN-1 is the data set to be cosine transformed, the extended data set x0#, …, x2N-3# is defined as follows

• xk# = xk if 0 ≤ k < N,
• xk# = x2N-2-k if N ≤ k < 2N - 2.

Then, the standard DCT-I y0, …, yN-1 of the real data set x0, …, xN-1 is equal to half of the N first elements of the DFT of the extended data set x0#, …, x2N-3#
yn = (1 / 2) ∑k=02N-3 xk# exp[-2πi nk / (2N - 2)]     k = 0, …, N-1.

The present implementation of the discrete cosine transform as a fast cosine transform requires the length of the data set to be a power of two plus one (N = 2n + 1). Besides, it implicitly assumes that the sampled function is even.

Since:
1.2
Version:
\$Id: FastCosineTransformer.java 1244107 2012-02-14 16:17:55Z erans \$
Serialized Form
• ### Constructor Summary

Constructors
Constructor and Description
`FastCosineTransformer(DctNormalization normalization)`
Creates a new instance of this class, with various normalization conventions.
• ### Method Summary

Methods
Modifier and Type Method and Description
`protected double[]` `fct(double[] f)`
Perform the FCT algorithm (including inverse).
`double[]` ```transform(double[] f, TransformType type)```
Returns the (forward, inverse) transform of the specified real data set.
`double[]` ```transform(UnivariateFunction f, double min, double max, int n, TransformType type)```
Returns the (forward, inverse) transform of the specified real function, sampled on the specified interval.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### FastCosineTransformer

`public FastCosineTransformer(DctNormalization normalization)`
Creates a new instance of this class, with various normalization conventions.
Parameters:
`normalization` - the type of normalization to be applied to the transformed data
• ### Method Detail

• #### transform

```public double[] transform(double[] f,
TransformType type)```
Returns the (forward, inverse) transform of the specified real data set.
Specified by:
`transform` in interface `RealTransformer`
Parameters:
`f` - the real data array to be transformed (signal)
`type` - the type of transform (forward, inverse) to be performed
Returns:
the real transformed array (spectrum)
Throws:
`MathIllegalArgumentException` - if the length of the data array is not a power of two plus one
• #### transform

```public double[] transform(UnivariateFunction f,
double min,
double max,
int n,
TransformType type)```
Returns the (forward, inverse) transform of the specified real function, sampled on the specified interval.
Specified by:
`transform` in interface `RealTransformer`
Parameters:
`f` - the function to be sampled and transformed
`min` - the (inclusive) lower bound for the interval
`max` - the (exclusive) upper bound for the interval
`n` - the number of sample points
`type` - the type of transform (forward, inverse) to be performed
Returns:
the real transformed array
Throws:
`NonMonotonicSequenceException` - if the lower bound is greater than, or equal to the upper bound
`NotStrictlyPositiveException` - if the number of sample points is negative
`MathIllegalArgumentException` - if the number of sample points is not a power of two plus one
• #### fct

```protected double[] fct(double[] f)
throws MathIllegalArgumentException```
Perform the FCT algorithm (including inverse).
Parameters:
`f` - the real data array to be transformed
Returns:
the real transformed array
Throws:
`MathIllegalArgumentException` - if the length of the data array is not a power of two plus one