R/dfDTW.R
dfDTW.RddfDTW calculates acoustic dissimilarity of dominant frequency contours using dynamic
time warping. Internally it applies the dtwDist function from the dtw package.
dfDTW(X = NULL, wl = 512, wl.freq = 512, length.out = 20, wn = "hanning", ovlp = 70, bp = c(0, 22), threshold = 15, threshold.time = NULL, threshold.freq = NULL, img = TRUE, parallel = 1, path = NULL, ts.df = NULL, img.suffix = "dfDTW", pb = TRUE, clip.edges = TRUE, window.type = "none", open.end = FALSE, scale = FALSE, frange.detec = FALSE, fsmooth = 0.1, adjust.wl = TRUE, ...)
| 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. |
| wl.freq | A numeric vector of length 1 specifying the window length of the spectrogram for measurements on the frequency spectrum. Default is 512. Higher values would provide more accurate measurements. |
| length.out | A numeric vector of length 1 giving the number of measurements of dominant 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 dominant frequency detection. Default is 15. |
| threshold.time | amplitude threshold (%) for the time domain. Use for dominant frequency detection. If |
| threshold.freq | amplitude threshold (%) for the frequency domain. Use for frequency range detection from the spectrum (see 'frange.detec'). If |
| 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 |
| ts.df | Optional. Data frame with frequency contour time series of signals to be compared. If provided "X" is ignored. |
| img.suffix | A character vector of length 1 with a suffix (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 |
| frange.detec | Logical. Controls whether frequency range of signal is automatically
detected using the |
| fsmooth | A numeric vector of length 1 to smooth the frequency spectrum with a mean
sliding window (in kHz) used for frequency range detection (when |
| adjust.wl | 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 dominant frequencies.
This function extracts the dominant frequency values as a time series and
then calculates the pairwise acoustic dissimilarity using dynamic time warping.
The function uses the approx function to interpolate values between dominant
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 dominant frequencies.
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 and dfts, ffts, ffDTW for frequency contour overlaid spectrograms.
blog post on DTW similarity
Other spectrogram creators:
color.spectro(),
dfts(),
ffDTW(),
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 dfDTW(lbh_selec_table, length.out = 30, flim = c(1, 12), bp = c(2, 9), wl = 300, path = tempdir()) }#> Phae.long1.wav-1 Phae.long1.wav-2 Phae.long1.wav-3 #> Phae.long1.wav-1 0.000 7.272 11.403 #> Phae.long1.wav-2 7.272 0.000 11.796 #> Phae.long1.wav-3 11.403 11.796 0.000 #> Phae.long2.wav-1 26.382 29.085 26.069 #> Phae.long2.wav-2 29.848 35.795 28.625 #> Phae.long3.wav-1 16.493 16.577 17.314 #> Phae.long3.wav-2 15.936 18.143 17.879 #> Phae.long3.wav-3 28.997 30.793 28.669 #> Phae.long4.wav-1 39.502 36.727 41.317 #> Phae.long4.wav-2 33.201 32.440 32.360 #> Phae.long4.wav-3 30.884 31.481 31.163 #> Phae.long2.wav-1 Phae.long2.wav-2 Phae.long3.wav-1 #> Phae.long1.wav-1 26.382 29.848 16.493 #> Phae.long1.wav-2 29.085 35.795 16.577 #> Phae.long1.wav-3 26.069 28.625 17.314 #> Phae.long2.wav-1 0.000 13.817 14.612 #> Phae.long2.wav-2 13.817 0.000 14.928 #> Phae.long3.wav-1 14.612 14.928 0.000 #> Phae.long3.wav-2 13.467 12.457 7.492 #> Phae.long3.wav-3 13.696 11.293 10.941 #> Phae.long4.wav-1 21.663 28.508 34.870 #> Phae.long4.wav-2 24.228 30.853 32.414 #> Phae.long4.wav-3 22.699 32.104 29.358 #> Phae.long3.wav-2 Phae.long3.wav-3 Phae.long4.wav-1 #> Phae.long1.wav-1 15.936 28.997 39.502 #> Phae.long1.wav-2 18.143 30.793 36.727 #> Phae.long1.wav-3 17.879 28.669 41.317 #> Phae.long2.wav-1 13.467 13.696 21.663 #> Phae.long2.wav-2 12.457 11.293 28.508 #> Phae.long3.wav-1 7.492 10.941 34.870 #> Phae.long3.wav-2 0.000 10.575 29.015 #> Phae.long3.wav-3 10.575 0.000 24.246 #> Phae.long4.wav-1 29.015 24.246 0.000 #> Phae.long4.wav-2 28.587 25.428 9.646 #> Phae.long4.wav-3 25.851 26.609 15.328 #> Phae.long4.wav-2 Phae.long4.wav-3 #> Phae.long1.wav-1 33.201 30.884 #> Phae.long1.wav-2 32.440 31.481 #> Phae.long1.wav-3 32.360 31.163 #> Phae.long2.wav-1 24.228 22.699 #> Phae.long2.wav-2 30.853 32.104 #> Phae.long3.wav-1 32.414 29.358 #> Phae.long3.wav-2 28.587 25.851 #> Phae.long3.wav-3 25.428 26.609 #> Phae.long4.wav-1 9.646 15.328 #> Phae.long4.wav-2 0.000 8.372 #> Phae.long4.wav-3 8.372 0.000