Example usage for org.apache.commons.math3.complex ComplexUtils convertToComplex

List of usage examples for org.apache.commons.math3.complex ComplexUtils convertToComplex

Introduction

In this page you can find the example usage for org.apache.commons.math3.complex ComplexUtils convertToComplex.

Prototype

public static Complex[] convertToComplex(double[] real) 

Source Link

Document

Convert an array of primitive doubles to an array of Complex objects.

Usage

From source file:jurbano.melodyshape.comparison.bspline.Laguerre.java

protected Complex[] findAllComplexRoots(PolynomialFunction f) {
    // This call to super.setup is the change we need in the Laguerre
    // implementation from the Apache Commons Math library. Need to set
    // up the maximum number of iterations and the bounds 0 and 1.
    // The original implementation had the maximum number of iterations set
    // to Integer.MAX_VALUE
    super.setup(this.maxIterations, f, 0, 1, 0);
    return this.solver.solveAll(ComplexUtils.convertToComplex(f.getCoefficients()), new Complex(0, 0d));
}

From source file:tw.edu.sju.ee.eea.module.iepe.file.IepeSpectrumElement.java

private JFreeChart createChart() {
    XYSeries series = new XYSeries("Ch_0");

    try {/*w  w w.j a  v  a  2 s  .c om*/
        ValueInputStream vi = new ValueInputStream(info.getInputStream());
        vi.skip(info.getCursor().getIndex() / 8);
        double[] value = new double[1024 * 16];
        for (int i = 0; i < value.length; i++) {
            value[i] = vi.readValue();
        }

        FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
        Complex[] data = ComplexUtils.convertToComplex(value);
        Complex[] transform = fft.transform(data, TransformType.FORWARD);
        int max = transform.length / 2 + 1;
        for (int i = 1; i < max; i++) {
            double f = (double) i * info.getSamplerate() / transform.length;
            series.add(f, transform[i].abs() / value.length * 2);
        }

    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
    }

    XYSeriesCollection collection = new XYSeriesCollection();
    collection.addSeries(series);

    BodePlot bodePlot = new BodePlot("Spectrum");
    bodePlot.addData(0, "Magnitude(dB)", collection);
    bodePlot.getXYPlot().getRangeAxis().setRange(0, 500);
    bodePlot.getXYPlot().getDomainAxis().setRange(0.5, 10000);
    return bodePlot;
}