在我看来,scipy.signal.spectrogram中计算出的幅度是不正确的(在我的情况下,降低了20%)。有可能对此进行改进吗?考虑这个例子
import matplotlib.pyplot as plt
import numpy as np
from numpy import pi as π
f_s = 200 # Sampling rate = number of measurements per second in [Hz]
t = np.arange(-10,10, 1 / f_s)
N = len(t)
T1 = np.tanh(t)/2 + 1.0 # Period in [s]
T2 = 0.125 # Period in [s]
f1 = 1 / T1 # Frequency in [Hz]
f2 = 1 / T2 # Frequency in [Hz]
# Signal
x = 13*np.sin(2 * π * f1 * t) + 42*np.sin(2 * π * f2 * t)
# Spectrogram with good time window
Δt = 4 # window length in [s]
Nw = np.int(2**np.round(np.log2(Δt * f_s)))
print(f"Effective window length is {Nw/f_s:.1f}s")
f, t_, Sxx = signal.spectrogram(x, f_s, window='hanning', nperseg=Nw, noverlap = Nw - 100, detrend=False, scaling='spectrum')
Δf = f[1] - f[0]
Δt_ = t_[1] - t_[0]
fig, ax = plt.subplots(figsize = (15,5))
im = ax.pcolormesh(t_ + t[0] - Δt_, f - Δf/2, np.sqrt(Sxx), cmap = "inferno_r")
plt.colorbar(im)
ax.grid(True)
ax.set_ylabel("Frequency in [Hz]")
ax.set_xlabel("t")
ax.set_ylim(0,10)
plt.show()
很明显,这些线没有显示其先前定义的幅度(分别为13和42)。