Learn R Programming

seewave (version 2.1.8)

dfreq: Dominant frequency of a time wave

Description

This function gives the dominant frequency (i. e. the frequency of highest amplitude) of a time wave.

Usage

dfreq(wave, f, channel = 1, wl = 512, wn = "hanning", ovlp = 0, fftw=  FALSE, at =
NULL, tlim = NULL, threshold = NULL, bandpass = NULL, clip = NULL,
plot = TRUE, xlab = "Times (s)", ylab = "Frequency (kHz)",
ylim = c(0, f/2000), ...)

Arguments

wave

an R object.

f

sampling frequency of wave (in Hz). Does not need to be specified if embedded in wave.

channel

channel of the R object, by default left channel (1).

wl

length of the window for the analysis (even number of points, by default = 512).

wn

window name, see ftwindow (by default "hanning").

ovlp

overlap between two successive analysis windows (in % ).

fftw

if TRUE calls the function FFT of the library fftw. See Notes of the spectro.

at

time position where the dominant frequency has to be computed (in s.).

tlim

modifications of the time X-axis limits.

threshold

amplitude threshold for signal detection (in % ).

bandpass

a numeric vector of length two, giving the lower and upper limits of a frequency bandpass filter (in Hz).

clip

a numeric value to select dominant frequency values according to their amplitude in reference to a maximal value of 1 for the whole signal (has to be >0 & < 1).

plot

logical, if TRUE plots the dominant frequency against time (by default TRUE).

xlab

title of the x axis.

ylab

title of the y axis.

ylim

the range of y values.

other plot graphical parameters.

Value

When plot is FALSE, dfreq returns a two-column matrix, the first column corresponding to time in seconds (x-axis) and the second column corresponding to to dominant frequency in kHz (y-axis). NA corresponds to pause sections in wave (see threshold).

See Also

spec, meanspec,spectro.

Examples

Run this code
# NOT RUN {
data(tico)
f <- 22050
# default
dfreq(tico,f)
# using the amplitude threshold and changing the graphical output
dfreq(tico, f, ovlp=50,threshold=5, type="l", col=2)
# using 'at' argument for specific positions along the time axis
dfreq(tico, f, at=c(0.25, 0.75, 1.2, 1.6))
dfreq(tico, f, at=seq(0.5, 1.4, by=0.005), threshold=5)
# a specific number of measures on a single note
dfreq(tico, f, at=seq(0.5, 0.9, len=100), threshold=5, xlim=c(0.5,0.9))
# overlap on spectrogram
# and use of 'clip' argument to better track the dominant frequency
# in noisy conditions
op <- par()
ticon <- tico@left/max(tico@left) + noisew(d=length(tico@left)/f, f)
spectro(ticon, f)
res <- dfreq(ticon, f, clip=0.3, plot=FALSE)
points(res, col=2, pch =13)
par(op)
# }

Run the code above in your browser using DataLab