Java Array Subtract subtractSignals(double[] s1, double[] s2)

Here you can find the source of subtractSignals(double[] s1, double[] s2)

Description

subtract Signals

License

Open Source License

Declaration

public static double[] subtractSignals(double[] s1, double[] s2) 

Method Source Code

//package com.java2s;
/**//from  w  ww. j  a  v  a 2s  .c  o  m
 * Copyright 2000-2009 DFKI GmbH.
 * All Rights Reserved.  Use is subject to license terms.
 *
 * This file is part of MARY TTS.
 *
 * MARY TTS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    public static double[] subtractSignals(double[] s1, double[] s2) {
        return addSignals(s1, 1.0, s2, -1.0);
    }

    public static double[] addSignals(double[] s1, double[] s2) {
        int len = 0;
        if (s1 != null)
            len = s1.length;
        if (s2 != null && s2.length > len)
            len = s2.length;

        double[] y = null;
        if (len > 0)
            y = new double[len];

        if (s1 != null)
            System.arraycopy(s1, 0, y, 0, s1.length);

        if (s2 != null) {
            for (int i = 0; i < s2.length; i++)
                y[i] += s2[i];
        }

        return y;
    }

    public static double[] addSignals(double[] s1, double gain1, double[] s2, double gain2) {
        int len = 0;
        if (s1 != null)
            len = s1.length;
        if (s2 != null && s2.length > len)
            len = s2.length;

        double[] y = null;
        if (len > 0)
            y = new double[len];

        if (s1 != null)
            System.arraycopy(s1, 0, y, 0, s1.length);

        if (s2 != null) {
            for (int i = 0; i < s2.length; i++)
                y[i] = gain1 * y[i] + gain2 * s2[i];
        } else if (s1 != null) {
            for (int i = 0; i < s1.length; i++)
                y[i] = gain1 * y[i];
        }

        return y;
    }
}

Related

  1. subtractInPlace(double[] first, double[] second)
  2. subtractInPlace(final double[] a, final double[] b)
  3. subtractKeepPositiveValues(float[] dividend, float divisor)
  4. subtractMin(Double[] array)
  5. subtractRange(double[] accumulator, int offset, double[] values)
  6. subtractTo(double a[][][], double b[][][])
  7. subtractUnitsArray(int[] units1, int[] units2)
  8. SubtractVec2D(double[] vec2Ret, double[] vec2A, double[] vec2B)
  9. SubtractVec3D(double[] vec3Ret, double[] vec3A, double[] vec3B)