Created
July 13, 2017 09:12
-
-
Save standy66/e175e69f8af9e9acaafb11f45776bd76 to your computer and use it in GitHub Desktop.
Python sawtooth wave generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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