MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / calculate_signal_power

Function calculate_signal_power

machine_learning/mfcc.py:254–271  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

252
253
254def 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
274def freq_to_mel(freq: float) -> float:

Callers 1

mfccFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected