.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/beats_onsets/plot_tempogram.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_beats_onsets_plot_tempogram.py: Tempogram ========= Local tempo over time. A signal that changes speed shows up as a step. .. GENERATED FROM PYTHON SOURCE LINES 7-14 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import audio_samples as aus from audio_samples import effects .. GENERATED FROM PYTHON SOURCE LINES 15-16 Ten seconds at 90 BPM followed by ten at 150 BPM. .. GENERATED FROM PYTHON SOURCE LINES 16-21 .. code-block:: Python sr = 22050 times = np.concatenate([np.arange(0.0, 10.0, 60 / 90), np.arange(10.0, 20.0, 60 / 150)]) y = effects.clicks(times=times, sr=sr, length=20 * sr) audio = aus.AudioSamples.new_mono(y.astype(np.float32), sr) .. GENERATED FROM PYTHON SOURCE LINES 22-23 ``tempogram`` returns ``(channels, lags, frames)``; lag 0 is excluded from the plot. .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. code-block:: Python gram = audio.tempogram()[0] fig, ax = plt.subplots(figsize=(7, 3.5)) ax.imshow(gram[1:], origin="lower", aspect="auto", extent=[0, 20, 1, gram.shape[0]]) ax.set(xlabel="Time (s)", ylabel="Lag (frames)", ylim=(1, 120), title="Autocorrelation tempogram") .. image-sg:: /gallery/beats_onsets/images/sphx_glr_plot_tempogram_001.png :alt: Autocorrelation tempogram :srcset: /gallery/beats_onsets/images/sphx_glr_plot_tempogram_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [Text(0.5, 9.333333333333327, 'Time (s)'), Text(45.222222222222214, 0.5, 'Lag (frames)'), (1.0, 120.0), Text(0.5, 1.0, 'Autocorrelation tempogram')] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.309 seconds) .. _sphx_glr_download_gallery_beats_onsets_plot_tempogram.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_tempogram.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_tempogram.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_tempogram.zip `