且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

scipy.signal.spectrogram nfft参数

更新时间:2023-02-26 16:59:37

快速傅里叶变换(FFT).可以使用nperseg参数控制这些段的长度,该参数使您可以调整由于

scipy.signal.spectrogram works by splitting the signal into (partially overlapping) segments of time, and then computing the power spectrum from the Fast Fourier Transform (FFT) of each segment. The length of these segments can be controlled using the nperseg argument, which lets you adjust the trade-off between resolution in the frequency and time domains that arises due to the uncertainty principle. Making nperseg larger gives you more resolution in the frequency domain at the cost of less resolution in the time domain.

除了改变进入每个段的样本数量外,有时还需要在进行FFT之前对每个段应用零填充.这就是nfft参数的用途:

In addition to varying the number of samples that go into each segment, it's also sometimes desirable to apply zero-padding to each segment before taking its FFT. This is what the nfft argument is for:

nfft :int,可选

如果需要零填充FFT,则使用FFT的长度.如果为 None ,则FFT长度为 nperseg .默认为.

Length of the FFT used, if a zero padded FFT is desired. If None, the FFT length is nperseg. Defaults to None.

默认情况下为nfft == nperseg,表示将不使用零填充.

By default, nfft == nperseg, meaning that no zero-padding will be used.

  • 一个原因是,这会使FFT结果更长,这意味着您最终会得到更多的频率仓,并且频谱图在频率范围内看起来更平滑".但是,请注意,这实际上并不会在频域中为您提供任何分辨率-从根本上讲,这是对FFT结果进行正弦插值的一种有效方法(请参见
  • One reason is that this makes the FFT result longer, meaning that you end up with more frequency bins and a spectrogram that looks "smoother" over the frequency dimension. However, note that this doesn't actually give you any more resolution in the frequency domain - it's basically an efficient way of doing sinc interpolation on the FFT result (see here for a more detailed explanation).
  • From a performance perspective it might make sense to pad the segments so that their length is a power of 2, since radix-2 FFTs can be significantly faster than more general methods.