.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_3_1_2_spectrum.py: ================================== Energy Spectrum of an Audio Signal ================================== Figure 3.3 from the tutorial. .. image:: /auto_examples/images/sphx_glr_plot_3_1_2_spectrum_001.png :class: sphx-glr-single-img .. code-block:: default from os.path import dirname, abspath, join from scipy.io import loadmat import numpy as np import matplotlib.pyplot as plt DATA_PATH = join(abspath(dirname("__file__")), "data", "gabor.mat") signal = loadmat(DATA_PATH)['gabor'].ravel() time = np.arange(338) dsp = np.fft.fftshift(np.abs(np.fft.fft(signal)) ** 2) freq = np.arange(-169, 169, dtype=float) / 338 * 1000 plt.subplot(211) plt.plot(time, signal) plt.grid(True) plt.xlim(0, time.max()) plt.xlabel('Time (ms)') plt.subplot(212) plt.plot(dsp) plt.grid(True) plt.title('Spectrum') plt.xlabel('Frequency (Hz)') plt.subplots_adjust(hspace=0.5) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.227 seconds) .. _sphx_glr_download_auto_examples_plot_3_1_2_spectrum.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_3_1_2_spectrum.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_3_1_2_spectrum.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_