Example usage for org.apache.commons.math3.complex Complex ZERO

List of usage examples for org.apache.commons.math3.complex Complex ZERO

Introduction

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

Prototype

Complex ZERO

To view the source code for org.apache.commons.math3.complex Complex ZERO.

Click Source Link

Document

A complex number representing "0.0 + 0.0i"

Usage

From source file:com.wwidesigner.math.StateVector.java

/**
 * @return a state vector representing an ideal open end.
 *//*from w  w w  .  ja  v a2  s .c o m*/
public static StateVector OpenEnd() {
    // At an open end, pressure is zero.
    return new StateVector(Complex.ZERO, Complex.ONE);
}

From source file:com.wwidesigner.math.StateVector.java

/**
 * @return a state vector representing an ideal closed end.
 *///ww  w.ja  v a2  s .  co  m
public static StateVector ClosedEnd() {
    // At a closed end, acoustic flow is zero.
    return new StateVector(Complex.ONE, Complex.ZERO);
}

From source file:com.wwidesigner.math.StateVector.java

/**
 * Simple 2x1 complex vector representing the state of the air column at a
 * point in the bore. P refers to the pressure and U to the volume flow.
 *//*w w w  . jav a2s  . co  m*/
public StateVector() {
    mP = Complex.ZERO;
    mU = Complex.ZERO;
}

From source file:net.sf.dsp4j.octave_3_2_4.m.polynomial.Poly.java

public static Complex[] poly(Complex[] x) {

    Complex[] y;//  w  ww . java2  s  .c o  m

    if (x.length == 0) {
        return new Complex[] { Complex.ONE };
    }

    y = new Complex[x.length + 1];
    Arrays.fill(y, Complex.ZERO);
    y[0] = Complex.ONE;
    for (int j = 1; j < y.length; j++) {
        for (int i = j; i >= 1; i--) {
            y[i] = y[i].subtract(x[j - 1].multiply(y[i - 1]));
        }
    }

    return y;
}

From source file:com.wwidesigner.math.TransferMatrix.java

/**
 * Simple 2x2 complex matrix. Here e.g. PU represents the component of the
 * output pressure that depends on the input volume flow, etc.
 * The default matrix is the identity matrix.
 *///from  ww  w.  j  a  v  a2 s.  co m
public TransferMatrix() {
    mPP = Complex.ONE;
    mPU = Complex.ZERO;
    mUP = Complex.ZERO;
    mUU = Complex.ONE;
}

From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Zp2Sos.java

public Zp2Sos(Complex[] zeros, Complex[] poles, double gain) {
    this.gain = gain;

    CplxReal cplxReal = new CplxReal();

    cplxReal.cplxReal(0.0000000001, zeros);
    Complex[] zc = cplxReal.getConjComplxPair();
    Complex[] zr = cplxReal.getRealValues();

    cplxReal.cplxReal(0.0000000001, poles);
    Complex[] pc = cplxReal.getConjComplxPair();
    Complex[] pr = cplxReal.getRealValues();

    int nzc = zc.length;
    int npc = pc.length;

    int nzr = zr.length;
    int npr = pr.length;

    // Pair up real zeros:
    int nzrsec = 0;
    Complex[] zrms = new Complex[0];
    Complex[] zrp = new Complex[0];
    if (nzr > 0) {
        if (nzr % 2 == 1) {
            zr = Arrays.copyOf(zr, zr.length + 1);
            zr[zr.length - 1] = Complex.ZERO;
            nzr++;//from   w  w  w  . j  a v  a2  s.  co m
        }
        nzrsec = nzr / 2;
        zrms = new Complex[nzrsec];
        zrp = new Complex[nzrsec];
        for (int i = 0; i < zrms.length; i++) {
            zrms[i] = zr[i * 2].negate().subtract(zr[i * 2 + 1]);
            zrp[i] = zr[i * 2].multiply(zr[i * 2 + 1]);
        }
    }

    // Pair up real poles:
    int nprsec = 0;
    Complex[] prms = new Complex[0];
    Complex[] prp = new Complex[0];
    if (npr > 0) {
        if (npr % 2 == 1) {
            pr = Arrays.copyOf(pr, pr.length + 1);
            pr[pr.length - 1] = Complex.ZERO;
            npr++;
        }
        nprsec = npr / 2;
        prms = new Complex[nprsec];
        prp = new Complex[nprsec];
        for (int i = 0; i < prms.length; i++) {
            prms[i] = pr[i * 2].negate().subtract(pr[i * 2 + 1]);
            prp[i] = pr[i * 2].multiply(pr[i * 2 + 1]);
        }
    }

    int nsecs = Math.max(nzc + nzrsec, npc + nprsec);

    // Convert complex zeros and poles to real 2nd-order section form:
    double[] zcm2r = OctaveBuildIn.real(zc);
    for (int i = 0; i < zcm2r.length; i++) {
        zcm2r[i] *= -2;
    }
    double[] zca2 = OctaveBuildIn.abs(zc);
    for (int i = 0; i < zca2.length; i++) {
        zca2[i] = Math.pow(zca2[i], 2);
    }
    double[] pcm2r = OctaveBuildIn.real(pc);
    for (int i = 0; i < pcm2r.length; i++) {
        pcm2r[i] *= -2;
    }
    double[] pca2 = OctaveBuildIn.abs(pc);
    for (int i = 0; i < pca2.length; i++) {
        pca2[i] = Math.pow(pca2[i], 2);
    }

    //all 2nd-order polynomials are monic
    sos = new double[nsecs][6];
    for (int i = 0; i < nsecs; i++) {
        sos[i][0] = 1;
        sos[i][3] = 1;
    }

    int nzrl = nzc + nzrsec; // index of last real zero section
    int nprl = npc + nprsec; // index of last real pole section

    for (int i = 0; i < nsecs; i++) {

        if (i < nzc) {
            // lay down a complex zero pair:
            sos[i][1] = zcm2r[i];
            sos[i][2] = zca2[i];
        } else if (i < nzrl) {
            // lay down a pair of real zeros:
            sos[i][1] = zrms[i - nzc].getReal();
            sos[i][2] = zrp[i - nzc].getReal();
        }

        if (i < npc) {
            // lay down a complex pole pair:
            sos[i][4] = pcm2r[i];
            sos[i][5] = pca2[i];
        } else if (i < nprl) {
            //lay down a pair of real poles:
            sos[i][4] = prms[i - npc].getReal();
            sos[i][5] = prp[i - npc].getReal();
        }
    }
}

From source file:com.wwidesigner.geometry.calculation.FluteMouthpieceCalculator.java

@Override
protected TransferMatrix calcTransferMatrix(Mouthpiece mouthpiece, double waveNumber,
        PhysicalParameters parameters) {
    if (mouthpiece.isPressureNode()) {
        // Resort to default if this is not a flow-node mouthpiece.
        return super.calcTransferMatrix(mouthpiece, waveNumber, parameters);
    }/*from   w  w w .j  a  v  a2s.  c  o m*/

    double freq = parameters.calcFrequency(waveNumber);

    Complex Zwindow = calcZ(mouthpiece, freq, parameters);
    return new TransferMatrix(Complex.ONE, Zwindow, Complex.ZERO, Complex.ONE);
}

From source file:com.wwidesigner.geometry.calculation.SimpleReedMouthpieceCalculator.java

@Override
protected TransferMatrix calcTransferMatrix(Mouthpiece mouthpiece, double waveNumber,
        PhysicalParameters parameters) {
    if (!mouthpiece.isPressureNode()) {
        // Resort to default if this is not a pressure-node mouthpiece.
        return super.calcTransferMatrix(mouthpiece, waveNumber, parameters);
    }//  w  w w  .j  a v  a2s .  com

    double freq = parameters.calcFrequency(waveNumber);
    double alpha = 0.0;
    Double beta = mouthpiece.getBeta();
    if (beta == null) {
        beta = 0.0;
    }
    //      double reedResonance = 440.0;
    if (mouthpiece.getSingleReed() != null) {
        alpha = mouthpiece.getSingleReed().getAlpha();
    } else if (mouthpiece.getDoubleReed() != null) {
        alpha = mouthpiece.getDoubleReed().getAlpha();
        //         reedResonance = mouthpiece.getDoubleReed().getCrowFreq();
    } else if (mouthpiece.getLipReed() != null) {
        // For lip reeds, adjustment factor is negative.
        alpha = +mouthpiece.getLipReed().getAlpha();
        beta = -beta;
    }

    double headRadius = 0.5 * mouthpiece.getBoreDiameter();
    double z0 = parameters.calcZ0(headRadius);
    double X = alpha * 1.0e-3 * freq + beta;
    TransferMatrix closedEnd = new TransferMatrix(new Complex(0.0, X), new Complex(z0, 0.0),
            new Complex(1.0, 0.0), Complex.ZERO);
    return closedEnd;
}

From source file:com.wwidesigner.geometry.calculation.SimpleFippleMouthpieceCalculator.java

@Override
protected TransferMatrix calcTransferMatrix(Mouthpiece mouthpiece, double waveNumber,
        PhysicalParameters parameters) {
    if (mouthpiece.isPressureNode()) {
        // Resort to default if this is not a flow-node mouthpiece.
        return super.calcTransferMatrix(mouthpiece, waveNumber, parameters);
    }/*  w w  w.j a v a  2  s .  com*/

    double freq = parameters.calcFrequency(waveNumber);

    Complex Zwindow = calcZ(mouthpiece, freq, parameters);
    /*
    List<BoreSection> headspace = mouthpiece.getHeadspace();
    if (headspace.size() > 0)
    {
       StateVector windowState = new StateVector(Zwindow, Complex.ONE);
       StateVector headspaceState = calcHeadspace_compliance(headspace, waveNumber, parameters);
            
       // Assume the bore sees the window impedance in parallel with
       // the headspace impedance.
       windowState = windowState.parallel(headspaceState);
       Zwindow = windowState.getImpedance();
    }
    */
    return new TransferMatrix(Complex.ONE, Zwindow, Complex.ZERO, Complex.ONE);
}

From source file:net.sf.dsp4j.octave_3_2_4.m.polynomial.Roots.java

public static Complex[] roots(RealVector v) {

    if (v.isInfinite() || v.isNaN()) {
        throw new RuntimeException("roots: inputs must not contain Inf or NaN");
    }//ww  w  . j  a  v  a  2s .  c o  m

    int n = v.getDimension();

    // ## If v = [ 0 ... 0 v(k+1) ... v(k+l) 0 ... 0 ], we can remove the
    // ## leading k zeros and n - k - l roots of the polynomial are zero.

    int[] f = new int[v.getDimension()];
    if (v.getDimension() > 0) {
        int fI = 0;
        double max = v.getMaxValue();
        double min = FastMath.abs(v.getMinValue());
        if (min > max) {
            max = min;
        }
        RealVector v1 = v.mapDivide(max);
        f = OctaveBuildIn.find(v1);
    }

    Complex[] r = new Complex[0];
    if (f.length > 0 && n > 1) {
        v = v.getSubVector(f[0], f[f.length - 1] - f[0] + 1);
        if (v.getDimension() > 1) {
            double[] ones = new double[v.getDimension() - 2];
            Arrays.fill(ones, 1);
            RealMatrix A = OctaveBuildIn.diag(ones, -1);
            for (int i = 0; i < A.getRowDimension(); i++) {
                A.setEntry(i, 0, -v.getEntry(i + 1) / v.getEntry(0));
            }
            try {
                r = Eig.eig(A);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (f[f.length - 1] < n) {
                int diffLength = n - 1 - f[f.length - 1];
                if (diffLength > 0) {
                    int rl = r.length;
                    r = Arrays.copyOf(r, r.length + diffLength);
                    Arrays.fill(r, rl, r.length, Complex.ZERO);
                }
            }
        } else {
            r = new Complex[n - f[f.length - 1]];
            Arrays.fill(r, Complex.ZERO);
        }
    } else {
        r = new Complex[0];
    }
    return r;

}