Learn R Programming

seewave (version 1.4.5)

diffenv: Difference between two amplitude envelopes

Description

This function estimates the surface difference between two amplitude envelopes.

Usage

diffenv(wave1, wave2, f, smooth = NULL, plot = FALSE,
lty1 = 1, lty2 = 2, col1 = 2, col2 = 4, cold = 8, xlab = "Time (s)",
ylab = "Amplitude",...)

Arguments

wave1
data or a Sample object generated loading a wav file with loadSample (package Sound) describing a first time wave.
wave2
data or a Sample object generated loading a wav file with loadSample (package Sound) describing a second time wave.
f
sampling frequency of wave1 and wave1 (in Hz). Does not need to be specified if wave1 and/or wave2 are/is (a) Sample object(s).
smooth
smoothes both envelopes by floating average. See examples.
plot
logical, if TRUE plots both envelopes and their surface difference (by default FALSE).
lty1
line type of the first envelope (envelope of wave1).
lty2
line type of the second envelope (envelope of wave2).
col1
colour of the first envelope (envelope of wave1).
col2
colour of the second envelope (envelope of wave2).
cold
colour of the surface difference.
xlab
title of the time axis.
ylab
title of the amplitude axis.
...
other plot graphical parameters.

Value

  • The difference is returned. This value is without unit. When plot is TRUE, both envelopes and their difference surface are plotted on the same graph.

Details

Envelopes of both waves are first transformed as probability mass functions (PMF). Envelope difference is then computed according to: $$D = \frac{\sum{|env1-env2|}}{2}, with D \in [0,1].$$

See Also

oscillo, corenv, diffspec, diffwave

Examples

Run this code
data(tico)
data(orni)
# selection in tico to have two waves of similar duration (length)
tico<-as.matrix(tico[1:15842,1])
diffenv(tico,orni,f=22050,plot=TRUE)
# [1] 0.7362514
# smoothing the envelope gives a better graph but changes the result
diffenv(tico,orni,f=22050,smooth=20,plot=TRUE)
# [1] 0.6871243
# smoothing can have actually dramatic effects
# so always use the same smooth settings for comparisons
a<-synth(d=0.5,f=8000,cf=1000,plot=FALSE)
b<-synth(d=0.5,f=8000,cf=1100,plot=FALSE)
diffenv(a,b,f=8000)
# [1] 0.2727784
diffenv(a,b,f=8000,smooth=50)
# [1] 0.01012826

Run the code above in your browser using DataLab