Calculate the power of the audio signal from its FFT. Args: audio_fft: The FFT of the audio signal. Returns: The power of the audio signal. Examples: >>> audio_fft = np.array([1+2j, 2+3j, 3+4j, 4+5j]) >>> power = calculate_signal_power(audio_fft) >>> n
(audio_fft: np.ndarray)
| 252 | |
| 253 | |
| 254 | def calculate_signal_power(audio_fft: np.ndarray) -> np.ndarray: |
| 255 | """ |
| 256 | Calculate the power of the audio signal from its FFT. |
| 257 | |
| 258 | Args: |
| 259 | audio_fft: The FFT of the audio signal. |
| 260 | |
| 261 | Returns: |
| 262 | The power of the audio signal. |
| 263 | |
| 264 | Examples: |
| 265 | >>> audio_fft = np.array([1+2j, 2+3j, 3+4j, 4+5j]) |
| 266 | >>> power = calculate_signal_power(audio_fft) |
| 267 | >>> np.allclose(power, np.array([5, 13, 25, 41])) |
| 268 | True |
| 269 | """ |
| 270 | # Calculate the power by squaring the absolute values of the FFT coefficients |
| 271 | return np.square(np.abs(audio_fft)) |
| 272 | |
| 273 | |
| 274 | def freq_to_mel(freq: float) -> float: |