Algorithms | latest | spectral-peak-frequency
Spectral peak frequency
The spectral peak frequency is the frequency at which a signal or a waveform has its highest energy. It can be computed from the power spectrum
The result is in the range of 0 Hz and the nyquist frequency (half the sampling rate
Code
INFO
The following snippet is written in a generic and unoptimized manner. The code aims to be comprehensible to programmers familiar with various programming languages and may not represent the most efficient or idiomatic Python practices. Please refer to implementations for optimized implementations in different programming languages.
py
import numpy as np
def spectral_peak_frequency(spectrum: np.ndarray, samplerate: float) -> float:
peak_bin = np.argmax(spectrum**2)
return 0.5 * samplerate / (len(spectrum) - 1) * peak_bin