Example usage for org.apache.commons.math3.util FastMath cosh

List of usage examples for org.apache.commons.math3.util FastMath cosh

Introduction

In this page you can find the example usage for org.apache.commons.math3.util FastMath cosh.

Prototype

public static double cosh(double x) 

Source Link

Document

Compute the hyperbolic cosine of a number.

Usage

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

public static double[] cheb(int n, double[] x) {

    if (n <= 0) {
        throw new IllegalArgumentException("cheb: n has to be a positive integer");
    }/*  w  w w . j a v  a2 s  . c o  m*/

    if (x.length == 0) {
        return new double[0];
    }
    //# avoid resizing latencies
    double[] T = new double[x.length];
    for (int i = 0; i < x.length; i++) {
        if (Math.abs(x[i]) > 1) {
            T[i] = FastMath.cos(n * FastMath.acos(x[i]));
        } else {
            T[i] = FastMath.cosh(n * FastMath.acosh(x[i]));
        }
    }
    return T;
}

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

private Cheby1(int n, double Rp, double[] W, boolean digital, boolean stop) {
    super(W, digital, stop);

    if (Rp < 0) {
        throw new IllegalArgumentException("cheby1: passband ripple must be positive decibels");
    }// www .  j  ava  2 s  . c  o m

    this.Rp = Rp;

    //## Generate splane poles and zeros for the chebyshev type 1 filter
    final double C = 1; //# default cutoff frequency
    final double epsilon = FastMath.sqrt(FastMath.pow(10, (Rp / 10)) - 1);
    final double v0 = FastMath.asinh(1 / epsilon) / n;
    pole = new Complex[n];
    for (int i = 0; i < n; i++) {
        final Complex p = new Complex(0, FastMath.PI * (2.0 * i - n + 1.0) / (2.0 * n)).exp(); //TODO richtig ???
        pole[i] = new Complex(-FastMath.sinh(v0) * p.getReal())
                .add(IMAG_ONE.multiply(FastMath.cosh(v0)).multiply(p.getImaginary()));
    }
    zero = new Complex[0];

    //## compensate for amplitude at s=0
    Complex gainC = OctaveBuildIn.prod(OctaveBuildIn.neg(pole));
    //## if n is even, the ripple starts low, but if n is odd the ripple
    //## starts high. We must adjust the s=0 amplitude to compensate.
    if (n % 2 == 0) {
        gainC = gainC.divide(FastMath.pow(10, Rp / 20));
    }
    gain = gainC.getReal();
}

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

private Cheby2(int n, double Rs, double[] W, boolean digital, boolean stop) {
    super(W, digital, stop);

    if (Rs < 0) {
        throw new IllegalArgumentException("cheby2: stopband attenuation must be positive decibels");
    }//  w w w . ja  v  a 2s  .  c om

    this.Rs = Rs;

    //## Generate splane poles and zeros for the chebyshev type 2 filter
    //## From: Stearns, SD; David, RA; (1988). Signal Processing Algorithms.
    //##       New Jersey: Prentice-Hall.
    int C = 1; //# default cutoff frequency
    final double lambda = FastMath.pow(10, Rs / 20);
    final double phi = FastMath.log(lambda + FastMath.sqrt(FastMath.pow(lambda, 2) - 1)) / n;
    final double[] theta = new double[n];
    final double[] alpha = new double[n];
    final double[] beta = new double[n];

    for (int i = 0; i < n; i++) {
        theta[i] = FastMath.PI * (i + 0.5) / n;
        alpha[i] = -FastMath.sinh(phi) * FastMath.sin(theta[i]);
        beta[i] = FastMath.cosh(phi) * FastMath.cos(theta[i]);
    }
    final Complex IMAG_ONE = new Complex(0.0, 1);
    if (n % 2 != 0) {
        //## drop theta==pi/2 since it results in a zero at infinity
        zero = new Complex[n - 1];
        for (int i = 0; i < n / 2; i++) {
            zero[i] = IMAG_ONE.multiply(C / FastMath.cos(theta[i]));
        }
        for (int i = n / 2 + 1; i < n; i++) {
            zero[i - 1] = IMAG_ONE.multiply(C / FastMath.cos(theta[i]));
        }
    } else {
        zero = new Complex[n];
        for (int i = 0; i < n; i++) {
            zero[i] = IMAG_ONE.multiply(C / FastMath.cos(theta[i]));
        }
    }
    pole = new Complex[n];
    for (int i = 0; i < n; i++) {
        pole[i] = new Complex(C / (FastMath.pow(alpha[i], 2) + FastMath.pow(beta[i], 2)))
                .multiply(new Complex(alpha[i], -beta[i]));
    }

    /*
    ## Compensate for amplitude at s=0
    ## Because of the vagaries of floating point computations, the
    ## prod(pole)/prod(zero) sometimes comes out as negative and
    ## with a small imaginary component even though analytically
    ## the gain will always be positive, hence the abs(real(...))
     */
    gain = FastMath.abs(OctaveBuildIn.prod(pole).divide(OctaveBuildIn.prod(zero)).getReal());
}

From source file:de.tuberlin.uebb.jbop.example.DSCompilerOnlyCompose.java

@Override
public void cosh(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    function[0] = FastMath.cosh(operand[0]);
    if (order > 0) {
        function[1] = FastMath.sinh(operand[0]);
        for (int i = 2; i <= order; ++i) {
            function[i] = function[i - 2];
        }//ww w . jav a2s  .c o m
    }

    // apply function composition
    compose(operand, function, result);

}

From source file:de.tuberlin.uebb.jbop.example.DSCompilerOnlyCompose.java

@Override
public void sinh(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    function[0] = FastMath.sinh(operand[0]);
    if (order > 0) {
        function[1] = FastMath.cosh(operand[0]);
        for (int i = 2; i <= order; ++i) {
            function[i] = function[i - 2];
        }//  w w  w.  j a v a 2  s .  c o m
    }

    // apply function composition
    compose(operand, function, result);

}

From source file:de.tuberlin.uebb.jbop.example.DSCompiler.java

@Override
@Optimizable/*  w w w.ja va2  s .  c o  m*/
@StrictLoops
public void cosh(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    function[0] = FastMath.cosh(operand[0]);
    if (order > 0) {
        function[1] = FastMath.sinh(operand[0]);
        for (int i = 2; i <= order; ++i) {
            function[i] = function[i - 2];
        }
    }

    // apply function composition
    compose(operand, function, result);

}

From source file:de.tuberlin.uebb.jbop.example.DSCompiler.java

@Override
@Optimizable//from   www . j a  v  a  2  s.  co m
@StrictLoops
public void sinh(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    function[0] = FastMath.sinh(operand[0]);
    if (order > 0) {
        function[1] = FastMath.cosh(operand[0]);
        for (int i = 2; i <= order; ++i) {
            function[i] = function[i - 2];
        }
    }

    // apply function composition
    compose(operand, function, result);

}

From source file:org.apache.sysml.runtime.codegen.LibSpoofPrimitives.java

public static void vectCoshAdd(double[] a, double[] c, int ai, int ci, int len) {
    for (int j = ai; j < ai + len; j++, ci++)
        c[ci] += FastMath.cosh(a[j]);
}

From source file:org.apache.sysml.runtime.codegen.LibSpoofPrimitives.java

public static void vectCoshAdd(double[] a, double[] c, int[] aix, int ai, int ci, int alen, int len) {
    for (int j = ai; j < ai + alen; j++)
        c[ci + aix[j]] += FastMath.cosh(a[j]);
}

From source file:org.apache.sysml.runtime.codegen.LibSpoofPrimitives.java

public static double[] vectCoshWrite(double[] a, int ai, int len) {
    double[] c = allocVector(len, false);
    for (int j = 0; j < len; j++, ai++)
        c[j] = FastMath.cosh(a[ai]);
    return c;/*from www  . ja v  a2s .co  m*/
}