Peaks
Peak detection and characterisation tools for spectral data: find peaks, measure bandwidth and Q-factor, and identify harmonic series.

dspkit.peaks.find_peaks(freqs, spectrum, prominence=None, height=None, distance_hz=None, max_peaks=None)
Detect peaks in a frequency spectrum.
Wraps scipy.signal.find_peaks with frequency-aware defaults suitable
for PSD / FFT spectra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freqs
|
(array_like, shape(M))
|
Frequency vector [Hz]. |
required |
spectrum
|
(array_like, shape(M))
|
Spectral amplitude or PSD values (real, non-negative). |
required |
prominence
|
float or None
|
Minimum peak prominence (in the same units as |
None
|
height
|
float or None
|
Minimum absolute peak height. |
None
|
distance_hz
|
float or None
|
Minimum horizontal distance between peaks [Hz]. Converted to samples internally. |
None
|
max_peaks
|
int or None
|
Return only the |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
peak_freqs |
ndarray
|
Frequencies of detected peaks [Hz]. |
peak_values |
ndarray
|
Spectrum values at the detected peaks. |
prominences |
ndarray
|
Prominence of each peak (useful for ranking). |
Source code in dspkit/peaks.py
dspkit.peaks.peak_bandwidth(freqs, spectrum, peak_freqs=None, rel_height=0.5)
Estimate the bandwidth of spectral peaks at a given relative height.
By default measures the half-power (-3 dB) bandwidth, i.e. the width at 50 % of peak height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freqs
|
(array_like, shape(M))
|
Frequency vector [Hz]. |
required |
spectrum
|
(array_like, shape(M))
|
Spectral amplitude or PSD values. |
required |
peak_freqs
|
array_like or None
|
Frequencies of peaks to measure. If |
None
|
rel_height
|
float
|
Relative height at which to measure width. 0.5 = half-power (-3 dB). |
0.5
|
Returns:
| Name | Type | Description |
|---|---|---|
peak_freqs |
ndarray
|
Frequencies of the measured peaks [Hz]. |
bandwidths |
ndarray
|
Bandwidth of each peak [Hz]. |
q_factors |
ndarray
|
Quality factor Q = f_peak / bandwidth for each peak. |
Source code in dspkit/peaks.py
dspkit.peaks.find_harmonics(freqs, spectrum, fundamental, n_harmonics=5, tolerance_hz=None)
Identify harmonic peaks (f0, 2f0, 3f0, ...) in a spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freqs
|
(array_like, shape(M))
|
Frequency vector [Hz]. |
required |
spectrum
|
(array_like, shape(M))
|
Spectral amplitude or PSD. |
required |
fundamental
|
float
|
Fundamental frequency [Hz]. |
required |
n_harmonics
|
int
|
Number of harmonics to look for (including the fundamental). |
5
|
tolerance_hz
|
float or None
|
Search tolerance around each expected harmonic [Hz].
Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
harmonic_freqs |
(ndarray, shape(n_found))
|
Detected harmonic frequencies [Hz]. |
harmonic_values |
(ndarray, shape(n_found))
|
Spectrum values at those frequencies. |
harmonic_orders |
(ndarray, shape(n_found))
|
Harmonic order (1 = fundamental, 2 = second harmonic, ...). |