Mam w pythonie taki skrypt: import numpy as np import matplotlib.pyplot as plt from…
- User
Mam w pythonie taki skrypt: import numpy as np import matplotlib.pyplot as plt from scipy.signal import spectrogram, windows import soundfile as sf
Wczytaj plik sweep
x, fs = sf.read('swepout.wav')
Jeśli stereo, wybierz jeden kanał
if x.ndim > 1: x = x[:, 0]
Parametry spektrogramu
nperseg = 8192 noverlap = 6144
window = windows.hann(nperseg, sym=False) #window = windows.blackmanharris(nperseg, sym=False)
Oblicz spektrogram
f, t, Sxx = spectrogram(x, fs, window=window, nperseg=nperseg, noverlap=noverlap, scaling='spectrum', mode='magnitude')
Normalizacja i logarytm do dBFS
#Sxx_db = 20 * np.log10(Sxx / np.max(Sxx) + 1e-20) Sxx_db = 20 * np.log10(np.maximum(Sxx / np.max(Sxx), 1e-25))
Tworzenie wykresu
plt.figure(figsize=(12, 6)) pcm = plt.pcolormesh(t, f, Sxx_db, shading='gouraud', cmap='inferno', vmin=-250, vmax=0) plt.ylabel('Częstotliwość [Hz]') plt.xlabel('Czas [s]') plt.title('Spectrogram – Sweep (do -250 dBFS)') plt.colorbar(pcm, label='Amplituda [dBFS]') plt.ylim(0, fs / 2) plt.tight_layout()
Zapis do PNG
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.