Shepard Tones¶
In [1]:
import numpy as np
import matplotlib.pyplot as plt
import IPython.display as ipd
import librosa
In [2]:
sr = 44100
base_freq = 30
t = np.arange(sr*20)/sr
octave_rate = 0.2 # Number of cycles of Shepard tone per second
y = np.zeros(t.size)
n_octaves = 9
for i in range(n_octaves):
## Define instantaneous frequency trajectory
octave = (i + t*octave_rate) % n_octaves
df = base_freq*(2**octave)
## Integrate instantaneous frequency
f = np.cumsum(df)/sr
## Accumulate this tone
denom = 1+np.abs(octave - n_octaves/2)
y += np.cos(2*np.pi*f)/denom**2
ipd.Audio(y, rate=sr)
Out[2]:
In [3]:
S = librosa.stft(y)
S_db = librosa.amplitude_to_db(np.abs(S), ref=np.max)
librosa.display.specshow(S_db, x_axis='time', y_axis='linear', sr=sr)
plt.colorbar()
Out[3]:
<matplotlib.colorbar.Colorbar at 0x7e9cd4243e90>
In [4]:
S = librosa.stft(y)
S_db = librosa.amplitude_to_db(np.abs(S), ref=np.max)
librosa.display.specshow(S_db, x_axis='time', y_axis='log', sr=sr)
plt.colorbar()
Out[4]:
<matplotlib.colorbar.Colorbar at 0x7e9cd41390d0>
In [ ]: