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

Function dft_bins

numpy_ml/preprocessing/dsp.py:276–301  ·  view source on GitHub ↗

Calc the frequency bin centers for a DFT with `N` coefficients. Parameters ---------- N : int The number of frequency bins in the DFT fs : int The sample rate/frequency of the signal (in Hz). Default is 44000. positive_only : bool Whether to only ret

(N, fs=44000, positive_only=True)

Source from the content-addressed store, hash-verified

274
275
276def dft_bins(N, fs=44000, positive_only=True):
277 """
278 Calc the frequency bin centers for a DFT with `N` coefficients.
279
280 Parameters
281 ----------
282 N : int
283 The number of frequency bins in the DFT
284 fs : int
285 The sample rate/frequency of the signal (in Hz). Default is 44000.
286 positive_only : bool
287 Whether to only return the bins for the positive frequency
288 terms. Default is True.
289
290 Returns
291 -------
292 bins : :py:class:`ndarray <numpy.ndarray>` of shape `(N,)` or `(N // 2 + 1,)` if `positive_only`
293 The frequency bin centers associated with each coefficient in the
294 DFT spectrum
295 """
296 if positive_only:
297 freq_bins = np.linspace(0, fs / 2, 1 + N // 2, endpoint=True)
298 else:
299 l, r = (1 + (N - 1) / 2, (1 - N) / 2) if N % 2 else (N / 2, -N / 2)
300 freq_bins = np.r_[np.arange(l), np.arange(r, 0)] * fs / N
301 return freq_bins
302
303
304def magnitude_spectrum(frames):

Callers 2

test_dft_binsFunction · 0.90
mel_filterbankFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_dft_binsFunction · 0.72