maad.features.number_of_peaks

maad.features.number_of_peaks(X, fn, mode='dB', min_peak_val=None, min_freq_dist=200, slopes=(1, 1), prominence=0, display=False, **kwargs)[source]

Count the number of frequency peaks on a mean spectrum. [1] This function was adapted from the function fpeaks of the R package Seewave [2]

Parameters:
Xndarray of floats (1d) or (2d)

Amplitude spectrum (1d) or spectrogram (2d). If spectrogram, the mean spectrum will be computed before finding peaks

fn1d ndarray of floats

frequency vector

modestring {dB, linear}, optional, default is dB

select if the amplitude spectrum is converted into dB

min_peak_valscalar, optional, default is None

amplitude threshold parameter. Only peaks above this threshold will be considered.

min_freq_dist: scalar, optional, default is 200

frequency threshold parameter (in Hz). If the frequency difference of two successive peaks is less than this threshold, then the peak of highest amplitude will be kept only.

slopestupple of two values, optional, default is (1,1)

slope parameter, tupple of float of length 2 corresponding to left and right slopes, one or both could be set to None. Refers to the amplitude slopes of the peak. The first value is the left slope and the second value is the right slope. Only peaks with higher slopes than threshold values will be kept.

prominencenumber, ndarray or sequence, optional, default is None

Prominence of peaks. The first element is the minimal prominence and the second element is the maximal prominence. If a single number is provided it is interpreted as the minimal value, and no maximial value will be used.

display: boolean, optional, default is False

if True, display the mean spectrum with the detected peaks

Returns:
NBPeaksinteger

Number of detected peaks on the mean spectrum

References

[1]

Gasc, A. & al (2013). Biodiversity sampling using a global acoustic approach: contrasting sites with microendemics in New Caledonia. PloS one, 8(5), e65311. DOI: 10.1371/journal.pone.0065311

[2]

Seewave : http://rug.mnhn.fr/seewave. Sueur, J., Aubin, T., & Simonis, C. (2008). Seewave, a free modular tool for sound analysis and synthesis. Bioacoustics, 18(2), 213-226. DOI: 10.1080/09524622.2008.9753600

Examples

>>> import maad
>>> s, fs = maad.sound.load('../data/cold_forest_daylight.wav')
>>> Sxx_power, tn, fn, _ = maad.sound.spectrogram (s, fs)  
>>> maad.features.number_of_peaks(Sxx_power, fn, slopes=6, min_freq_dist=100, display=True) 
14