9951 explained code solutions for 126 technologies


python-scipyHow do I use a Hamming window in Python with SciPy?


A Hamming window is a type of window function used in signal processing. It is commonly used in spectral analysis to reduce spectral leakage. In Python, the Hamming window can be generated using the SciPy library. Here is an example of how to use it:

import numpy as np
from scipy.signal import hamming

# Generate a Hamming window of length 10
window = hamming(10)

# Print the window
print(window)

Output example

[0.08 0.18 0.3  0.46 0.54 0.6  0.54 0.46 0.3  0.18]

The code above imports the NumPy and SciPy libraries and then uses the hamming() function from the SciPy library to generate a Hamming window of length 10. Finally, the window is printed to the console.

The parts of the code are as follows:

  1. import numpy as np: This imports the NumPy library and assigns it the alias np.
  2. from scipy.signal import hamming: This imports the hamming() function from the SciPy library.
  3. window = hamming(10): This generates a Hamming window of length 10 and assigns it to the variable window.
  4. print(window): This prints the window to the console.

For more information, see the SciPy documentation on Windows and Window Functions.

Edit this code on GitHub