.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/gap.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_gap.py: Generate stimuli with gaps ========================== This demonstrates how to generate various stimuli with gaps (e.g., for measuring temporal processing). .. GENERATED FROM PYTHON SOURCE LINES 8-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from psiaudio import calibration from psiaudio import stim from psiaudio import util # Creating calibration # -------------------- # This ensures that the resulting waveform is in units of Pascals. flat_cal = calibration.FlatCalibration.from_spl(94) fs = 100e3 .. GENERATED FROM PYTHON SOURCE LINES 23-26 Gap detection based on tone pips -------------------------------- Commonly used in human studies. .. GENERATED FROM PYTHON SOURCE LINES 26-49 .. code-block:: Python waveform = stim.gap( fs=fs, fc=4e3, octaves=0, gap=2e-3, durations=[4e-3, 4e-3], rise_time=2e-3, level=80, calibration=flat_cal, ) t = np.arange(len(waveform)) / fs figure, axes = plt.subplots(1, 2, figsize=(8, 4), constrained_layout=True) axes[0].plot(t, waveform) axes[0].set_xlabel('Time (s)') axes[1].set_xlabel('Amplitude (Pa)') axes[1].specgram(waveform, Fs=fs); axes[1].axis(ymin=200, ymax=20e3) axes[1].set_yscale('octave', octaves=2) axes[0].set_xlabel('Time (s)') axes[1].set_xlabel('Frequency (kHz)') plt.show() .. image-sg:: /gallery/images/sphx_glr_gap_001.png :alt: gap :srcset: /gallery/images/sphx_glr_gap_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-53 Gap detection based on bandlimited noise ---------------------------------------- Commonly used in animal studies. .. GENERATED FROM PYTHON SOURCE LINES 53-76 .. code-block:: Python waveform = stim.gap( fs=fs, fc=4e3, octaves=0.5, gap=8e-3, durations=[500e-3, 500e-3], rise_time=2e-3, level=80, calibration=flat_cal, ) t = np.arange(len(waveform)) / fs figure, axes = plt.subplots(1, 2, figsize=(8, 4), constrained_layout=True) axes[0].plot(t, waveform) axes[0].set_xlabel('Time (s)') axes[1].set_xlabel('Amplitude (Pa)') axes[1].specgram(waveform, Fs=fs); axes[1].axis(ymin=200, ymax=20e3) axes[1].set_yscale('octave', octaves=2) axes[0].set_xlabel('Time (s)') axes[1].set_xlabel('Frequency (kHz)') plt.show() .. image-sg:: /gallery/images/sphx_glr_gap_002.png :alt: gap :srcset: /gallery/images/sphx_glr_gap_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/hostedtoolcache/Python/3.13.13/x64/lib/python3.13/site-packages/matplotlib/axes/_axes.py:8283: RuntimeWarning: divide by zero encountered in log10 Z = 10. * np.log10(spec) .. GENERATED FROM PYTHON SOURCE LINES 77-81 Multiple gaps based on tone pips -------------------------------- Commonly used in animal studies to help train the animal before switching to a single gap. This embeds three gaps in the stimulus. .. GENERATED FROM PYTHON SOURCE LINES 81-103 .. code-block:: Python waveform = stim.gap( fs=fs, fc=4e3, octaves=0, gap=8e-3, durations=[32e-3, 32e-3, 32e-3, 32e-3], rise_time=2e-3, level=80, calibration=flat_cal, ) t = np.arange(len(waveform)) / fs figure, axes = plt.subplots(1, 2, figsize=(8, 4), constrained_layout=True) axes[0].plot(t, waveform) axes[0].set_xlabel('Time (s)') axes[1].set_xlabel('Amplitude (Pa)') axes[1].specgram(waveform, Fs=fs); axes[1].axis(ymin=200, ymax=20e3) axes[1].set_yscale('octave', octaves=2) axes[0].set_xlabel('Time (s)') axes[1].set_xlabel('Frequency (kHz)') plt.show() .. image-sg:: /gallery/images/sphx_glr_gap_003.png :alt: gap :srcset: /gallery/images/sphx_glr_gap_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.752 seconds) .. _sphx_glr_download_gallery_gap.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: gap.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: gap.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: gap.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_