scipy.signal.get_window(window,M,fftbins=True) takes a 3rd argument
...the fftbins=True argument (True beeing the default value), which is not mentionned throughout of the course, and can lead to precision errors easily in a multitude of cases, because it forces the window to be periodic or symmetric* :
fftbins : bool, optional
If True (default), create a "periodic" window, ready to use with
`ifftshift` and be multiplied by the result of an FFT (see also
`fftpack.fftfreq`).
If False, create a "symmetric" window, for use in filter design.
So if this argument is unchanged, get_window will always return a periodic window. This option could possibly have been added in a modern-ish version of scipy, hence why it's not beeing adressed. (see here https://www.coursera.org/learn/audio-signal-processing/programming/AZcF0/short-time-fourier-transform-stft/discussions/threads/W6_BoR4dEeiRQwooVK8Q3A)
*a first wrong understanding on my end was that this parameter changed the length of the window to be of an even or odd size, and change the length in samples of the output. It doesn't seem to change the length of the output. The way i understand it, if for example the size in samples is odd and the window supposed to be even-sized, then it may create an even sized window and zero-pad the last sample or the first one. In any case, the difference is real. See https://en.wikipedia.org/wiki/Window_function#Symmetry . I could add this line to have get_window behave consistently with what was expected from it : fftbins = M%2==0 ; M beeing the window size ; then passing fftbins argument to get_window.
This is possibly related to this SciPy commit & discussion : https://github.com/scipy/scipy/pull/6483
From my experiments, this only appears to have an effect on the phase spectrum.
...the
fftbins=Trueargument (Truebeeing the default value), which is not mentionned throughout of the course, and can lead to precision errors easily in a multitude of cases, because it forces the window to be periodic or symmetric* :fftbins : bool, optional If True (default), create a "periodic" window, ready to use with `ifftshift` and be multiplied by the result of an FFT (see also `fftpack.fftfreq`). If False, create a "symmetric" window, for use in filter design.So if this argument is unchanged, get_window will always return a periodic window. This option could possibly have been added in a modern-ish version of scipy, hence why it's not beeing adressed. (see here https://www.coursera.org/learn/audio-signal-processing/programming/AZcF0/short-time-fourier-transform-stft/discussions/threads/W6_BoR4dEeiRQwooVK8Q3A)
*a first wrong understanding on my end was that this parameter changed the length of the window to be of an even or odd size, and change the length in samples of the output. It doesn't seem to change the length of the output. The way i understand it, if for example the size in samples is odd and the window supposed to be even-sized, then it may create an even sized window and zero-pad the last sample or the first one. In any case, the difference is real. See https://en.wikipedia.org/wiki/Window_function#Symmetry . I could add this line to have
get_windowbehave consistently with what was expected from it :fftbins = M%2==0;Mbeeing the window size ; then passingfftbinsargument toget_window.This is possibly related to this SciPy commit & discussion : scipy/scipy#6483
You are my life-saver!!!