Skip to content

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 Xp=|X|RM.

fpeak=fs2(M1)\argmaxmXp[m]

The result is in the range of 0 Hz and the nyquist frequency (half the sampling rate fs).

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
Run in playground