| diffspec {seewave} | R Documentation |
Difference between two frequency spectra
Description
This function estimates the surface difference between two frequency spectra.
Usage
diffspec(spec1, spec2, f = NULL, mel = FALSE,
plot = FALSE, type="l",
lty=c(1, 2), col =c(2, 4, 8),
flab = NULL, alab = "Amplitude",
flim = NULL, alim = NULL, title = TRUE, legend = TRUE, ...)
Arguments
spec1 |
a first data set resulting of a spectral analysis obtained
with |
spec2 |
a first data set resulting of a spectral analysis obtained
with |
f |
sampling frequency of waves used to obtain |
mel |
a logical, if |
plot |
logical, if |
type |
if |
lty |
a vector of length 2 for the line type of |
col |
a vector of length 3 for the colour of |
flab |
title of the frequency axis. |
alab |
title of the amplitude axis. |
flim |
the range of frequency values. |
alim |
range of amplitude axis. |
title |
logical, if |
legend |
logical, if |
... |
other |
Details
D is a Manhattan distance (l1 norm).
Both spectra are first transformed as probability mass functions (PMF).
Spectral difference is then computed according to:
D = \frac{\sum{|spec1-spec2|}}{2}, with D \in [0,1].
, with 0 < D < 1.
Value
The difference is returned. This value is without unit.
When plot is TRUE, both spectra and their difference surface are
plotted on the same graph.
Note
This method can be used as a relative distance estimation
between different spectra.
The dB value obtained can be very different from the one visually estimated
when looking at the graph (plot=TRUE).
Author(s)
Jerome Sueur, Sandrine Pavoine and Laurent Lellouch
References
Sueur, J., Pavoine, S., Hamerlynck, O. and Duvail, S. (2008). Rapid acoustic survey for biodiversity appraisal. PLoS One, 3(12): e4065.
See Also
spec, meanspec, corspec,
simspec, diffcumspec, diffenv, kl.dist,
ks.dist, logspec.dist, itakura.dist
Examples
a <- noisew(f=8000,d=1)
b <- synth(f=8000,d=1,cf=2000)
c <- synth(f=8000,d=1,cf=1000)
d <- noisew(f=8000,d=1)
speca <- spec(a,f=8000,wl=512,at=0.5,plot=FALSE)
specb <- spec(b,f=8000,wl=512,at=0.5,plot=FALSE)
specc <- spec(c,f=8000,wl=512,at=0.5,plot=FALSE)
specd <- spec(d,f=8000,wl=512,at=0.5,plot=FALSE)
diffspec(speca,speca,f=8000)
#[1] 0 => similar spectra of course !
diffspec(speca,specb)
diffspec(speca,specc,plot=TRUE)
diffspec(specb,specc,plot=TRUE)
diffspec(speca,specd,plot=TRUE)
## mel scale
require(tuneR)
data(orni)
data(tico)
orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE)
orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean)
tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE)
tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean)
diffspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)