35 lines
715 B
Python
35 lines
715 B
Python
import soundbox
|
|
import numpy as np
|
|
import scipy.signal as sig
|
|
import matplotlib
|
|
import matplotlib.pyplot as plt
|
|
|
|
signal = soundbox.load_signal('out.wav')
|
|
|
|
freq, time, fts = sig.stft(signal, soundbox.samp_rate, nperseg=soundbox.samp_rate * 0.5)
|
|
|
|
fig, ax = plt.subplots()
|
|
ax.pcolormesh(
|
|
time, freq,
|
|
np.abs(fts),
|
|
cmap='plasma',
|
|
shading='gouraud')
|
|
|
|
|
|
def freq_format(value, pos):
|
|
return f'{value:.0f} Hz'
|
|
|
|
|
|
def time_format(value, pos):
|
|
return f'{value:.0f} s'
|
|
|
|
|
|
ax.set_xlabel('Temps')
|
|
ax.xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(time_format))
|
|
|
|
ax.set_ylabel('Fréquence')
|
|
ax.set_ylim(0, 800)
|
|
ax.yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(freq_format))
|
|
|
|
plt.show()
|