Here you can find the source of interpolate_linear(int[] x, double[] y, int[] xi)
public static double[] interpolate_linear(int[] x, double[] y, int[] xi)
//package com.java2s; /**// ww w . ja v a 2s . c o m * Copyright 2004-2006 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[] interpolate_linear(int[] x, double[] y, int[] xi) { assert (x.length == y.length); double[] yi = new double[xi.length]; int i, j; boolean bFound; double alpha; for (i = 0; i < xi.length; i++) { bFound = false; for (j = 0; j < x.length - 1; j++) { if (xi[i] >= x[j] && xi[i] < x[j + 1]) { bFound = true; break; } } if (bFound) { alpha = (((double) xi[i]) - x[j]) / (x[j + 1] - x[j]); yi[i] = (1 - alpha) * y[j] + alpha * y[j + 1]; } } if (xi[xi.length - 1] == x[x.length - 1]) yi[xi.length - 1] = y[x.length - 1]; return yi; } }