.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/tone-pips.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_tone-pips.py: Simple tone pips ================ Demonstration of how to generate a simple tone pip. .. GENERATED FROM PYTHON SOURCE LINES 7-12 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from psiaudio import calibration, stim, util .. GENERATED FROM PYTHON SOURCE LINES 13-15 Since 1 Pascal is 94 dB SPL, this calibration results in the stimulus waveform being scaled such that 1 Vrms = 1 Pascal. .. GENERATED FROM PYTHON SOURCE LINES 15-18 .. code-block:: Python cal = calibration.FlatCalibration.from_spl(94) fs = 100e3 .. GENERATED FROM PYTHON SOURCE LINES 19-22 Stimulus levels are always specified in RMS power, not peak-equivalent power. This means that you will see the peak-to-peak tone amplitude run from -1.4 to 1.4 (resulting in a RMS value of 1). .. GENERATED FROM PYTHON SOURCE LINES 22-31 .. code-block:: Python tone1 = stim.ramped_tone( fs=fs, duration=5e-3, rise_time=0.5e-3, frequency=2e3, level=94, calibration=cal, ) .. GENERATED FROM PYTHON SOURCE LINES 32-34 The default value for `rise_time` is None, which indicates that there's no plateau (i.e., steady state) period. .. GENERATED FROM PYTHON SOURCE LINES 34-58 .. code-block:: Python tone2 = stim.ramped_tone( fs=fs, duration=5e-3, frequency=2e3, level=94, calibration=cal, ) t = np.arange(len(tone1)) / fs * 1e3 psd1 = util.patodb(util.psd_df(tone1, fs)) psd2 = util.patodb(util.psd_df(tone2, fs)) figure, axes = plt.subplots(1, 2, figsize=(8, 4)) axes[0].plot(t, tone1, label='0.5 msec rise/fall') axes[0].plot(t, tone2, label='2.5 msec rise/fall') axes[0].set_xlabel('Time (msec)') axes[0].set_ylabel('Amplitude (Pascals)') axes[1].semilogx(psd1, label='0.5 msec rise/fall') axes[1].semilogx(psd2, label='2.5 msec rise/fall') axes[1].axhline(94, ls=':') .. image-sg:: /gallery/images/sphx_glr_tone-pips_001.png :alt: tone pips :srcset: /gallery/images/sphx_glr_tone-pips_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 59-61 Format the axes. Note the use of psiaudio's custom scale to show ticks on an octave scale. .. GENERATED FROM PYTHON SOURCE LINES 61-70 .. code-block:: Python axes[1].set_xscale('octave') axes[1].axis(xmin=250, xmax=16e3, ymin=0, ymax=100) axes[1].set_xlabel('Frequency (kHz)') axes[1].set_ylabel('Amplitude (dB SPL)') axes[1].legend() figure.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.217 seconds) .. _sphx_glr_download_gallery_tone-pips.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tone-pips.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tone-pips.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: tone-pips.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_