Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9EB3110FB4 for ; Wed, 5 Jun 2013 11:43:07 +0000 (UTC) Received: (qmail 66313 invoked by uid 500); 5 Jun 2013 11:43:06 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 65574 invoked by uid 500); 5 Jun 2013 11:43:05 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 65544 invoked by uid 99); 5 Jun 2013 11:43:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Jun 2013 11:43:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Jun 2013 11:42:57 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E33C923889F1; Wed, 5 Jun 2013 11:42:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1489821 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java Date: Wed, 05 Jun 2013 11:42:36 -0000 To: commits@commons.apache.org From: erans@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130605114236.E33C923889F1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: erans Date: Wed Jun 5 11:42:36 2013 New Revision: 1489821 URL: http://svn.apache.org/r1489821 Log: Javadoc. Variable names. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java?rev=1489821&r1=1489820&r2=1489821&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java Wed Jun 5 11:42:36 2013 @@ -1354,45 +1354,50 @@ public class MathArrays { } /** - * Calculates the convolution between two sequences. - *

- * The solution is obtained via straightforward computation of the convolution sum (and not via FFT; - * for longer sequences, the performance of this method might be inferior to an FFT-based implementation). + * Calculates the + * convolution between two sequences. + * The solution is obtained via straightforward computation of the + * convolution sum (and not via FFT). + * Whenever the computation needs an element that would be located + * at an index outside the input arrays, the value is assumed to be + * zero. * - * @param x the first sequence (double array of length {@code N}); - * the sequence is assumed to be zero elsewhere (i.e. {x[i]}=0 for i<0 and i>={@code N}). - * Typically, this sequence will represent an input signal to a system. - * @param h the second sequence (double array of length {@code M}); - * the sequence is assumed to be zero elsewhere (i.e. {h[i]}=0 for i<0 and i>={@code M}). - * Typically, this sequence will represent the impulse response of the system. - * @return the convolution of {@code x} and {@code h} (double array of length {@code N} + {@code M} -1) - * @throws NullArgumentException if either {@code x} or {@code h} is null - * @throws NoDataException if either {@code x} or {@code h} is empty + * @param x First sequence. + * Typically, this sequence will represent an input signal to a system. + * @param h Second sequence. + * Typically, this sequence will represent the impulse response of the + * system. + * @return the convolution of {@code x} and {@code h}. + * This array's length will be {@code x.length + h.length - 1}. + * @throws NullArgumentException if either {@code x} or {@code h} is + * {@code null}. + * @throws NoDataException if either {@code x} or {@code h} is empty. * - * @see Convolution (Wikipedia) * @since 3.3 */ - public static double[] convolve(double[] x, double[] h) throws NullArgumentException, NoDataException { + public static double[] convolve(double[] x, double[] h) + throws NullArgumentException, + NoDataException { MathUtils.checkNotNull(x); MathUtils.checkNotNull(h); - final int lenX = x.length; - final int lenH = h.length; + final int xLen = x.length; + final int hLen = h.length; - if (lenX == 0 || lenH == 0) { + if (xLen == 0 || hLen == 0) { throw new NoDataException(); } // initialize the output array - final int totalLength = lenX + lenH - 1; + final int totalLength = xLen + hLen - 1; final double[] y = new double[totalLength]; // straightforward implementation of the convolution sum for (int n = 0; n < totalLength; n++) { double yn = 0; - int k = FastMath.max(0, n + 1 - lenX); + int k = FastMath.max(0, n + 1 - xLen); int j = n - k; - while (k < lenH && j >= 0) { + while (k < hLen && j >= 0) { yn += x[j--] * h[k++]; } y[n] = yn; @@ -1400,5 +1405,4 @@ public class MathArrays { return y; } - }