Learn R Programming

warbleR (version 1.1.8)

xcorr: Spectrogram cross-correlation

Description

xcorr estimates the similarity of two spectrograms by means of cross-correlation

Usage

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)

Arguments

X

Data frame containing columns for sound files (sound.files), selection number (selec), and start and end time of signal (start and end).

wl

A numeric vector of length 1 specifying the window length of the spectrogram, default is 512.

frange

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.

ovlp

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.

dens

Numeric vector of length 1 specifying the approximate density of points in which to sample amplitude. See makeTemplate. Deafult is 0.9.

bp

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.

wn

A character vector of length 1 specifying the window name as in ftwindow.

cor.method

A character vector of length 1 specifying the correlation method as in cor.

parallel

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.

path

Character string containing the directory path where the sound files are located. If NULL (default) then the current working directory is used.

pb

Logical argument to control progress bar. Default is TRUE. Note that progress bar is only used when parallel = 1.

na.rm

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.

dfrange

Logical. If TRUE the dfts function can is used to determine the frequency range in which to compare signals.

cor.mat

Logical. If TRUE only the correlation matrix is returned. Default is TRUE.

Value

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.

Details

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`.

See Also

xcorr.graph

Examples

Run this code
# 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