Skip to content

Instantly share code, notes, and snippets.

@bmcfee
Created April 19, 2018 13:32
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmcfee/746e572232be36f3bd462749fb1796da to your computer and use it in GitHub Desktop.
Save bmcfee/746e572232be36f3bd462749fb1796da to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@faroit
Copy link

faroit commented Feb 10, 2019

@bmcfee thanks for doing this. I actually found out that you can get even closer for 'hann' windows. Also the normalization factor should be n_fft (in your example 1024).

@vvasily
Copy link

vvasily commented Jun 11, 2021

scipy.signal.stft uses scale factor for the result https://github.com/scipy/scipy/blob/43b76937c0aadf23b4e0fcc04f546fa5d61b543b/scipy/signal/spectral.py#L1805
To get the same values you need to divide D2 in following way:
hamm_win = scipy.signal.get_window('hamming', 2048)
scale = np.sqrt(1.0 / hamm_win.sum()**2)
D2 = D2 / scale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment