1
0
mirror of https://github.com/apache/commons-math.git synced 2025-03-07 08:59:09 +00:00

- Changed enum FastFourierTransformer.DftNormalization to top-level enumeration (MATH-743).

- Moved part of the Javadoc of FastFourierTransformer to this new enum.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1243009 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2012-02-11 06:24:15 +00:00
parent dee1c0d70b
commit 29e6359399
5 changed files with 89 additions and 73 deletions
src
main/java/org/apache/commons/math/transform
test/java/org/apache/commons/math/transform

@ -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 Fourier transforms (DFT). The exact definition of these
* normalizations is detailed below.
*
* @see FastFourierTransformer
* @version $Id Revision$
* @since 3.0
*/
public enum DftNormalization {
/**
* <p>
* Should be passed to the constructor of e.g.
* {@link FastFourierTransformer} to use the <em>standard</em> normalization
* convention. This normalization convention is defined as follows
* <ul>
* <li>forward transform: y<sub>n</sub> = &sum;<sub>k=0</sub><sup>N-1</sup>
* x<sub>k</sub> exp(-2&pi;i n k / N),</li>
* <li>inverse transform: x<sub>k</sub> = N<sup>-1</sup>
* &sum;<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> exp(2&pi;i n k / N),</li>
* </ul>
* where N is the size of the data sample.
* </p>
*/
STANDARD,
/**
* <p>
* Should be passed to the constructor of e.g.
* {@link FastFourierTransformer} to use the <em>unitary</em> normalization
* convention. This normalization convention is defined as follows
* <ul>
* <li>forward transform: y<sub>n</sub> = (1 / &radic;N)
* &sum;<sub>k=0</sub><sup>N-1</sup> x<sub>k</sub>
* exp(-2&pi;i n k / N),</li>
* <li>inverse transform: x<sub>k</sub> = (1 / &radic;N)
* &sum;<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> exp(2&pi;i n k / N),</li>
* </ul>
* which makes the transform unitary. N is the size of the data sample.
* </p>
*/
UNITARY;
}

@ -25,7 +25,6 @@ import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.NonMonotonicSequenceException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.transform.FastFourierTransformer.DftNormalization;
import org.apache.commons.math.util.ArithmeticUtils;
import org.apache.commons.math.util.FastMath;

@ -38,7 +38,8 @@ import org.apache.commons.math.util.MathArrays;
* </p>
* <p>
* There are several variants of the discrete Fourier transform, with various
* normalization conventions, which are described below.
* normalization conventions, which are specified by the parameter
* {@link DftNormalization}.
* </p>
* <p>
* The current implementation of the discrete Fourier transform as a fast
@ -49,56 +50,13 @@ import org.apache.commons.math.util.MathArrays;
* <i>On computing the discrete Fourier transform</i>, Mathematics of
* Computation, 32 (1978), 175 - 199.
* </p>
* <h3><a id="standard">Standard DFT</a></h3>
* <p>
* The standard normalization convention is defined as follows
* <ul>
* <li>forward transform: y<sub>n</sub> = &sum;<sub>k=0</sub><sup>N-1</sup>
* x<sub>k</sub> exp(-2&pi;i n k / N),</li>
* <li>inverse transform: x<sub>k</sub> = N<sup>-1</sup>
* &sum;<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> exp(2&pi;i n k / N),</li>
* </ul>
* where N is the size of the data sample.
* </p>
* <p>
* {@link FastFourierTransformer}s following this convention are returned by the
* factory method {@link #create()}.
* </p>
* <h3><a id="unitary">Unitary DFT</a></h3>
* <p>
* The unitary normalization convention is defined as follows
* <ul>
* <li>forward transform: y<sub>n</sub> = (1 / &radic;N)
* &sum;<sub>k=0</sub><sup>N-1</sup> x<sub>k</sub> exp(-2&pi;i n k / N),</li>
* <li>inverse transform: x<sub>k</sub> = (1 / &radic;N)
* &sum;<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> exp(2&pi;i n k / N),</li>
* </ul>
* which makes the transform unitary. N is the size of the data sample.
* </p>
* <p>
* {@link FastFourierTransformer}s following this convention are returned by the
* factory method {@link #createUnitary()}.
* </p>
*
* @see DftNormalization
* @version $Id$
* @since 1.2
*/
public class FastFourierTransformer implements Serializable {
/**
* The various types of normalizations that can be applied to discrete
* Fourier transforms.
*
* @see FastFourierTransformer
*/
public static enum DftNormalization {
/** The normalization to be specified for standard DFT. */
STANDARD,
/** The normalization to be specified for unitary DFT. */
UNITARY;
}
/** Serializable version identifier. */
static final long serialVersionUID = 20120210L;

@ -25,7 +25,6 @@ import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.NonMonotonicSequenceException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.transform.FastFourierTransformer.DftNormalization;
import org.apache.commons.math.util.ArithmeticUtils;
import org.apache.commons.math.util.FastMath;

@ -26,7 +26,6 @@ import org.apache.commons.math.complex.Complex;
import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
import org.apache.commons.math.exception.NumberIsTooLargeException;
import org.apache.commons.math.transform.FastFourierTransformer.DftNormalization;
import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
@ -51,8 +50,8 @@ public final class FastFourierTransformerTest {
public void testTransformComplexSizeNotAPowerOfTwo() {
final int n = 127;
final Complex[] x = createComplexData(n);
final FastFourierTransformer.DftNormalization[] norm;
norm = FastFourierTransformer.DftNormalization.values();
final DftNormalization[] norm;
norm = DftNormalization.values();
final TransformType[] type;
type = TransformType.values();
for (int i = 0; i < norm.length; i++) {
@ -74,8 +73,8 @@ public final class FastFourierTransformerTest {
public void testTransformRealSizeNotAPowerOfTwo() {
final int n = 127;
final double[] x = createRealData(n);
final FastFourierTransformer.DftNormalization[] norm;
norm = FastFourierTransformer.DftNormalization.values();
final DftNormalization[] norm;
norm = DftNormalization.values();
final TransformType[] type;
type = TransformType.values();
for (int i = 0; i < norm.length; i++) {
@ -97,8 +96,8 @@ public final class FastFourierTransformerTest {
public void testTransformFunctionSizeNotAPowerOfTwo() {
final int n = 127;
final UnivariateFunction f = new Sin();
final FastFourierTransformer.DftNormalization[] norm;
norm = FastFourierTransformer.DftNormalization.values();
final DftNormalization[] norm;
norm = DftNormalization.values();
final TransformType[] type;
type = TransformType.values();
for (int i = 0; i < norm.length; i++) {
@ -120,8 +119,8 @@ public final class FastFourierTransformerTest {
public void testTransformFunctionNotStrictlyPositiveNumberOfSamples() {
final int n = -128;
final UnivariateFunction f = new Sin();
final FastFourierTransformer.DftNormalization[] norm;
norm = FastFourierTransformer.DftNormalization.values();
final DftNormalization[] norm;
norm = DftNormalization.values();
final TransformType[] type;
type = TransformType.values();
for (int i = 0; i < norm.length; i++) {
@ -144,8 +143,8 @@ public final class FastFourierTransformerTest {
public void testTransformFunctionInvalidBounds() {
final int n = 128;
final UnivariateFunction f = new Sin();
final FastFourierTransformer.DftNormalization[] norm;
norm = FastFourierTransformer.DftNormalization.values();
final DftNormalization[] norm;
norm = DftNormalization.values();
final TransformType[] type;
type = TransformType.values();
for (int i = 0; i < norm.length; i++) {
@ -216,7 +215,7 @@ public final class FastFourierTransformerTest {
}
private static void doTestTransformComplex(final int n, final double tol,
final FastFourierTransformer.DftNormalization normalization,
final DftNormalization normalization,
final TransformType type) {
final FastFourierTransformer fft;
fft = new FastFourierTransformer(normalization);
@ -225,14 +224,14 @@ public final class FastFourierTransformerTest {
final double s;
if (type==TransformType.FORWARD) {
expected = dft(x, -1);
if (normalization == FastFourierTransformer.DftNormalization.STANDARD){
if (normalization == DftNormalization.STANDARD){
s = 1.0;
} else {
s = 1.0 / FastMath.sqrt(n);
}
} else {
expected = dft(x, 1);
if (normalization == FastFourierTransformer.DftNormalization.STANDARD) {
if (normalization == DftNormalization.STANDARD) {
s = 1.0 / n;
} else {
s = 1.0 / FastMath.sqrt(n);
@ -252,7 +251,7 @@ public final class FastFourierTransformerTest {
}
private static void doTestTransformReal(final int n, final double tol,
final FastFourierTransformer.DftNormalization normalization,
final DftNormalization normalization,
final TransformType type) {
final FastFourierTransformer fft;
fft = new FastFourierTransformer(normalization);
@ -265,14 +264,14 @@ public final class FastFourierTransformerTest {
final double s;
if (type == TransformType.FORWARD) {
expected = dft(xc, -1);
if (normalization == FastFourierTransformer.DftNormalization.STANDARD) {
if (normalization == DftNormalization.STANDARD) {
s = 1.0;
} else {
s = 1.0 / FastMath.sqrt(n);
}
} else {
expected = dft(xc, 1);
if (normalization == FastFourierTransformer.DftNormalization.STANDARD) {
if (normalization == DftNormalization.STANDARD) {
s = 1.0 / n;
} else {
s = 1.0 / FastMath.sqrt(n);
@ -293,7 +292,7 @@ public final class FastFourierTransformerTest {
private static void doTestTransformFunction(final UnivariateFunction f,
final double min, final double max, int n, final double tol,
final FastFourierTransformer.DftNormalization normalization,
final DftNormalization normalization,
final TransformType type) {
final FastFourierTransformer fft;
fft = new FastFourierTransformer(normalization);
@ -306,14 +305,14 @@ public final class FastFourierTransformerTest {
final double s;
if (type == TransformType.FORWARD) {
expected = dft(x, -1);
if (normalization == FastFourierTransformer.DftNormalization.STANDARD) {
if (normalization == DftNormalization.STANDARD) {
s = 1.0;
} else {
s = 1.0 / FastMath.sqrt(n);
}
} else {
expected = dft(x, 1);
if (normalization == FastFourierTransformer.DftNormalization.STANDARD) {
if (normalization == DftNormalization.STANDARD) {
s = 1.0 / n;
} else {
s = 1.0 / FastMath.sqrt(n);
@ -337,8 +336,8 @@ public final class FastFourierTransformerTest {
@Test
public void testTransformComplex() {
final FastFourierTransformer.DftNormalization[] norm;
norm = FastFourierTransformer.DftNormalization.values();
final DftNormalization[] norm;
norm = DftNormalization.values();
final TransformType[] type;
type = TransformType.values();
for (int i = 0; i < norm.length; i++) {
@ -356,8 +355,8 @@ public final class FastFourierTransformerTest {
@Test
public void testStandardTransformReal() {
final FastFourierTransformer.DftNormalization[] norm;
norm = FastFourierTransformer.DftNormalization.values();
final DftNormalization[] norm;
norm = DftNormalization.values();
final TransformType[] type;
type = TransformType.values();
for (int i = 0; i < norm.length; i++) {
@ -378,8 +377,8 @@ public final class FastFourierTransformerTest {
final UnivariateFunction f = new Sinc();
final double min = -FastMath.PI;
final double max = FastMath.PI;
final FastFourierTransformer.DftNormalization[] norm;
norm = FastFourierTransformer.DftNormalization.values();
final DftNormalization[] norm;
norm = DftNormalization.values();
final TransformType[] type;
type = TransformType.values();
for (int i = 0; i < norm.length; i++) {