spectrum_correlation() measures frequency spectrum correlation of
sounds referenced in an extended selection table. Spectral
correlation measures the similarity of two sounds in the frequency
domain.
Usage
spectrum_correlation(
X,
cores = getOption("mc.cores", 1),
pb = getOption("pb", TRUE),
cor.method = c("pearson", "spearman", "kendall"),
spec.smooth = getOption("spec.smooth", 5),
hop.size = getOption("hop.size", 11.6),
wl = getOption("wl", NULL),
ovlp = getOption("ovlp", 70),
path = getOption("sound.files.path", "."),
n.bins = 100
)Arguments
- X
The output of
set_reference_sounds(), an object of classdata.frame,selection_table, orextended_selection_table(the last 2 classes are created bywarbleR::selection_table()from the warbleR package) with the test sound files' annotations. Must contain the following columns: 1)sound.files: name of the.wavfiles, 2)selec: unique selection identifier (within a sound file), 3)start: start time and 4)end: end time of selections, 5)bottom.freq: low frequency for bandpass, 6)top.freq: high frequency for bandpass, 7)sound.id: ID of sounds used to identify counterparts across distances, and 8)reference: identity of sounds to be used as reference for each test sound (row). Seeset_reference_sounds()for more details on the structure ofX.- cores
Numeric vector of length 1. Controls whether parallel computing is applied by specifying the number of cores to be used. Default
1(i.e. no parallel computing). Can be set globally for the current R session via the"mc.cores"option (seeoptions()).- pb
Logical argument to control if progress bar is shown. Default
TRUE. Can be set globally for the current R session via the"pb"option (seeoptions()).- cor.method
Character string indicating the correlation coefficient to be applied (
"pearson","spearman", or"kendall", seestats::cor()).- spec.smooth
Numeric vector of length 1 determining the length of the sliding window used for a sum smooth for power spectrum calculation (in kHz). Default
5.- hop.size
Numeric vector of length 1 specifying the time window duration (in ms). Default
11.6ms, which is equivalent to 512wlfor a 44.1 kHz sampling rate. Ignored ifwlis supplied. Can be set globally for the current R session via the"hop.size"option (seeoptions()).- wl
A vector with a single even integer number specifying the window length of the spectrogram. Default
NULL. If supplied,hop.sizeis ignored. Odd integers will be rounded up to the nearest even number. Can be set globally for the current R session via the"wl"option (seeoptions()).- ovlp
Numeric vector of length 1 specifying the percentage of overlap between two consecutive windows, as in
seewave::spectro(). Default70. Can be set globally for the current R session via the"ovlp"option (seeoptions()).- path
Character string containing the directory path where the sound files are found. Only needed when
Xis not an extended selection table. If not supplied the current working directory is used. Can be set globally for the current R session via the"sound.files.path"option (seeoptions()).- n.bins
Numeric vector of length 1 specifying the number of frequency bins to use for representing power spectra. Default
100. IfNULL, the raw power spectrum is used (note that this can result in high RAM memory usage for large data sets). Power spectrum values are interpolated usingstats::approx().
Value
Object X with an additional column, spectrum.correlation,
containing the computed frequency spectrum correlation
coefficients.
Details
The function measures the spectral correlation coefficients of
sounds in which a reference playback has been re-recorded at
increasing distances. Values range from 1 (identical frequency
spectrum, i.e. no degradation) to 0. The sound.id column must be
used to tell the function to only compare sounds belonging to the
same category (e.g. song-types). The function will then compare
each sound to the corresponding reference sound. Two methods for
computing spectral correlation are provided (see the method
argument). The function uses seewave::meanspec() internally to
compute power spectra. Use spectrum_blur_ratio() to extract raw
spectra values. NA is returned if at least one of the power
spectra cannot be computed.
References
Araya-Salas, M., Grabarczyk, E. E., Quiroz-Oliva, M., Garcia-Rodriguez, A., & Rico-Guevara, A. (2025). Quantifying degradation in animal acoustic signals with the R package baRulho. Methods in Ecology and Evolution, 00, 1-12. https://doi.org/10.1111/2041-210X.14481 Apol, C.A., Sturdy, C.B. & Proppe, D.S. (2017). Seasonal variability in habitat structure may have shaped acoustic signals and repertoires in the black-capped and boreal chickadees. Evol Ecol. 32:57-74.
Author
Marcelo Araya-Salas (marcelo.araya@ucr.ac.cr)
Examples
{
# load example data
data("test_sounds_est")
# method 1
# add reference column
Y <- set_reference_sounds(X = test_sounds_est)
# run spectrum correlation
spectrum_correlation(X = Y)
# method 2
Y <- set_reference_sounds(X = test_sounds_est, method = 2)
# spectrum_correlation(X = Y)
}