.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_scipy_auto_examples_solutions_plot_periodicity_finder.py: ========================== Crude periodicity finding ========================== Discover the periods in evolution of animal populations (:download:`../../../../data/populations.txt`) Load the data ########################################################### .. code-block:: python import numpy as np data = np.loadtxt('../../../../data/populations.txt') years = data[:, 0] populations = data[:, 1:] Plot the data ########################################################### .. code-block:: python import matplotlib.pyplot as plt plt.figure() plt.plot(years, populations * 1e-3) plt.xlabel('Year') plt.ylabel('Population number ($\cdot10^3$)') plt.legend(['hare', 'lynx', 'carrot'], loc=1) .. image:: /intro/scipy/auto_examples/solutions/images/sphx_glr_plot_periodicity_finder_001.png :class: sphx-glr-single-img Plot its periods ########################################################### .. code-block:: python from scipy import fftpack ft_populations = fftpack.fft(populations, axis=0) frequencies = fftpack.fftfreq(populations.shape[0], years[1] - years[0]) periods = 1 / frequencies plt.figure() plt.plot(periods, abs(ft_populations) * 1e-3, 'o') plt.xlim(0, 22) plt.xlabel('Period') plt.ylabel('Power ($\cdot10^3$)') plt.show() .. image:: /intro/scipy/auto_examples/solutions/images/sphx_glr_plot_periodicity_finder_002.png :class: sphx-glr-single-img There's probably a period of around 10 years (obvious from the plot), but for this crude a method, there's not enough data to say much more. **Total running time of the script:** ( 0 minutes 0.027 seconds) .. _sphx_glr_download_intro_scipy_auto_examples_solutions_plot_periodicity_finder.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_periodicity_finder.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_periodicity_finder.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_