There are multiple ways to generate a window function, which is widely used in signal processing, with python
.
Since the behavior is slightly different depending on the generation method, record it as a memorandum.
(Limited to humming windows here. Maybe similar things happen with any window)
There are three types of candidates to compare. The window width is $ N $.
numpy.hamming(N)
scipy.signal.hamming(N)
scipy.signal.get_window('hamming', N)
Same when $ N $ is odd.
>>> import scipy.signal, numpy
>>> N = 5
>>> numpy.hamming(N)
array([ 0.08, 0.54, 1. , 0.54, 0.08])
>>> scipy.signal.hamming(N)
array([ 0.08, 0.54, 1. , 0.54, 0.08])
>>> scipy.signal.get_window('hamming', N)
array([ 0.08, 0.54, 1. , 0.54, 0.08])
However, the situation changes when $ N $ becomes an even number. (get_window
)
>>> import numpy, scipy.signal
>>> N = 4
>>> numpy.hamming(N)
array([ 0.08, 0.77, 0.77, 0.08])
>>> scipy.signal.hamming(N)
array([ 0.08, 0.77, 0.77, 0.08])
>>> scipy.signal.get_window('hamming', N)
array([ 0.08, 0.54, 1. , 0.54])
However, if you put False
in the third argument of get_window
, the result will be the same.
>>> scipy.signal.get_window('hamming', N, False)
array([ 0.08, 0.77, 0.77, 0.08])
scipy.signal.hamming
and numpy.hamming
are by default
Generate the value of the window function so that it is symmetrical.
On the other hand, get_window
generates a" periodic "(?) Value for ease of use in the FFT.
Setting the third argument to False
produces a symmetric value that is easy for the filter to use.
Therefore, the default behavior differs depending on the function.
http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.hamming.html http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.get_window.html
Recommended Posts