bundles / scipy 1.17.1 / scipy / signal / windows / _windows / general_hamming
function
scipy.signal.windows._windows:general_hamming
Signature
def general_hamming ( M , alpha , sym = True , * , xp = None , device = None ) Summary
Return a generalized Hamming window.
Extended Summary
The generalized Hamming window is constructed by multiplying a rectangular window by one period of a cosine function [1].
Parameters
M: intNumber of points in the output window. If zero, an empty array is returned. An exception is thrown when it is negative.
alpha: floatThe window coefficient,
sym: bool, optionalWhen True (default), generates a symmetric window, for use in filter design. When False, generates a periodic window, for use in spectral analysis.
xp: array_namespace, optionalOptional array namespace. Should be compatible with the array API standard, or supported by array-api-compat. Default:
numpydevice: anyoptional device specification for output. Should match one of the supported device specification in
xp.
Returns
w: ndarrayThe window, with the maximum value normalized to 1 (though the value 1 does not appear if
Mis even andsymis True).
Notes
The generalized Hamming window is defined as
Both the common Hamming window and Hann window are special cases of the generalized Hamming window with = 0.54 and = 0.5, respectively [2].
Array API Standard Support
general_hamming has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ✅ JAX ✅ ✅ Dask ✅ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
The Sentinel-1A/B Instrument Processing Facility uses generalized Hamming windows in the processing of spaceborne Synthetic Aperture Radar (SAR) data [3]_. The facility uses various values for the :math:`\alpha` parameter based on operating mode of the SAR instrument. Some common :math:`\alpha` values include 0.75, 0.7 and 0.52 [4]_. As an example, we plot these different windows.import numpy as np from scipy.signal.windows import general_hamming from scipy.fft import fft, fftshift import matplotlib.pyplot as plt✓
fig1, spatial_plot = plt.subplots()
✓spatial_plot.set_title("Generalized Hamming Windows") spatial_plot.set_ylabel("Amplitude") spatial_plot.set_xlabel("Sample")✗
fig2, freq_plot = plt.subplots()
✓freq_plot.set_title("Frequency Responses") freq_plot.set_ylabel("Normalized magnitude [dB]") freq_plot.set_xlabel("Normalized frequency [cycles per sample]")✗
for alpha in [0.75, 0.7, 0.52]: window = general_hamming(41, alpha) spatial_plot.plot(window, label="{:.2f}".format(alpha)) A = fft(window, 2048) / (len(window)/2.0) freq = np.linspace(-0.5, 0.5, len(A)) response = 20 * np.log10(np.abs(fftshift(A / abs(A).max()))) freq_plot.plot(freq, response, label="{:.2f}".format(alpha)) freq_plot.legend(loc="upper right") spatial_plot.legend(loc="upper right")✗
See also
- hamming
- hann
Aliases
-
scipy.signal.windows.general_hamming