xcorr
estimates the similarity of two spectrograms by means of cross-correlation
xcorr(X, wl =512, frange= NULL, ovlp=90, dens=0.9, bp= NULL, wn='hanning',
cor.method = "pearson", parallel = 1, path = NULL, pb = TRUE, na.rm = FALSE,
dfrange = FALSE, cor.mat = TRUE)
'selection.table' object or data frame containing columns for sound files (sound.files), selection number (selec), and start and end time of signal (start and end).
A numeric vector of length 1 specifying the window length of the spectrogram, default is 512.
A numeric vector of length 2 setting the upper and lower frequency limits (in kHz)
in which to compare the signals. Must be provided. The dfts
function can be used to determine this parameter if dfrange = TRUE
. This method is more adequate for pure tone
signals. Default is NULL
.
Numeric vector of length 1 specifying % of overlap between two
consecutive windows, as in spectro
. Default is 90. High values of ovlp
slow down the function but produce more accurate results.
Numeric vector of length 1 specifying the approximate density of points in which to sample amplitude.
See makeTemplate
. Deafult is 0.9.
A numeric vector of length 2 for the lower and upper limits of a
frequency bandpass filter (in kHz) in which to detect dominant frequency.
Only applied when frange is NULL
. Default is NULL
.
A character vector of length 1 specifying the window name as in ftwindow
.
A character vector of length 1 specifying the correlation method as in cor
.
Numeric. Controls whether parallel computing is applied. It specifies the number of cores to be used. Default is 1 (i.e. no parallel computing). Not available in Windows OS.
Character string containing the directory path where the sound files are located.
If NULL
(default) then the current working directory is used.
Logical argument to control progress bar. Default is TRUE
. Note that progress bar is only used
when parallel = 1. Note that progress bar is not completely accurate as the number of pairwise comparisons decreases on each iteration
decreases. The first iteration runs n-1 comparisons while the last one only 1 (n = nrow(X)
).
Logical. If TRUE
all NAs produced when pairwise cross-correlations failed are removed from the
results. This means that all selections with at least 1 cross-correlation that failed are excluded.
Logical. If TRUE
the dfts
function can is used to determine the frequency range in which to compare signals.
Logical. If TRUE
only the correlation matrix is returned. Default is TRUE
.
If corr.mat is TRUE
the function returns a matrix with
the maximum (peak) correlation for each pairwise comparison. Otherwise it will return a list that includes 1) a data frame with the correlation statistic for each "sliding" step, 2) a matrix with
the maximum correlation for each pairwise comparison, and 3) the frequency range.
This function calculates the pairwise similarity of multiple signals by means of spectrogram cross-correlation.
This method "slides" one spectrogram over the other calculating a correlation of the amplitude values at each step.
The function runs pairwise cross-correlations on several signals and returns a list including the correlation statistic
for each "sliding" step as well as the maximum (peak) correlation for each pairwise comparison. To accomplish this the margins
of the signals are expanded by half the duration of the signal both before and after the provided time coordinates.
The correlation matrix could have NA's if some of the pairwise correlation did not work (common when sound files have been modified by band-pass filters).
This function is a modified version of the corMatch
and makeTemplate
from the awesome R package `monitoR`.
# NOT RUN {
{
#First set temporary working directory
setwd(tempdir())
#load data
data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4","selec.table"))
writeWave(Phae.long1, "Phae.long1.wav") #save sound files
writeWave(Phae.long2, "Phae.long2.wav")
writeWave(Phae.long3, "Phae.long3.wav")
writeWave(Phae.long4, "Phae.long4.wav")
xcor <- xcorr(X = selec.table, wl = 300, frange = c(2, 9), ovlp = 90,
dens = 1, wn = 'hanning', cor.method = "pearson")
}
# }
Run the code above in your browser using DataLab