scipy.signal.spectrogram 和 scipy.signal.stft 有什么区别?

What is the difference between scipy.signal.spectrogram and scipy.signal.stft?

函数
spicy.signal.spectrogram:https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html

spicy.signal.stft:https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.stft.html
似乎做的事情非常相似。

这两个函数有什么区别?

Tl;dr:如果我用 SciPy 文档给出的输出编写它:Sxx = Zxx ** 2

说明: 频谱图和短时傅里叶变换是两个不同的对象,但它们非常接近。

The short-time Fourier transform (STFT), is a Fourier-related transform used to determine the sinusoidal frequency and phase content of local sections of a signal as it changes over time. In practice, the procedure for computing STFTs is to divide a longer time signal into shorter segments of equal length and then compute the Fourier transform separately on each shorter segment. This reveals the Fourier spectrum on each shorter segment. One then usually plots the changing spectra as a function of time. Wikipedia

另一方面,

A spectrogram is a visual representation of the spectrum of frequencies of a signal as it varies with time. Wikipedia

频谱图基本上将您的信号切割成很小的部分 windows,并显示一系列颜色来表示这个或那个特定频率的强度。与 STFT 完全一样。事实上它正在使用 STFT。

现在,对于差异,根据定义,频谱图是信号 s(t) 的短时傅立叶变换 (STFT) 的平方幅值:

spectrogram(t, w) = |STFT(t, w)|^2

scipy.signal.stft 页面底部显示的示例显示:

>>> plt.pcolormesh(t, f, np.abs(Zxx), vmin=0, vmax=amp)

它正在运行,您可以看到色标。但它是线性的,因为 abs 操作。

实际上,要得到真正的频谱图,应该这样写:

>>> plt.pcolormesh(t, f, Zxx ** 2, vmin=0, vmax=amp)