/** * Return the absolute value of the given complex number * * @param num the number to getScalar the absolute value for * @return the absolute value of this complex number */ public static IComplexNumber abs(IComplexNumber num) { double c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).abs(); return Nd4j.createDouble(c, 0); }
/** * Check whether the given complex root is actually a real zero * in the given interval, within the solver tolerance level. * * @param min Lower bound for the interval. * @param max Upper bound for the interval. * @param z Complex root. * @return {@code true} if z is a real zero. */ public boolean isRoot(double min, double max, Complex z) { if (isSequence(min, z.getReal(), max)) { double tolerance = FastMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy()); return (FastMath.abs(z.getImaginary()) <= tolerance) || (z.abs() <= getFunctionValueAccuracy()); } return false; }
return createComplex(FastMath.log(abs()), FastMath.atan2(imaginary, real));
final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n);
double t = FastMath.sqrt((FastMath.abs(real) + abs()) / 2.0); if (real >= 0.0) { return createComplex(t, imaginary / (2.0 * t));
final double tolerance = FastMath.max(relativeAccuracy * z.abs(), absoluteAccuracy); if ((z.subtract(oldz)).abs() <= tolerance) { return z; if (pv.abs() <= functionValueAccuracy) { return z; final Complex dplus = G.add(deltaSqrt); final Complex dminus = G.subtract(deltaSqrt); final Complex denominator = dplus.abs() > dminus.abs() ? dplus : dminus;
public ArrayList<double[]> fft(double[] signal, double samplingInterval) { /* Returns positive half of the Fourier transform of the signal. Sampling interval 'samplingInterval', in milliseconds */ int ns = signal.length; Complex[] complex; double[] terms; double[] frequencyArray; double[] x; double[] y; if (ns % 2 == 1) { ns = ns - 1; signal = Arrays.copyOfRange(signal, 0, ns); } FastFourierTransformer fastFourierTransformer = new FastFourierTransformer(DftNormalization.STANDARD); complex = fastFourierTransformer.transform(signal, TransformType.FORWARD); terms = new double[complex.length]; for (int i = 0; i < complex.length; i++) terms[i] = complex[i].abs() / ns; frequencyArray = fftFrequency(ns, samplingInterval); x = Arrays.copyOfRange(frequencyArray, 0, ns / 2); y = Arrays.copyOfRange(terms, 0, ns / 2); return new ArrayList<double[]>(Arrays.asList(x, y)); }
amplitude = new double[complex.length / 2]; for (int i = 0; i < complex.length / 2; i++) { // take only the +ive half of the fft result amplitude[i] = complex[i].abs() / voltageLength; if (amplitude[i] > max) { // search for the tallest peak, the fundamental max = amplitude[i];
public double findFrequency(double[] voltage, double samplingInterval) { int voltageLength = voltage.length; double[] frequency; double[] amplitude; int index = 0; double max = 0; Complex[] complex; DescriptiveStatistics stats = new DescriptiveStatistics(); for (int i = 0; i < voltageLength; i++) stats.addValue(voltage[i]); double voltageMean = stats.getMean(); for (int i = 0; i < voltageLength; i++) voltage[i] = voltage[i] - voltageMean; // remove DC component frequency = Arrays.copyOfRange(fftFrequency(voltageLength, samplingInterval), 0, voltageLength / 2); // take only the +ive half of the frequncy array FastFourierTransformer fastFourierTransformer = new FastFourierTransformer(DftNormalization.STANDARD); complex = fastFourierTransformer.transform(voltage, TransformType.FORWARD); amplitude = new double[complex.length / 2]; for (int i = 0; i < complex.length / 2; i++) { // take only the +ive half of the fft result amplitude[i] = complex[i].abs() / voltageLength; if (amplitude[i] > max) { // search for the tallest peak, the fundamental max = amplitude[i]; index = i; } } return frequency[index]; }
public double getMagnitude() { return value.abs(); }
/** * c = abs(a) Michael Borcherds 2009-03-10 * * @param a * a * @return absolute value of a */ public static double complexAbs(GeoVec2D a) { Complex out = new Complex(a.x, a.y); return out.abs(); }
@Override public int compareTo(Node primitive) { if (primitive == null) return 1; if (!(primitive instanceof ComplexNode)) throw new RuntimeException("Attempted to compare primitives of different types."); ComplexNode that = (ComplexNode) primitive; int result = new Double(value.abs()).compareTo(that.value.abs()); if (result != 0) return result; result = new Double(value.getArgument()).compareTo(that.value.getArgument()); return result; }
public static float numberOfIterationsToCheckSmooth(Complex z0, int max) { Complex z = z0; for (int t = 0; t < max; t++) { double fAbs = z.abs(); if (fAbs > 2.0) { // based on the final value, add a fractional amount based on // how much it escaped by (fAbs will be in the range of 2 to around 4): return (float)t + (2.0f - (Math.log(fAbs) / Math.log(2.0))); } z =z.multiply(z).add(z0); } return (float)max; }
@Override public double getMaxValue (final Spectrum<Complex []> fs, final int low, final int high) { return fs.getState () [this.getMaxIndex (fs, low, high)].abs (); }
/** * Return the absolute value of the given complex number * * @param num the number to getScalar the absolute value for * @return the absolute value of this complex number */ public static IComplexNumber abs(IComplexNumber num) { double c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).abs(); return Nd4j.createDouble(c, 0); }
@Override public Spectrum<Complex []> spectrumToCepstrum (final Spectrum<Complex []> spectrum) { final double [] logSpectrumReals = new double [spectrum.getState ().length]; for (int i = 0 ; i < logSpectrumReals.length ; i++) { logSpectrumReals [i] = Math.log (1 + NaiveSpectrumToCepstrumHelper.A_CONSTANT_TO_REDUCE_OCTAVE_ERRORS * spectrum.getState () [i].abs ()); } final FastFourierTransformer fastFourierTransformer = new FastFourierTransformer (DftNormalization.STANDARD); return new Spectrum<Complex []> (fastFourierTransformer.transform (logSpectrumReals, TransformType.INVERSE), spectrum.getFormatInfo ()); } }
public StateVariable toSv1(StateVariable sv2) { Complex s2 = new Complex(-sv2.p, -sv2.q); // s2=p2+jq2 Complex u2 = ComplexUtils.polar2Complex(sv2.u, Math.toRadians(sv2.theta)); Complex v2 = u2.divide(SQUARE_3); // v2=u2/sqrt(3) Complex i2 = s2.divide(v2.multiply(3)).conjugate(); // i2=conj(s2/(3*v2)) Complex v1p = v2.add(z.multiply(i2)); // v1'=v2+z*i2 Complex i1p = i2.negate().add(y.multiply(v1p)); // i1'=-i2+v1'*y Complex i1 = i1p.multiply(ratio); // i1=i1p*ration Complex v1 = v1p.divide(ratio); // v1=v1p/ration Complex s1 = v1.multiply(3).multiply(i1.conjugate()); // s1=3*v1*conj(i1) Complex u1 = v1.multiply(SQUARE_3); return new StateVariable(-s1.getReal(), -s1.getImaginary(), u1.abs(), Math.toDegrees(u1.getArgument())); }
@Override public Spectrum<Complex []> transformFrequencies (final Spectrum<Complex []> fs, final int offset, final int powOf2NearestLength, final int length) { final double threshold = this.getMaxAbs (fs.getSampleSize ()); final Complex [] newAmpl = new Complex [powOf2NearestLength]; for (double j = 0 ; j < length ; j++) { newAmpl [(int) j] = fs.getState () [(int) j].multiply (this.oneIfTrueElseZero (fs.getState () [(int) j].abs () > threshold)); } for (int j = length ; j < powOf2NearestLength ; j++) { newAmpl [j] = new Complex (0, 0); } return new Spectrum<Complex []> (newAmpl, new FormatInfo (fs.getSampleSize (), fs.getSampleRate ())); }
public StateVariable toSv2(StateVariable sv1) { Complex s1 = new Complex(-sv1.p, -sv1.q); // s1=p1+jq1 Complex u1 = ComplexUtils.polar2Complex(sv1.u, Math.toRadians(sv1.theta)); Complex v1 = u1.divide(SQUARE_3); // v1=u1/sqrt(3) Complex v1p = v1.multiply(ratio); // v1p=v1*rho Complex i1 = s1.divide(v1.multiply(3)).conjugate(); // i1=conj(s1/(3*v1)) Complex i1p = i1.divide(ratio); // i1p=i1/rho Complex i2 = i1p.subtract(y.multiply(v1p)).negate(); // i2=-(i1p-y*v1p) Complex v2 = v1p.subtract(z.multiply(i2)); // v2=v1p-z*i2 Complex s2 = v2.multiply(3).multiply(i2.conjugate()); // s2=3*v2*conj(i2) Complex u2 = v2.multiply(SQUARE_3); return new StateVariable(-s2.getReal(), -s2.getImaginary(), u2.abs(), Math.toDegrees(u2.getArgument())); }