.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/1_basic/plot_circadian_spectrogram.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__auto_examples_1_basic_plot_circadian_spectrogram.py: Circadian soundscape ==================== When dealing with large amounts of audio recordings, visualization plays a key role to evidence the main patterns in the data. In this example we show how to easily combine 96 audio files to build a visual representation of a 24 hour natural soundscape. .. GENERATED FROM PYTHON SOURCE LINES 14-15 Load packages and set variables. .. GENERATED FROM PYTHON SOURCE LINES 15-22 .. code-block:: Python import glob import matplotlib.pyplot as plt from maad import sound, util fpath = '../../data/indices/' # location of audio files sample_len = 3 # length in seconds of each audio slice .. GENERATED FROM PYTHON SOURCE LINES 23-24 Build a long list of audio slices of length `sample_len`. .. GENERATED FROM PYTHON SOURCE LINES 24-32 .. code-block:: Python flist = glob.glob(fpath+'*.wav') flist.sort() long_wav = list() for idx, fname in enumerate(flist): s, fs = sound.load(fname) s = sound.trim(s, fs, 0, sample_len) long_wav.append(s) .. GENERATED FROM PYTHON SOURCE LINES 33-35 Combine all audio recordings applying a crossfade and compute the spectrogram of the resulting mixed audio. .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python long_wav = util.crossfade_list(long_wav, fs, fade_len=0.5) Sxx, tn, fn, ext = sound.spectrogram(long_wav, fs, window='hann', nperseg=1024, noverlap=512) .. GENERATED FROM PYTHON SOURCE LINES 40-42 Display the spectrogram. We can see clearly the bird chorus at dawn (5-10 h) and dusk (20-21 h), as well as the wind and airplanes sounds at low frequencies. .. GENERATED FROM PYTHON SOURCE LINES 42-46 .. code-block:: Python fig, ax = plt.subplots(1,1, figsize=(10,3)) util.plot_spectrogram(Sxx, extent=[0, 24, 0, 11], ax=ax, db_range=80, gain=25, colorbar=False) ax.set_xlabel('Time [Hours]') ax.set_xticks(range(0,25,4)) .. image-sg:: /_auto_examples/1_basic/images/sphx_glr_plot_circadian_spectrogram_001.png :alt: plot circadian spectrogram :srcset: /_auto_examples/1_basic/images/sphx_glr_plot_circadian_spectrogram_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.109 seconds) .. _sphx_glr_download__auto_examples_1_basic_plot_circadian_spectrogram.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_circadian_spectrogram.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_circadian_spectrogram.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_