Learn R Programming

seewave (version 1.4.1)

diffspec: Surface difference between two frequency spectra

Description

This function calculates the difference between the surfaces of two frequency spectra.

Usage

diffspec(spec1, spec2, f, dB = FALSE, plot = FALSE, type = "l",
lty1 = 1, lty2 = 2, col1 = 2, col2 = 4, cold = 8,
flab = "Frequency (kHz)", alab = "Amplitude",
flim = c(0, f/2000), alim = c(0, 1.1), ...)

Arguments

spec1
a first data set resulting of a spectral analysis obtained with spec or meanspec (not in dB).
spec2
a second data set resulting of a spectral analysis obtained with spec or meanspec (not in dB).
f
sampling frequency of waves used to obtain spec1 and spec2 (in Hz).
dB
logical, if TRUE return the spectra and their surface difference in dB (by default FALSE).
plot
logical, if TRUE plots both spectra and their surface difference (by default FALSE).
type
plot type, see plot.
lty1
line type of spec1 if type="l".
lty2
line type of spec2 if type="l".
col1
colour of spec1.
col2
colour of spec2.
cold
colour of the surface difference.
flab
title of the frequency axis.
alab
title of the amplitude axis.
flim
the range of frequency values.
alim
range of amplitude axis.
...
other plot graphical parameters.

Value

  • The surface difference is returned. This value is without unit, spectra being scaled between 0 and 1. If dB is TRUE, the same value is returned in dB. When plot is TRUE, both spectra and their difference surface are plotted on the same graph.

Details

This method can be used as a relative distance estimation between different spectra.

See Also

spec, meanspec, corspec

Examples

Run this code
a<-noise(f=8000,d=1)
b<-synth(f=8000,d=1,cf=2000)
c<-synth(f=8000,d=1,cf=1000)
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)
diffspec(speca,speca,f=8000)
#[1] 0 => similar spectra of course !
diffspec(speca,specb,f=8000)
#[1] 85.40181 => different spectra
diffspec(speca,specc,f=8000,plot=TRUE)
#[1] 0.1139283

Run the code above in your browser using DataLab