.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/chirp.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_chirp.py: Generate bandlimited clicks =========================== This demonstrates how to generate a bandlimited click of uniform SPL when you have an acoustic system whose output varies with frequency (e.g., an EPL-style starship). .. GENERATED FROM PYTHON SOURCE LINES 9-82 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/images/sphx_glr_chirp_001.png :alt: chirp :srcset: /gallery/images/sphx_glr_chirp_001.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/images/sphx_glr_chirp_002.png :alt: chirp :srcset: /gallery/images/sphx_glr_chirp_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none 60 60.000001373108915 59.99999879873765 40 40.000001373108915 39.99999879873765 60 60.000000069524575 60.0000000399643 40 40.000000069524575 40.0000000399643 60 74.20659021281183 40 54.20659021281182 60 73.20998939490426 40 53.209989394904255 60 65.25340722275232 40 45.25340722275232 60 73.45654136827942 40 53.45654136827942 | .. code-block:: Python import matplotlib.pyplot as plt from psiaudio import calibration from psiaudio import stim from psiaudio import util figure, axes = plt.subplots(1, 2, figsize=(8, 4)) flat_cal = calibration.FlatCalibration.from_spl(80) fs = 96e3 window = 2.5e-3 for flb, fub in [(4e3, 32e3), (8e3, 16e3)]: for level in (60, 40): waveform = stim.chirp( fs=fs, start_frequency=flb, end_frequency=fub, duration=2e-3, level=level, calibration=flat_cal, window='hann', ) psd = util.psd_df(waveform, fs) spl = flat_cal.get_db(psd) rms_spl = flat_cal.get_db(1e3, util.rms(waveform)) psd_spl = util.rms_rfft_db(spl) axes[0].plot(waveform) p, = axes[1].plot(spl) sl = util.band_to_spectrum_level(level, (fub-flb) / 500) print(f'{level} {rms_spl} {psd_spl}') axes[1].axhline(sl, color=p.get_color(), ls=':') axes[1].axis(xmin=0.5e3, xmax=64e3, ymin=-10, ymax=50) axes[1].set_xscale('octave') st_cal = calibration.load_demo_starship() figure, axes = plt.subplots(1, 2, figsize=(8, 4)) for flb, fub in [(2e3, 8e3), (4e3, 32e3), (8e3, 16e3), (16e3, 32e3)]: for level in (60, 40): waveform = stim.chirp( fs=fs, start_frequency=flb, end_frequency=fub, duration=2e-3, level=level, calibration=st_cal, window='hann', ) psd = util.psd_df(waveform, fs) # DC frequency is not calibrated, so we exclude it. spl = st_cal.get_db(psd.iloc[1:]) rms_spl = st_cal.get_db(1e3, util.rms(waveform)) psd_spl = util.rms_rfft_db(spl) axes[0].plot(waveform) p, = axes[1].plot(spl) sl = util.band_to_spectrum_level(level, (fub-flb) / 500) print(f'{level} {psd_spl}') axes[1].axhline(sl, color=p.get_color(), ls=':') axes[1].axis(xmin=0.5e3, xmax=64e3, ymin=-10, ymax=70) axes[1].set_xscale('octave') plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.256 seconds) .. _sphx_glr_download_gallery_chirp.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: chirp.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: chirp.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: chirp.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_