summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2009-06-02 10:30:49 +0000
committerDavid Cournapeau <cournape@gmail.com>2009-06-02 10:30:49 +0000
commit42f4f816a23d430c6d3f471416ef7f7308159d7a (patch)
treec218933ad70e86debbddf94d12086d2da1c729cd /numpy/core/numeric.py
parente3d65f0e5ad0323894d5171ed2ec7b45e6280d18 (diff)
downloadnumpy-42f4f816a23d430c6d3f471416ef7f7308159d7a.tar.gz
Add PyArray_Acorrelate function
PyArray_Correlate function did not compute the usual definition for correlation: it assumed correlate(a, b) == correlate(b, a), and did not use conjugate for the 2nd argument. As some people may rely on the current behavior, we add a PyArray_Acorrelate function and acorrelate python function to implement the usual definition. Squashed commit of the following: commit 1e1e0ff38968934825ad64cddd36fcb21e378954 Author: David Cournapeau <cournape@gmail.com> Date: Tue Jun 2 18:59:57 2009 +0900 Refactor [A]Correlate, so that they share most of the implementation. commit ffbd54ecf539df508363a725ec5f7529f71a9bb4 Author: David Cournapeau <cournape@gmail.com> Date: Tue Jun 2 18:35:21 2009 +0900 Handle conjugate in correlate. commit df47fddd8e5142758504dece39b0716b8f46434f Author: David Cournapeau <cournape@gmail.com> Date: Tue Jun 2 17:42:38 2009 +0900 Correlate and correlate tests better shared. commit f48de4450b05260e9174cf224302a1c8a1f60331 Author: David Cournapeau <cournape@gmail.com> Date: Tue Jun 2 17:39:15 2009 +0900 Add acorrelate function at the python level. commit a37cc7ff144b0e6b64f8fd0a8cae4c9e561f4a1c Author: David Cournapeau <cournape@gmail.com> Date: Tue Jun 2 17:21:20 2009 +0900 Update test for correlate - we will test for inverted output for acorrelate. commit 4140a30f1b6daf95ce2fa8fa7bd26f827b2fcfd1 Author: David Cournapeau <cournape@gmail.com> Date: Tue Jun 2 17:19:14 2009 +0900 Add PyArray_Acorrelate function in the C API. commit 082f9d4b0205a9a4f0112d8cfd3852b3907b6e09 Author: David Cournapeau <cournape@gmail.com> Date: Mon Jun 1 12:04:12 2009 +0900 Add simple test for correlate. commit 7179187953d7cb396a7557a418e6fbcaeddc4211 Author: David Cournapeau <cournape@gmail.com> Date: Mon Jun 1 11:57:46 2009 +0900 Invert output array if we swapped input arrays.
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py39
1 files changed, 37 insertions, 2 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 26ef27dc9..50e3fd75b 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -6,7 +6,7 @@ __all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc',
'set_numeric_ops', 'can_cast',
'asarray', 'asanyarray', 'ascontiguousarray', 'asfortranarray',
'isfortran', 'empty_like', 'zeros_like',
- 'correlate', 'convolve', 'inner', 'dot', 'outer', 'vdot',
+ 'correlate', 'acorrelate', 'convolve', 'inner', 'dot', 'outer', 'vdot',
'alterdot', 'restoredot', 'roll', 'rollaxis', 'cross', 'tensordot',
'array2string', 'get_printoptions', 'set_printoptions',
'array_repr', 'array_str', 'set_string_function',
@@ -579,11 +579,46 @@ def correlate(a,v,mode='valid'):
--------
convolve : Discrete, linear convolution of two
one-dimensional sequences.
-
+ acorrelate: Discrete correlation following the usual signal processing
+ definition for complex arrays, and without assuming that
+ correlate(a, b) == correlate(b, a)
"""
mode = _mode_from_name(mode)
return multiarray.correlate(a,v,mode)
+def acorrelate(a, v, mode='valid'):
+ """
+ Discrete, linear correlation of two 1-dimensional sequences.
+
+ This function computes the correlation as generally defined in signal
+ processing texts:
+
+ z[k] = sum_n a[n] * conj(v[n+k])
+
+ with a and v sequences being zero-padded where necessary and conj being the
+ conjugate.
+
+ Parameters
+ ----------
+ a, v : array_like
+ Input sequences.
+ mode : {'valid', 'same', 'full'}, optional
+ Refer to the `convolve` docstring. Note that the default
+ is `valid`, unlike `convolve`, which uses `full`.
+
+ Note
+ ----
+ This is the function which corresponds to matlab xcorr.
+
+ See Also
+ --------
+ convolve : Discrete, linear convolution of two
+ one-dimensional sequences.
+ correlate: Deprecated function to compute correlation
+ """
+ mode = _mode_from_name(mode)
+ return multiarray.acorrelate(a, v, mode)
+
def convolve(a,v,mode='full'):
"""