[PYTHON] Difference in output of even-length window function

Introduction

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)

Comparison

There are three types of candidates to compare. The window width is $ N $.

Comparison result

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])

why

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.

References

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

Difference in output of even-length window function
Implementation of login function in Django
Output tree structure of files in Python
Output the number of CPU cores in Python
Draw a graph of a quadratic function in Python
[Linux] Difference in time information depending on the clock ID of the clock_gettime () function
Get the caller of a function in Python
Read the output of subprocess.Popen in real time
Reconsideration of paging implementation by Relay style in GraphQL (version using Window function)
Fix the argument of the function used in map
Gacha written in python-Addition of period setting function-
Output in the form of a python array
Duality in function
Project Euler # 6 "Difference in sum of squares" in Python
Speed evaluation of CSV file output in Python
Difference between Ruby and Python in terms of variables
[Cinema 4D] function of check all object in scene
[python] Calculation of months and years of difference in datetime
Difference in results depending on the argument of multiprocess.Process
Execute function in parallel
Japanese output in Python
Basics of python: Output
Set function of NumPy
Have the equation graph of the linear function drawn in Python
A memo of writing a basic function in Python using recursion
Make the function of drawing Japanese fonts in OpenCV general
Coordination of each process in MPI and buffering of standard output