Skip to content

Instantly share code, notes, and snippets.

@standy66
Created July 13, 2017 09:12
Show Gist options
  • Save standy66/e175e69f8af9e9acaafb11f45776bd76 to your computer and use it in GitHub Desktop.
Save standy66/e175e69f8af9e9acaafb11f45776bd76 to your computer and use it in GitHub Desktop.
Python sawtooth wave generator
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import Audio
from scipy.signal import spectrogram
sample_rate = 8000
t = np.arange(0, 10, 1.0/sample_rate)
x = t % (2 / sample_rate)
plt.figure(figsize=(16, 6), dpi=200)
plt.plot(t, x)
plt.xlim(0, 0.1)
Audio(data=x, rate=sample_rate)
fs, ts, Sxx = spectrogram(x / x.max(), sample_rate)
plt.figure(figsize=(15, 6))
plt.pcolor(ts, fs, np.log(1e-9 + Sxx))
plt.show()
plt.figure(figsize=(16, 6), dpi=200)
plt.plot(fs, Sxx[-1])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment