Example usage for org.apache.commons.math3.transform TransformType INVERSE

List of usage examples for org.apache.commons.math3.transform TransformType INVERSE

Introduction

In this page you can find the example usage for org.apache.commons.math3.transform TransformType INVERSE.

Prototype

TransformType INVERSE

To view the source code for org.apache.commons.math3.transform TransformType INVERSE.

Click Source Link

Document

The type to be specified for inverse transforms.

Usage

From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java

/**
 * Computes discrete Hilbert transform of the input array (in place) using
 * FFTs. The transform operation is computed in place. For efficiency, no
 * error checking is performed on input data range limits or length of input
 * array. The input array length <b>must</b> be equal to a power of 2,
 * otherwise a runtime exception may be thrown.
 *
 * @param a         input array//w w w. ja v  a 2s . c o  m
 * @param isForward true for forward Hilbert transform, false for inverse
 *                  Hilbert transform
 */
public static final void fastHilbertTransformPowerOf2(double[] a, boolean isForward) {
    int n = a.length;
    int nOver2 = n / 2;
    double c = isForward ? 1.0 : -1.0;

    // create zero-valued imaginary component
    double[] aIm = new double[n];

    // perform FFT
    FastFourierTransformer.transformInPlace(new double[][] { a, aIm }, DftNormalization.STANDARD,
            TransformType.FORWARD);

    // zero out DC and Nyquist components
    a[0] = aIm[0] = a[nOver2] = aIm[nOver2] = 0.0;

    // multiply positive frequency components by -I
    for (int i = 1; i < nOver2; i++) {
        double temp = a[i];
        a[i] = c * aIm[i];
        aIm[i] = -c * temp;
    }

    // multiply negative frequency components by I
    for (int i = nOver2 + 1; i < n; i++) {
        double temp = a[i];
        a[i] = -c * aIm[i];
        aIm[i] = c * temp;
    }

    FastFourierTransformer.transformInPlace(new double[][] { a, aIm }, DftNormalization.STANDARD,
            TransformType.INVERSE);
}

From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java

/**
 * Filters input array within specified range by Fourier transforming the
 * segment of the input array, multiplying the real and imaginary parts of
 * the transformed segment by {@code filterCoefficients} element-by-element,
 * and inverse Fourier transforming the result. The output is the filtered
 * segment; input array is unchanged. The length of the segment to be
 * filtered <b>must</b> be a power-of-2, otherwise unexpected results or
 * runtime errors may occur. No error checking is performed on range limits;
 * if the values are negative or outside the range of the array, a runtime
 * exception may be thrown./*from  ww w.j  a v a 2s  .  co m*/
 *
 * @param a                  input array (assumed to be real-valued)
 * @param from               initial index of the range of elements to
 *                           filter
 * @param to                 final index of the range of elements to filter
 * @param filterCoefficients frequency-domain filter coefficients; if length
 *                           of array is not equal to {@code from-to},
 *                           return an unmodified copy of the input array
 *                           segment
 * @return filtered array segment
 */
public static final double[] freqDomainFilter(double[] a, int from, int to, double[] filterCoefficients) {
    int n = to - from;

    double[] re = Arrays.copyOfRange(a, from, to);
    if (filterCoefficients.length != n) {
        return re;
    }

    double[] im = new double[n];

    FastFourierTransformer.transformInPlace(new double[][] { re, im }, DftNormalization.STANDARD,
            TransformType.FORWARD);
    for (int i = 0; i < n; i++) {
        re[i] *= filterCoefficients[i];
        im[i] *= filterCoefficients[i];
    }
    FastFourierTransformer.transformInPlace(new double[][] { re, im }, DftNormalization.STANDARD,
            TransformType.INVERSE);

    return re;
}

From source file:org.hawkular.datamining.forecast.utils.AutomaticPeriodIdentificationTest.java

/**
 *
 * http://stackoverflow.com/questions/12239096/computing-autocorrelation-with-fft-using-jtransforms-library
 * http://dsp.stackexchange.com/questions/3337/finding-peaks-in-an-autocorrelation-function
 * @throws IOException/*from   w  w w .j a v a2  s .co  m*/
 */
//    @Test
public void testFFT() throws IOException {

    ModelData rModel = ModelReader.read("austourists");
    double[] x = Utils.toArray(rModel.getData());

    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);

    Complex[] forward = fft.transform(x, TransformType.FORWARD);
    Complex[] inverse = fft.transform(forward, TransformType.INVERSE);
}