Class FastSineTransform

  • All Implemented Interfaces:
    Function<double[],​double[]>, UnaryOperator<double[]>, RealTransform

    public class FastSineTransform
    extends Object
    implements RealTransform
    Implements the Fast Sine 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 sine transform. The present implementation corresponds to DST-I, with various normalization conventions, which are specified by the parameter FastSineTransform.Norm. It should be noted that regardless to the convention, the first element of the dataset to be transformed must be zero.

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

    • x0# = x0 = 0,
    • xk# = xk if 1 ≤ k < N,
    • xN# = 0,
    • xk# = -x2N-k if N + 1 ≤ k < 2N.

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

    The present implementation of the discrete sine transform as a fast sine transform requires the length of the data to be a power of two. Besides, it implicitly assumes that the sampled function is odd. In particular, the first element of the data set must be 0, which is enforced in apply(DoubleUnaryOperator, double, double, int), after sampling.

    • Constructor Detail

      • FastSineTransform

        public FastSineTransform​(FastSineTransform.Norm normalization,
                                 boolean inverse)
        Parameters:
        normalization - Normalization to be applied to the transformed data.
        inverse - Whether to perform the inverse transform.
    • Method Detail

      • apply

        public double[] apply​(double[] f)
        Returns the transform of the specified data set. The first element of the specified data set is required to be 0.
        Specified by:
        apply in interface Function<double[],​double[]>
        Specified by:
        apply in interface RealTransform
        Parameters:
        f - the data array to be transformed (signal).
        Returns:
        the transformed array (spectrum).
        Throws:
        IllegalArgumentException - if the length of the data array is not a power of two, or the first element of the data array is not zero.
      • apply

        public double[] apply​(DoubleUnaryOperator f,
                              double min,
                              double max,
                              int n)
        Returns the transform of the specified function. The implementation enforces f(x) = 0 at x = 0.
        Specified by:
        apply in interface RealTransform
        Parameters:
        f - Function to be sampled and transformed.
        min - Lower bound (inclusive) of the interval.
        max - Upper bound (exclusive) of the interval.
        n - Number of sample points.
        Returns:
        the result.
        Throws:
        IllegalArgumentException - if the number of sample points is not a power of two, if the lower bound is greater than, or equal to the upper bound, if the number of sample points is negative.