Window functions¶
In digital signal processing, windowing functions are useful to counteract the assumption made by the FFT that data is infinite and to reduce spectral leakage.
blackman_harris
¶

numpy_ml.utils.windows.
blackman_harris
(window_len, symmetric=False)[source]¶ The BlackmanHarris window.
Notes
The BlackmanHarris window is an instance of the more general class of cosinesum windows where K=3. Additional coefficients extend the Hamming window to further minimize the magnitude of the nearest sidelobe in the frequency response.
\[\text{bh}(n) = a_0  a_1 \cos\left(\frac{2 \pi n}{N}\right) + a_2 \cos\left(\frac{4 \pi n }{N}\right)  a_3 \cos\left(\frac{6 \pi n}{N}\right)\]where N = window_len  1, \(a_0\) = 0.35875, \(a_1\) = 0.48829, \(a_2\) = 0.14128, and \(a_3\) = 0.01168.
Parameters:  window_len (int) – The length of the window in samples. Should be equal to the frame_width if applying to a windowed signal.
 symmetric (bool) – If False, create a ‘periodic’ window that can be used in with an FFT / in spectral analysis. If True, generate a symmetric window that can be used in, e.g., filter design. Default is False.
Returns: window (
ndarray
of shape (window_len,)) – The window
generalized_cosine
¶

numpy_ml.utils.windows.
generalized_cosine
(window_len, coefs, symmetric=False)[source]¶ The generalized cosine family of window functions.
Notes
The generalized cosine window is a simple weighted sum of cosine terms.
For \(n \in \{0, \ldots, \text{window_len} \}\):
\[\text{GCW}(n) = \sum_{k=0}^K (1)^k a_k \cos\left(\frac{2 \pi k n}{\text{window_len}}\right)\]Parameters:  window_len (int) – The length of the window in samples. Should be equal to the frame_width if applying to a windowed signal.
 coefs (list of floats) – The \(a_k\) coefficient values
 symmetric (bool) – If False, create a ‘periodic’ window that can be used in with an FFT / in spectral analysis. If True, generate a symmetric window that can be used in, e.g., filter design. Default is False.
Returns: window (
ndarray
of shape (window_len,)) – The window
hamming
¶

numpy_ml.utils.windows.
hamming
(window_len, symmetric=False)[source]¶ The Hamming window.
Notes
The Hamming window is an instance of the more general class of cosinesum windows where K=1 and \(a_0 = 0.54\). Coefficients selected to minimize the magnitude of the nearest sidelobe in the frequency response.
\[\text{hamming}(n) = 0.54  0.46 \cos\left(\frac{2 \pi n}{\text{window_len}  1}\right)\]Parameters:  window_len (int) – The length of the window in samples. Should be equal to the frame_width if applying to a windowed signal.
 symmetric (bool) – If False, create a ‘periodic’ window that can be used in with an FFT / in spectral analysis. If True, generate a symmetric window that can be used in, e.g., filter design. Default is False.
Returns: window (
ndarray
of shape (window_len,)) – The window
hann
¶

numpy_ml.utils.windows.
hann
(window_len, symmetric=False)[source]¶ The Hann window.
Notes
The Hann window is an instance of the more general class of cosinesum windows where K=1 and \(a_0\) = 0.5. Unlike the Hamming window, the end points of the Hann window touch zero.
\[\text{hann}(n) = 0.5  0.5 \cos\left(\frac{2 \pi n}{\text{window_len}  1}\right)\]Parameters:  window_len (int) – The length of the window in samples. Should be equal to the frame_width if applying to a windowed signal.
 symmetric (bool) – If False, create a ‘periodic’ window that can be used in with an FFT / in spectral analysis. If True, generate a symmetric window that can be used in, e.g., filter design. Default is False.
Returns: window (
ndarray
of shape (window_len,)) – The window