Skip to content

docstrings of cross-correlation functions (acorr and xcorr) need clarification #1835

Closed

Description

@pierre-haessig

1) lags interpretation

Coming from a discussion on numpy mailing-list [1] I noticed an ambiguity in the interpretation of the sign of the lags in plt.xcorr cross-correlation function. In R's acf/ccf documentation [2] there is the following notice :

The lag k value returned by ccf(x, y) estimates the correlation between x[t+k] and y[t].

I think that xcorr uses the same convention (like Matlab [3]) so we should put some similar notice. (note that this does not seem to be a universal definition. On Wikipedia cross-correlation page, the definition mentions x[t] * y[t+k] instead)

2) normed argument

In addition, the definition of the normed argument seems weird:

If normed = True, normalize the data by the cross correlation at 0-th lag

I think this is not what is computed [4]:

if normed:
    c /= np.sqrt(np.dot(x, x) * np.dot(y, y))

Maybe the acorr definition of normalization also needs so fine tuning because it's somehow recursive.

[1] http://mail.scipy.org/pipermail/numpy-discussion/2013-March/065839.html
[2] http://stat.ethz.ch/R-manual/R-patched/library/stats/html/acf.html
[3] http://www.mathworks.fr/fr/help/signal/ref/xcorr.html
[4] https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes.py#L4508

Activity

  1. added this to the milestone on Aug 17, 2014
  2. tacaswell commented on Aug 17, 2014

    @tacaswell
    Member

    @pierre-haessig I know this is old, but want to take a crack at updating the docstrings?

  3. added
    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    on May 31, 2016
  4. story645 commented on May 31, 2016

    @story645
    Member

    Note, these are the current docs: xcorr, acorr

  5. added 2 commits that reference this issue on Nov 20, 2016
  6. dstansby commented on Jan 2, 2017

    @dstansby
    Member

    Fixed by my PR (I think), but I forgot to put "fixes" in the description, could someone manually close this?

  7. modified the milestones: , on Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesDocumentation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions