scipy.signal stft 的第一条 DFT 线

First DFT line of the stft by scipy.signal

我已经手动实现了 STFT。 与 scipy.signal.stft 的比较揭示了与我的实现相同的结果,除了在开始时 (t=0) 有一个额外的 DFT 部分。 任何人都可以编写描述我可能错过的第一个 DFT 的脚本吗?

我的信号: ]1

sci.signal.stft 的信号: 2

代码:

def my_stft(samples, fs, wind_len_time=0.5, overlap_factor=0.5, 
                  zero_padding_factor=4):
    wind_len = int(fs * wind_len_time)
    overlap = wind_len * overlap_factor
    section_promotion = wind_len - overlap
    transform_len = wind_len * zero_padding_factor
    stft = []
    for index in np.arange(0, samples.size, section_promotion).astype(int):
        section = samples[index:index + wind_len]
        section_fft = np.abs(fft(section, n=transform_len))
        if not np.mod(section_fft.size, 2).astype(bool):
            section_fft = section_fft[:section_fft.size / 2]
        else:
            logger.debug('odd length fft') 
        stft.append(section_fft)
    time = np.arange(0, samples.size, section_promotion) / float(fs)
    freq = np.arange(section_fft.size) / float(section_fft.size) * fs / 2.0
    Freq, Time = np.meshgrid(time, freq)
    stft = np.array(stft).transpose()
    scaling = 2 / fs# onesided
    stft = stft * scaling
    return Time, Freq, stft

参数boundary=None的定义(在scipy.signal.stft)会去掉第一个谱t=0