I failed to reproduce Scipy's stft. When I have tried to remove all the possible modifications and go the minimal example, I converge to the following:
from scipy import signal
from scipy import fft
import numpy as np
n = 4
np.random.seed(0)
x = np.random.normal(size=n)
stftOut = signal.stft(
x, fs=1.0, window='hann', nperseg=n,
noverlap=None, nfft=n, detrend=False,
return_onesided=True, boundary=None,
padded=False, axis=-1, scaling='spectrum'
)[2]
rfftOut = fft.rfft(x * signal.windows.hann(n) / (signal.windows.hann(n)).sum())
Multiple tests showed that the larger the window, the smaller the error. It seems that I am missing something about the boundary conditions. What is it?