Change language

Hamming in Numpy

Hamming — this is a cone formed using a weighted cosine

  Parameters (numpy.hamming (M)):   M:  int Number of points in the output window. If zero or less, an empty array is returned.  Returns:   out: array

Window with maximum value normalized to one (value one appears only if the number of samples is odd). 
Example :

import numpy as np 

print (np.hamming ( 12 ))

Output:

 [0.08 0.15302337 0.34890909 0.60546483 0.84123594 0.98136677 0.98136677 0.84123594 0.60546483 0.34890909 0.15302337 0.08] 

Plotting the window and its frequency response (SciPy required ):
For window:

import numpy as np 

import matplotlib.pyplot as plt 

from numpy.fft import fft, fftshift 

 

window = np.hamming ( 51 )

 
plt.plot (window) 

plt.title ( " Hamming window " )

plt.ylabel ( "Amplitude"

plt.xlabel ( "Sample"

plt.show () 

Exit:

hamming_window

For frequency:

import numpy as np 

import matplotlib.pyplot as plt 

from numpy.fft import fft, fftshift 

  

window = np.hamming ( 51 )

 
plt.figure ()

 

A = fft (window, 2048 ) / 25.5

mag = np. abs (fftshift (A))

freq = np.linspace ( - 0.5 , 0.5 , len (A))

response = 20 * np.log10 (mag)

response = np.clip (response, - 100 , 100 )

 
plt.plot (freq, response )

plt.title ( "Frequency response of Hamming window" )

plt.ylabel ( "Magnitude [dB]" )

plt.xlabel ( "Normalized frequency [cycles per sample] " )

plt.axis ( ’ tight’ )

plt.show ()

Exit:

hamming_frequency

Shop

Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best laptop for development

$499+
Gifts for programmers

Best laptop for Cricut Maker

$299+
Gifts for programmers

Best laptop for hacking

$890
Gifts for programmers

Best laptop for Machine Learning

$699+
Gifts for programmers

Raspberry Pi robot kit

$150

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically