Top Description Fields Constructors Methods
org.apache.commons.math3.transform

public Class FastCosineTransformer

extends Object
implements RealTransformer, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.transform.RealTransformer
Imports
java.io.Serializable, org.apache.commons.math3.analysis.FunctionUtils, .UnivariateFunction, org.apache.commons.math3.complex.Complex, org.apache.commons.math3.exception.MathIllegalArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.ArithmeticUtils, .FastMath

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

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

Field Summary

Modifier and TypeField and Description
private final DctNormalization
normalization

The type of DCT to be performed.

pack-priv static final long
serialVersionUID

Serializable version identifier.

Constructor Summary

AccessConstructor and Description
public
FastCosineTransformer(final DctNormalization
the type of normalization to be applied to the transformed data
normalization
)

Creates a new instance of this class, with various normalization conventions.

Method Summary

Modifier and TypeMethod and Description
protected double[]

Returns:

the real transformed array
fct
(double[]
the real data array to be transformed
f
)

Perform the FCT algorithm (including inverse).

public double[]
transform(final double[]
the real data array to be transformed (signal)
f
,
final TransformType
the type of transform (forward, inverse) to be performed
type
)

Implements org.apache.commons.math3.transform.RealTransformer.transform.

Returns the (forward, inverse) transform of the specified real data set.

public double[]
transform(final UnivariateFunction
the function to be sampled and transformed
f
,
final double
the (inclusive) lower bound for the interval
min
,
final double
the (exclusive) upper bound for the interval
max
,
final int
the number of sample points
n
,
final TransformType
the type of transform (forward, inverse) to be performed
type
)

Implements org.apache.commons.math3.transform.RealTransformer.transform.

Returns the (forward, inverse) transform of the specified real function, sampled on the specified interval.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

normalizationback to summary
private final DctNormalization normalization

The type of DCT to be performed.

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Serializable version identifier.

Constructor Detail

FastCosineTransformerback to summary
public FastCosineTransformer(final DctNormalization normalization)

Creates a new instance of this class, with various normalization conventions.

Parameters
normalization:DctNormalization

the type of normalization to be applied to the transformed data

Method Detail

fctback to summary
protected double[] fct(double[] f) throws MathIllegalArgumentException

Perform the FCT algorithm (including inverse).

Parameters
f:double[]

the real data array to be transformed

Returns:double[]

the real transformed array

Exceptions
MathIllegalArgumentException:
if the length of the data array is not a power of two plus one
transformback to summary
public double[] transform(final double[] f, final TransformType type) throws MathIllegalArgumentException

Implements org.apache.commons.math3.transform.RealTransformer.transform.

Doc from org.apache.commons.math3.transform.RealTransformer.transform.

Returns the (forward, inverse) transform of the specified real data set.

Parameters
f:double[]

the real data array to be transformed (signal)

type:TransformType

the type of transform (forward, inverse) to be performed

Returns:double[]

the real transformed array (spectrum)

Exceptions
MathIllegalArgumentException:
if the length of the data array is not a power of two plus one
transformback to summary
public double[] transform(final UnivariateFunction f, final double min, final double max, final int n, final TransformType type) throws MathIllegalArgumentException

Implements org.apache.commons.math3.transform.RealTransformer.transform.

Doc from org.apache.commons.math3.transform.RealTransformer.transform.

Returns the (forward, inverse) transform of the specified real function, sampled on the specified interval.

Parameters
f:UnivariateFunction

the function to be sampled and transformed

min:double

the (inclusive) lower bound for the interval

max:double

the (exclusive) upper bound for the interval

n:int

the number of sample points

type:TransformType

the type of transform (forward, inverse) to be performed

Returns:double[]

the real transformed array

Exceptions
MathIllegalArgumentException:
if the number of sample points is not a power of two plus one
NonMonotonicSequenceException:
if the lower bound is greater than, or equal to the upper bound
NotStrictlyPositiveException:
if the number of sample points is negative