View deep-pitchs-errors-by-key.py
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
files = os.listdir("samples") | |
np.random.shuffle(files) | |
notes = ['A', 'As', 'B', 'C', 'Cs', 'D', 'Ds', 'E', 'F', 'Fs', 'G', 'Gs'] | |
note_map = {} | |
for i, note_name in enumerate(notes): | |
note_map[note_name] = i | |
count_by_key = np.zeros((8 * 12)) | |
errors_by_key = np.zeros((8 * 12)) |
View sine-wave.py
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 | |
# Generate Sine wave | |
hz = 20 | |
x = np.arange(0, 1, 0.001) # 1 second | |
y = np.sin(2 * np.pi * hz * x) | |
plt.figure(figsize=(10, 3)) | |
plt.plot(x, y) | |
plt.show() |
View sine-wave-fft.py
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
# Generate an integer-period sine wave to | |
# eliminate spectral leak. | |
hz = 20 | |
x = np.linspace(0, 2 * np.pi * hz, 128 * hz) | |
y = np.sin(x) | |
plt.figure(figsize=(10, 3)) | |
plt.plot(x, y) | |
plt.show() | |
# We're only interested in the real components |
View impulse-signal.py
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
points = 256 | |
y = np.zeros(points, dtype="complex64") | |
y[20] = np.complex(1,0) # stick a 1 into the 20th position | |
plt.figure(figsize=(10, 3)) | |
plt.bar(np.arange(100), np.absolute(y)[:100]) # Show the first 100 points | |
plt.show() |
View impulse-fft.py
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
points = 256 | |
y = np.zeros(points, dtype="complex64") | |
y[20] = np.complex(1,0) | |
ifft_y = fft.irfft(y) * points | |
plt.figure(figsize=(10, 3)) | |
plt.plot(ifft_y) | |
plt.show() |
View impulse-fft-inverse.py
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
x = np.linspace(0, 2 * np.pi * hz, points * hz) | |
y = np.sin(x) | |
plt.figure(figsize=(10, 3)) | |
plt.bar(np.arange(75), y[:75 * 10:10]) # sample every 10th element for bar graph | |
plt.show() | |
fft_y = fft.ifft(y.astype("complex64")) * 2 | |
plt.figure(figsize=(10, 3)) | |
plt.bar(np.arange(100), np.absolute(fft_y[:100])) | |
plt.show() |
View spectrogram.py
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 scipy import signal | |
def spectrogram(xs): | |
return signal.spectrogram(xs, 256, window=('hann'), nperseg=256, nfft=256, noverlap=200, mode='complex') |
View spectrogram_build_training_data.py
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
def build_training_data(batch_size, sample_size): | |
xs = np.random.randn(batch_size, sample_size) | |
f, t, ys = spectrogram(xs) | |
(num_rows, num_cols) = (ys.shape[1], ys.shape[2]) | |
print(ys.shape) | |
ys = ys.reshape(batch_size, num_rows * num_cols) | |
Ys = np.hstack([ys.real, ys.imag]) | |
return (xs, Ys, num_rows, num_cols) |
View spectrogram_keras_model.py
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 tensorflow as tf | |
size = 2048 | |
N = 15000 | |
(xs, ys, rows, cols) = build_training_data(N, size) | |
model = tf.keras.models.Sequential([ | |
tf.keras.layers.Dense(rows * cols * 2, input_dim=size, use_bias=False) | |
]) |
View spectrogram_scipy_vs_nn.py
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
def make_wave(): | |
# Create four evenly-spaced tones | |
waves = [] | |
hz = 0 | |
for i in range(0, size, 512): | |
hz = hz + 50 | |
waves.append(np.sin(np.linspace(0, 2 * np.pi * hz, 512))) | |
return np.hstack(waves) | |
wave = make_wave() |