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)
| 321 | |
| 322 | |
| 323 | def 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 | ####################################################################### |
no test coverage detected