

.. _sphx_glr_gallery_pylab_examples_xcorr_demo.py:


==========
Xcorr Demo
==========





.. image:: /gallery/pylab_examples/images/sphx_glr_xcorr_demo_001.png
    :align: center





.. code-block:: python

    import matplotlib.pyplot as plt
    import numpy as np


    # Fixing random state for reproducibility
    np.random.seed(19680801)


    x, y = np.random.randn(2, 100)
    fig = plt.figure()
    ax1 = fig.add_subplot(211)
    ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
    ax1.grid(True)
    ax1.axhline(0, color='black', lw=2)

    ax2 = fig.add_subplot(212, sharex=ax1)
    ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
    ax2.grid(True)
    ax2.axhline(0, color='black', lw=2)

    plt.show()

**Total running time of the script:** ( 0 minutes  0.055 seconds)



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

     :download:`Download Python source code: xcorr_demo.py <xcorr_demo.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: xcorr_demo.ipynb <xcorr_demo.ipynb>`

.. rst-class:: sphx-glr-signature

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
