MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / generalized_cosine

Function generalized_cosine

numpy_ml/utils/windows.py:108–142  ·  view source on GitHub ↗

The generalized cosine family of window functions. Notes ----- The generalized cosine window is a simple weighted sum of cosine terms. For :math:`n \in \{0, \ldots, \\text{window_len} \}`: .. math:: \\text{GCW}(n) = \sum_{k=0}^K (-1)^k a_k \cos\left(\\frac{2 \pi

(window_len, coefs, symmetric=False)

Source from the content-addressed store, hash-verified

106
107
108def generalized_cosine(window_len, coefs, symmetric=False):
109 """
110 The generalized cosine family of window functions.
111
112 Notes
113 -----
114 The generalized cosine window is a simple weighted sum of cosine terms.
115
116 For :math:`n \in \{0, \ldots, \\text{window_len} \}`:
117
118 .. math::
119
120 \\text{GCW}(n) = \sum_{k=0}^K (-1)^k a_k \cos\left(\\frac{2 \pi k n}{\\text{window_len}}\\right)
121
122 Parameters
123 ----------
124 window_len : int
125 The length of the window in samples. Should be equal to the
126 `frame_width` if applying to a windowed signal.
127 coefs: list of floats
128 The :math:`a_k` coefficient values
129 symmetric : bool
130 If False, create a 'periodic' window that can be used in with an FFT /
131 in spectral analysis. If True, generate a symmetric window that can be
132 used in, e.g., filter design. Default is False.
133
134 Returns
135 -------
136 window : :py:class:`ndarray <numpy.ndarray>` of shape `(window_len,)`
137 The window
138 """
139 window_len += 1 if not symmetric else 0
140 entries = np.linspace(-np.pi, np.pi, window_len) # (-1)^k * 2pi*n / window_len
141 window = np.sum([ak * np.cos(k * entries) for k, ak in enumerate(coefs)], axis=0)
142 return window[:-1] if not symmetric else window
143
144
145class WindowInitializer:

Callers 3

blackman_harrisFunction · 0.85
hammingFunction · 0.85
hannFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected