Here you can find the source of shift(double[] x, int N)
public static double[] shift(double[] x, int N)
//package com.java2s; /**/*from w ww. j av a 2 s . co 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[] shift(double[] x, int N) { if (N == 0) return x; double[] y = new double[x.length]; int i; if (N > 0) { for (i = 0; i < N; i++) y[i] = x[0]; for (i = N; i < x.length - N; i++) y[i] = x[i - N]; } else { N = -1 * N; for (i = 0; i < x.length - N; i++) y[i] = x[i + N]; for (i = x.length - N; i < x.length; i++) y[i] = x[x.length - 1]; } return y; } public static float[] shift(float[] x, int N) { if (N == 0) return x; float[] y = new float[x.length]; int i; if (N > 0) // Shift right { for (i = 0; i < N; i++) y[i] = x[0]; for (i = N; i < x.length; i++) y[i] = x[i - N]; } else // Shift left { N = -1 * N; for (i = 0; i < x.length - N; i++) y[i] = x[i + N]; for (i = x.length - N; i < x.length; i++) y[i] = x[x.length - 1]; } return y; } }