Note
Go to the end to download the full example code.
Generate texture stimuli#
This shows how to generate texture coherence stimuli.
import matplotlib.pyplot as plt
import numpy as np
from expyfun.stimuli import play_sound, texture_ERB
fs = 24414
n_freqs = 20
n_coh = 18 # very coherent example
# let's make a textured stimilus and play it
sig = texture_ERB(n_freqs, n_coh, fs=fs, seq=("inc", "nb", "sam"))
play_sound(sig, fs, norm=True, wait=True)
This stim will have successive tones separated by 1.45 ERBs
Let’s look at the time course
And now the spectrogram:
fig, ax = plt.subplots(1, figsize=(8, 2))
img = ax.specgram(sig, NFFT=1024, Fs=fs, noverlap=800)[3]
img.set_clim([img.get_clim()[1] - 50, img.get_clim()[1]])
ax.set(xlim=t[[0, -1]], ylim=[0, 10000], xlabel="Time (sec)", ylabel="Freq (Hz)")
fig.tight_layout()
And the long-term spectrum:
Total running time of the script: (0 minutes 3.746 seconds)