Example usage for org.apache.commons.math3.transform DftNormalization STANDARD

List of usage examples for org.apache.commons.math3.transform DftNormalization STANDARD

Introduction

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

Prototype

DftNormalization STANDARD

To view the source code for org.apache.commons.math3.transform DftNormalization STANDARD.

Click Source Link

Document

Should be passed to the constructor of FastFourierTransformer to use the standard normalization convention.

Usage

From source file:com.mycompany.semconsolewebapp.FFT.java

public static double[] forward(double[] data) {
    FastFourierTransformer f = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] fftC = f.transform(data, TransformType.FORWARD);

    for (int i = 0; i < data.length; i++) {

        data[i] = fftC[i].abs();/*from w  w w.ja  va 2 s  . c  o  m*/

        if (Double.isNaN(data[i])) {
            System.out.println("C " + fftC[i].getReal() + " + i" + fftC[i].getImaginary());
            System.out.println("D " + data[i]);
            break;
        }
    }

    return data;
}

From source file:br.prof.salesfilho.oci.util.OCIUtils.java

public static Complex[] fft(double[] input, TransformType type) {
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] resultComplex = fft.transform(input, type);
    return resultComplex;
}

From source file:com.fpuna.preproceso.util.Util.java

public static double[] transform(double[] input) {
    //double[] tempConversion = new double[input.length];
    double[] tempConversion = new double[2048];

    FastFourierTransformer transformer = new FastFourierTransformer(DftNormalization.STANDARD);
    try {/*from ww  w.j  a v  a2 s  .  co m*/
        Complex[] complx = transformer.transform(input, TransformType.FORWARD);

        for (int i = 0; i < complx.length; i++) {
            double rr = (complx[i].getReal());
            double ri = (complx[i].getImaginary());

            tempConversion[i] = Math.sqrt((rr * rr) + (ri * ri));
        }

    } catch (IllegalArgumentException e) {
        System.out.println(e);
    }

    return tempConversion;
}

From source file:br.prof.salesfilho.oci.util.OCIUtils.java

public static Complex[] fft(Complex[] input, TransformType type) {
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] resultComplex = fft.transform(input, type);
    return resultComplex;
}

From source file:com.bleedobsidian.datawave.utils.Sinewave.java

/**
 * Calculate the frequency of sine wave from sound data.
 * //from   w  ww. ja v a2 s .c om
 * @param sampleRate Sample rate.
 * @param samples Samples.
 * 
 * @return Frequency.
 */
public static double calculateFrequency(double sampleRate, double[] samples) {
    FastFourierTransformer transformer = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] complex = transformer.transform(samples, TransformType.FORWARD);

    double real;
    double im;
    double mag[] = new double[complex.length];

    for (int i = 0; i < complex.length; i++) {
        real = complex[i].getReal();
        im = complex[i].getImaginary();
        mag[i] = Math.sqrt((real * real) + (im * im));
    }

    double peak = 0.2;
    int index = -1;
    for (int i = 0; i < complex.length; i++) {
        if (peak < mag[i]) {
            index = i;
            peak = mag[i];
        }
    }

    return ((sampleRate * index) / Audio.SAMPLE_BUFFER_SIZE) * 2;
}

From source file:br.prof.salesfilho.oci.util.OCIUtils.java

public static double[] fft_forward_double(double[] input) {
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] complexTransInput = fft.transform(input, TransformType.FORWARD);
    double[] result = new double[complexTransInput.length];
    for (int i = 0; i < complexTransInput.length; i++) {
        result[i] = (complexTransInput[i].getReal());
    }/*  w ww.  j a  v a 2s.c  o m*/
    return result;
}

From source file:br.prof.salesfilho.oci.util.OCIUtils.java

public static double[] fft_magnitude(double[] input) {
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] complexTransInput = fft.transform(input, TransformType.FORWARD);
    for (int i = 0; i < complexTransInput.length; i++) {
        double real = (complexTransInput[i].getReal());
        double img = (complexTransInput[i].getImaginary());
        input[i] = (Math.pow(real, 2) + Math.pow(img, 2));
    }/*  w  w  w .  j  ava 2  s  . c  o m*/
    return input;
}

From source file:kip.utils.PowerUtils.java

/**
 * Performs a FFT over the data// w ww . jav  a 2 s. c  o  m
 * @param samples   samples to perform FFT over
 * @return          transformed voltage
 */
public static double[] voltageTransform(int[] samples) {
    double[][] data = new double[2][samples.length];

    for (int i = 0; i < data[0].length; i++) {
        data[0][i] = i;
        data[1][i] = 0;
    }

    FastFourierTransformer.transformInPlace(data, DftNormalization.STANDARD, TransformType.FORWARD);
    //System.out.println(java.util.Arrays.toString(samples) + "\n");
    //System.out.println(java.util.Arrays.toString(data[0]) + "\n");
    return data[0];
}

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Freqz.java

public Freqz(double[] b, double[] a, int n) {
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);

    Complex[] hb = fft.transform(Arrays.copyOf(b, 2 * n), TransformType.FORWARD);
    Complex[] ha = fft.transform(Arrays.copyOf(a, 2 * n), TransformType.FORWARD);

    H = new Complex[n];
    w = new double[n];

    for (int i = 0; i < H.length; i++) {
        H[i] = hb[i].divide(ha[i]);/*from ww w  .j a v  a  2  s.c o  m*/
        w[i] = Math.PI / n * i;
    }

}

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Freqz.java

public Freqz(double[] b, int n) {
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] hb = fft.transform(Arrays.copyOf(b, 2 * n), TransformType.FORWARD);

    H = Arrays.copyOfRange(hb, 0, n);
    w = new double[n];

    for (int i = 0; i < H.length; i++) {
        w[i] = Math.PI / n * i;/*  ww  w.  j a va  2 s.  c  om*/
    }
}