Java Code Examples for org.apache.commons.math3.complex.Complex#ZERO

The following examples show how to use org.apache.commons.math3.complex.Complex#ZERO . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkData.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
public static BranchAdmittanceMatrix calculateBranchAdmittance(double r, double x, double ratio1, double alpha1,
    double ratio2, double alpha2, Complex ysh1, Complex ysh2) {

    Complex a1 = ComplexUtils.polar2Complex(ratio1, alpha1);
    Complex a2 = ComplexUtils.polar2Complex(ratio2, alpha2);

    Complex ytr;
    if (r == 0.0 && x == 0.0) {
        ytr = Complex.ZERO;
    } else {
        ytr = new Complex(r, x).reciprocal();
    }

    BranchAdmittanceMatrix branchAdmittance = new BranchAdmittanceMatrix();

    branchAdmittance.y11 = ytr.add(ysh1).divide(a1.conjugate().multiply(a1));
    branchAdmittance.y12 = ytr.negate().divide(a1.conjugate().multiply(a2));
    branchAdmittance.y21 = ytr.negate().divide(a2.conjugate().multiply(a1));
    branchAdmittance.y22 = ytr.add(ysh2).divide(a2.conjugate().multiply(a2));

    return branchAdmittance;
}
 
Example 2
Source File: LinkData.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
static Complex kronAntenna(Complex y11, Complex y12, Complex y21, Complex y22, boolean isOpenFrom) {
    Complex ysh = Complex.ZERO;

    if (isOpenFrom) {
        if (!y11.equals(Complex.ZERO)) {
            ysh = y22.subtract(y21.multiply(y12).divide(y11));
        }
    } else {
        if (!y22.equals(Complex.ZERO)) {
            ysh = y11.subtract(y12.multiply(y21).divide(y22));
        }
    }
    return ysh;
}
 
Example 3
Source File: Filters.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
public static void highpassfftfilt(List<double[]> set, double lowfreq, double highfreq) {
	/*
	 * steps:
	 * 1. pad data with 0s to get the number of samples to a power of 2
	 * 2. perform fft
	 * 3. filter based on frequency (see http://stackoverflow.com/a/2876292)
	 * 4. inverse fft
	 */

	//step 1
	ArrayList<double[]> padded = new ArrayList<double[]>(set);
	int padTo = Filters.findNextLargestPower2(padded.size());
	for(int i = padded.size(); i < padTo; i++) {
		padded.add(new double[]{0.0, 0.0});
	}
	double[][] arr = Filters.toArray(padded);

	//step 2
	FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
	Complex[] out = fft.transform(arr[1], TransformType.FORWARD);

	//step 3
	double sampFreq = 1000.0 / (arr[0][1]-arr[0][0]);
	int posHalf = out.length / 2;
	for(int i = 0; i < posHalf; i++) {
		int negInd = out.length - 1 - i;
		double currFreq = (double)i * (sampFreq / (double)posHalf);
		if (currFreq > lowfreq) {
			out[i] = Complex.ZERO;
			out[negInd] = Complex.ZERO;
		} /* else if (currFreq < highfreq) {
			double scale = 1.0 - ((currFreq - highFreq) / (lowFreq - highFreq));
			out[i] = out[i].multiply(scale);
			out[negInd] = out[negInd].multiply(scale);
		} */
	}

	//step 4
	out = fft.transform(out, TransformType.INVERSE);

	//write changes
	for(int i = 0; i < set.size(); i++) {
		set.set(i, new double[]{set.get(i)[0], out[i].getReal()});
	}
}