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

Function power_spectrum

numpy_ml/preprocessing/dsp.py:323–346  ·  view source on GitHub ↗

Compute the power spectrum for a signal represented as a collection of frames. Assumes each frame is real-valued only. The power spectrum is simply the square of the magnitude spectrum, possibly scaled by the number of FFT bins. It measures how the energy of the signal is distr

(frames, scale=False)

Source from the content-addressed store, hash-verified

321
322
323def power_spectrum(frames, scale=False):
324 """
325 Compute the power spectrum for a signal represented as a collection of
326 frames. Assumes each frame is real-valued only.
327
328 The power spectrum is simply the square of the magnitude spectrum, possibly
329 scaled by the number of FFT bins. It measures how the energy of the signal
330 is distributed over the frequency domain.
331
332 Parameters
333 ----------
334 frames : :py:class:`ndarray <numpy.ndarray>` of shape `(M, N)`
335 A sequence of `M` frames each consisting of `N` samples
336 scale : bool
337 Whether the scale by the number of DFT bins. Default is False.
338
339 Returns
340 -------
341 power_spec : :py:class:`ndarray <numpy.ndarray>` of shape `(M, N // 2 + 1)`
342 The power spectrum for each frame in `frames`. Only includes the
343 coefficients for the positive spectrum frequencies.
344 """
345 scaler = frames.shape[1] // 2 + 1 if scale else 1
346 return (1 / scaler) * magnitude_spectrum(frames) ** 2
347
348
349#######################################################################

Callers 1

mel_spectrogramFunction · 0.85

Calls 1

magnitude_spectrumFunction · 0.85

Tested by

no test coverage detected