In package o.a.c.m.transform, created enum DstNormalization to be passed to the constructor of FastSineTransformer (instead of boolean parameter).
Made constructor public, and removed factory methods. See MATH-743 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1243595 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1d67ef4bed
commit
274e2aa33f
|
@ -22,7 +22,7 @@ package org.apache.commons.math.transform;
|
||||||
* normalizations is detailed below.
|
* normalizations is detailed below.
|
||||||
*
|
*
|
||||||
* @see FastCosineTransformer
|
* @see FastCosineTransformer
|
||||||
* @version $Id Revision$
|
* @version $Id$
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public enum DctNormalization {
|
public enum DctNormalization {
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.apache.commons.math.transform;
|
||||||
* normalizations is detailed below.
|
* normalizations is detailed below.
|
||||||
*
|
*
|
||||||
* @see FastFourierTransformer
|
* @see FastFourierTransformer
|
||||||
* @version $Id Revision$
|
* @version $Id$
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public enum DftNormalization {
|
public enum DftNormalization {
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.commons.math.transform;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This enumeration defines the various types of normalizations that can be
|
||||||
|
* applied to discrete sine transforms (DST). The exact definition of these
|
||||||
|
* normalizations is detailed below.
|
||||||
|
*
|
||||||
|
* @see FastSineTransformer
|
||||||
|
* @version $Id$
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public enum DstNormalization {
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Should be passed to the constructor of {@link FastSineTransformer} to
|
||||||
|
* use the <em>standard</em> normalization convention. The standard DST-I
|
||||||
|
* normalization convention is defined as follows
|
||||||
|
* <ul>
|
||||||
|
* <li>forward transform: y<sub>n</sub> = ∑<sub>k=0</sub><sup>N-1</sup>
|
||||||
|
* x<sub>k</sub> sin(π nk / N),</li>
|
||||||
|
* <li>inverse transform: x<sub>k</sub> = (2 / N)
|
||||||
|
* ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> sin(π nk / N),</li>
|
||||||
|
* </ul>
|
||||||
|
* where N is the size of the data sample, and x<sub>0</sub> = 0.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
STANDARD_DST_I,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Should be passed to the constructor of {@link FastSineTransformer} to
|
||||||
|
* use the <em>orthogonal</em> normalization convention. The orthogonal
|
||||||
|
* DCT-I normalization convention is defined as follows
|
||||||
|
* <ul>
|
||||||
|
* <li>Forward transform: y<sub>n</sub> = √(2 / N)
|
||||||
|
* ∑<sub>k=0</sub><sup>N-1</sup> x<sub>k</sub> sin(π nk / N),</li>
|
||||||
|
* <li>Inverse transform: x<sub>k</sub> = √(2 / N)
|
||||||
|
* ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> sin(π nk / N),</li>
|
||||||
|
* </ul>
|
||||||
|
* which makes the transform orthogonal. N is the size of the data sample,
|
||||||
|
* and x<sub>0</sub> = 0.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
ORTHOGONAL_DST_I
|
||||||
|
}
|
|
@ -35,42 +35,10 @@ import org.apache.commons.math.util.FastMath;
|
||||||
* <p>
|
* <p>
|
||||||
* There are several variants of the discrete sine transform. The present
|
* There are several variants of the discrete sine transform. The present
|
||||||
* implementation corresponds to DST-I, with various normalization conventions,
|
* implementation corresponds to DST-I, with various normalization conventions,
|
||||||
* which are described below. <strong>It should be noted that regardless to the
|
* which are specified by the parameter {@link DstNormalization}.
|
||||||
* convention, the first element of the dataset to be transformed must be
|
* <strong>It should be noted that regardless to the convention, the first
|
||||||
* zero.</strong>
|
* element of the dataset to be transformed must be zero.</strong>
|
||||||
* </p>
|
* </p>
|
||||||
* <h3><a id="standard">Standard DST-I</a></h3>
|
|
||||||
* <p>
|
|
||||||
* The standard normalization convention is defined as follows
|
|
||||||
* <ul>
|
|
||||||
* <li>forward transform: y<sub>n</sub> = ∑<sub>k=0</sub><sup>N-1</sup>
|
|
||||||
* x<sub>k</sub> sin(π nk / N),</li>
|
|
||||||
* <li>inverse transform: x<sub>k</sub> = (2 / N)
|
|
||||||
* ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> sin(π nk / N),</li>
|
|
||||||
* </ul>
|
|
||||||
* where N is the size of the data sample, and x<sub>0</sub> = 0.
|
|
||||||
* </p>
|
|
||||||
* <p>
|
|
||||||
* {@link RealTransformer}s following this convention are returned by the
|
|
||||||
* factory method {@link #create()}.
|
|
||||||
* </p>
|
|
||||||
* <h3><a id="orthogonal">Orthogonal DST-I</a></h3>
|
|
||||||
* <p>
|
|
||||||
* The orthogonal normalization convention is defined as follows
|
|
||||||
* <ul>
|
|
||||||
* <li>Forward transform: y<sub>n</sub> = √(2 / N)
|
|
||||||
* ∑<sub>k=0</sub><sup>N-1</sup> x<sub>k</sub> sin(π nk / N),</li>
|
|
||||||
* <li>Inverse transform: x<sub>k</sub> = √(2 / N)
|
|
||||||
* ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> sin(π nk / N),</li>
|
|
||||||
* </ul>
|
|
||||||
* which makes the transform orthogonal. N is the size of the data sample, and
|
|
||||||
* x<sub>0</sub> = 0.
|
|
||||||
* </p>
|
|
||||||
* <p>
|
|
||||||
* {@link RealTransformer}s following this convention are returned by the
|
|
||||||
* factory method {@link #createOrthogonal()}.
|
|
||||||
* </p>
|
|
||||||
* <h3>Link with the DFT, and assumptions on the layout of the data set</h3>
|
|
||||||
* <p>
|
* <p>
|
||||||
* DST-I is equivalent to DFT of an <em>odd extension</em> of the data series.
|
* DST-I is equivalent to DFT of an <em>odd extension</em> of the data series.
|
||||||
* More precisely, if x<sub>0</sub>, …, x<sub>N-1</sub> is the data set
|
* More precisely, if x<sub>0</sub>, …, x<sub>N-1</sub> is the data set
|
||||||
|
@ -104,7 +72,7 @@ import org.apache.commons.math.util.FastMath;
|
||||||
* sampling.
|
* sampling.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @version $Id: FastSineTransformer.java 1213157 2011-12-12 07:19:23Z celestin$
|
* @version $Id$
|
||||||
* @since 1.2
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public class FastSineTransformer implements RealTransformer, Serializable {
|
public class FastSineTransformer implements RealTransformer, Serializable {
|
||||||
|
@ -112,50 +80,18 @@ public class FastSineTransformer implements RealTransformer, Serializable {
|
||||||
/** Serializable version identifier. */
|
/** Serializable version identifier. */
|
||||||
static final long serialVersionUID = 20120211L;
|
static final long serialVersionUID = 20120211L;
|
||||||
|
|
||||||
/**
|
/** The type of DST to be performed. */
|
||||||
* {@code true} if the orthogonal version of the DCT should be used.
|
private final DstNormalization normalization;
|
||||||
*
|
|
||||||
* @see #create()
|
|
||||||
* @see #createOrthogonal()
|
|
||||||
*/
|
|
||||||
private final boolean orthogonal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of this class, with various normalization
|
* Creates a new instance of this class, with various normalization
|
||||||
* conventions.
|
* conventions.
|
||||||
*
|
*
|
||||||
* @param orthogonal {@code false} if the DST is <em>not</em> to be scaled,
|
* @param normalization the type of normalization to be applied to the
|
||||||
* {@code true} if it is to be scaled so as to make the transform
|
* transformed data
|
||||||
* orthogonal.
|
|
||||||
* @see #create()
|
|
||||||
* @see #createOrthogonal()
|
|
||||||
*/
|
*/
|
||||||
private FastSineTransformer(final boolean orthogonal) {
|
public FastSineTransformer(final DstNormalization normalization) {
|
||||||
this.orthogonal = orthogonal;
|
this.normalization = normalization;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Returns a new instance of this class. The returned transformer uses the
|
|
||||||
* <a href="#standard">standard normalizing conventions</a>.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @return a new DST transformer, with standard normalizing conventions
|
|
||||||
*/
|
|
||||||
public static FastSineTransformer create() {
|
|
||||||
return new FastSineTransformer(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Returns a new instance of this class. The returned transformer uses the
|
|
||||||
* <a href="#orthogonal">orthogonal normalizing conventions</a>.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @return a new DST transformer, with orthogonal normalizing conventions
|
|
||||||
*/
|
|
||||||
public static FastSineTransformer createOrthogonal() {
|
|
||||||
return new FastSineTransformer(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,7 +103,7 @@ public class FastSineTransformer implements RealTransformer, Serializable {
|
||||||
* not a power of two, or the first element of the data array is not zero
|
* not a power of two, or the first element of the data array is not zero
|
||||||
*/
|
*/
|
||||||
public double[] transform(final double[] f, final TransformType type) {
|
public double[] transform(final double[] f, final TransformType type) {
|
||||||
if (orthogonal) {
|
if (normalization == DstNormalization.ORTHOGONAL_DST_I) {
|
||||||
final double s = FastMath.sqrt(2.0 / f.length);
|
final double s = FastMath.sqrt(2.0 / f.length);
|
||||||
return TransformUtils.scaleArray(fst(f), s);
|
return TransformUtils.scaleArray(fst(f), s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue