R/ffDTW.R
ffDTW.RdffDTW calculates acoustic dissimilarity of fundamental frequency contours using dynamic
time warping. Internally it applies the dtwDist function from the dtw package.
ffDTW(X, wl = 512, length.out = 20, wn = "hanning", ovlp = 70, bp = c(0, 22), threshold = 5, img = TRUE, parallel = 1, path = NULL, img.suffix = "ffDTW", pb = TRUE, clip.edges = TRUE, window.type = "none", open.end = FALSE, scale = FALSE, ...)
| X | object of class 'selection_table', 'extended_selection_table' or data frame containing columns for sound file name (sound.files),
selection number (selec), and start and end time of signal (start and end).
The output of |
|---|---|
| wl | A numeric vector of length 1 specifying the window length of the spectrogram, default is 512. |
| length.out | A numeric vector of length 1 giving the number of measurements of fundamental frequency desired (the length of the time series). |
| wn | Character vector of length 1 specifying window name. Default is
"hanning". See function |
| ovlp | Numeric vector of length 1 specifying % of overlap between two
consecutive windows, as in |
| bp | A numeric vector of length 2 for the lower and upper limits of a frequency bandpass filter (in kHz). Default is c(0, 22). |
| threshold | amplitude threshold (%) for fundamental frequency detection. Default is 5. |
| img | Logical argument. If |
| 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). |
| path | Character string containing the directory path where the sound files are located.
If |
| img.suffix | A character vector of length 1 with a sufix (label) to add at the end of the names of
image files. Default is |
| pb | Logical argument to control progress bar. Default is |
| clip.edges | Logical argument to control whether edges (start or end of signal) in
which amplitude values above the threshold were not detected will be removed. If
|
| window.type |
|
| open.end |
|
| scale | Logical. If |
| ... | Additional arguments to be passed to |
A matrix with the pairwise dissimilarity values. If img is
FALSE it also produces image files with the spectrograms of the signals listed in the
input data frame showing the location of the fundamental frequencies.
This function extracts the fundamental frequency values as a time series and
then calculates the pairwise acoustic dissimilarity of the selections using dynamic time warping.
The function uses the approx function to interpolate values between fundamental
frequency measures. If 'img' is TRUE the function also produces image files
with the spectrograms of the signals listed in the input data frame showing the
location of the fundamental frequencies. Note that if no amplitude is detected at the beginning or end
of the signals then NAs will be generated. On the other hand, if amplitude is not detected in between signal
segments in which amplitude was detected then the values of this adjacent segments will be interpolated to fill out the missing values (e.g. no NAs in between detected amplitude segments).
Araya-Salas, M., & Smith-Vidaurre, G. (2017). warbleR: An R package to streamline analysis of animal acoustic signals. Methods in Ecology and Evolution, 8(2), 184-191.
specreator for creating spectrograms from selections,
snrspecs for creating spectrograms to
optimize noise margins used in sig2noise
Other spectrogram creators:
color.spectro(),
dfDTW(),
dfts(),
ffts(),
multi_DTW(),
phylo_spectro(),
snrspecs(),
sp.en.ts(),
specreator(),
trackfreqs()
{ #load data data(list = c("Phae.long1", "Phae.long2","lbh_selec_table")) writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav")) #save sound files writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav")) # run function ffDTW(lbh_selec_table[1:4,], length.out = 30, flim = c(1, 12), img = TRUE, bp = c(1, 9), wl = 300, path = tempdir()) }#> Phae.long1.wav-1 Phae.long1.wav-2 Phae.long1.wav-3 #> Phae.long1.wav-1 0.000 16.859 22.810 #> Phae.long1.wav-2 16.859 0.000 13.009 #> Phae.long1.wav-3 22.810 13.009 0.000 #> Phae.long2.wav-1 17.365 84.824 35.844 #> Phae.long2.wav-1 #> Phae.long1.wav-1 17.365 #> Phae.long1.wav-2 84.824 #> Phae.long1.wav-3 35.844 #> Phae.long2.wav-1 0.000