In [2]:
from matplotlib import pyplot as plt
%matplotlib inline
import numpy as np
from scipy.signal import spectrogram
import soundfile

Spectrogram of a single note


In [2]:
samples, sample_rate = soundfile.read(r'data\IDMT-SMT-GUITAR_V2\dataset1\Fender Strat Clean Neck SC\audio\G53-50110-1111-00011.wav')
print(samples.shape)
print(sample_rate)


(110250,)
44100

In [18]:
f, t, Sxx = spectrogram(samples[4410:16000], sample_rate)
print(f.shape)
print(t.shape)
print(Sxx.shape)
plt.figure(figsize=(10,10))
plt.pcolormesh(t, f, Sxx, cmap='binary')
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.ylim(ymax=4000)


(129,)
(51,)
(129, 51)
Out[18]:
(0.0, 4000)

In [10]:
for desc, file in [
    ('nofx', r'D:\Users\Michel\Documents\FH\module\8_IP6\input\IDMT-SMT-AUDIO-EFFECTS\Gitarre monophon\Samples\NoFX\G61-40100-1111-20593.wav'),
    ('distorted', r'D:\Users\Michel\Documents\FH\module\8_IP6\input\IDMT-SMT-AUDIO-EFFECTS\Gitarre monophon\Samples\Distortion\G61-40100-4413-38689.wav'),
]:
    samples, sample_rate = soundfile.read(file)
    print(desc)
    print(samples[:4410].max())
    print(samples[4410:8820].max())
    print(samples[8820:13230].max())
    print(samples[13230:17640].max())
    f, t, Sxx = spectrogram(samples[:22050], sample_rate)
    plt.figure(figsize=(8, 6))
    plt.pcolormesh(t, f, Sxx, cmap='binary')
    plt.title(desc)
    plt.ylabel('Frequency [Hz]')
    plt.xlabel('Time [sec]')
    plt.ylim(ymax=2000)


nofx
0.0
3.0517578125e-05
0.000244140625
0.000152587890625
distorted
0.00100708007813
0.0018310546875
0.00930786132813
0.00711059570313