Learn R Programming

seewave (version 2.2.3)

localpeaks: Local maximum frequency peak detection

Description

This functions searches for local peaks of a frequency spectrum

Usage

localpeaks(spec, f = NULL, bands = 10, mel = FALSE, plot = TRUE,
xlab = NULL, ylab = "Amplitude", labels = TRUE, ...)

Value

A two-column matrix, the first column corresponding to the frequency values (x-axis) and the second column corresponding to the amplitude values (y-axis) of the peaks.

Arguments

spec

a data set resulting of a spectral analysis obtained with spec or meanspec. Can be in dB.

f

sampling frequency of spec (in Hz). Not requested if the first column of spec contains the frequency axis.

bands

a numeric vector. If vector of length 1, then sets the number of bands dividing in equal parts the spectrum. If of length > 1, then takes the values as kHz limits of the bands dividing the spectrum. These bands can be of different size. See details and examples.

mel

a logical, if TRUE the (htk-)mel scale is used.

plot

logical, if TRUE, a plot showing the peaks is returned.

xlab

label of the x-axis.

ylab

label of the y-axis.

labels

logical, if TRUE peak labels are plotted.

...

other plot graphical parameters.

Author

Jerome Sueur

Details

The function proceed as follows

  • divides the spectrum in bands. The limits of the bands are set with the argument bands. There are two options:

    • you set a number of bands with equal size by giving a single value to bands. For instance, setting bands to a value of 10 will slice the spectrum in 10 equal parts and return 10 local peaks.

    • you set the limits of the bands. This is achieve by giving a numeric vector to bands. The limits can follow a regular or irregular series. For instance attributing the vector c(0,2,4,8) will generate the following bands [0,2[, [2,4[, [4,8] kHz. Be aware that the last value should not exceed half the sampling frequency used to obtain the spectrum spec.

  • uses the function fpeaks with the argument nmax set to 1.

See Also

fpeaks, meanspec, spec

Examples

Run this code
data(sheep)
spec <- meanspec(sheep, f=8000)
# a specific number of bands with all the same size
localpeaks(spec, bands=5)
# bands directly specified  with a regular sequence
localpeaks(spec, bands=seq(0,8/2,by=0.5))
# bands directly specified  with an irregular sequence
localpeaks(spec, bands=c(0,0.5,1,1.5,3,4))
# Amaj octave bands, note that there is no peak detection
# in the higher part of the spectrum as sequence stops at 3520 Hz
localpeaks(spec, bands=octaves(440, below=3, above=3)/1000)
# melscale
require(tuneR)
mel <- melfcc(sheep, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE)
melspec.mean <- apply(mel$aspectrum, MARGIN=2, FUN=mean)
melspec.mean <- melspec.mean/max(melspec.mean) # [0,1] scaling 
localpeaks(melspec.mean, f=8000, bands=8)

Run the code above in your browser using DataLab