Here I show how to use the dfDTW function in warbleR to compare acoustics signals using dynamic time warping (DTW).

First load these packages (if not installed the code will install it):

and load example data from warbleR

These recordings all come from long-billed hermits with different song types.

We can run the DTW analysis to compare these time series usin the warbleR function dfDTW which calculates the dominant frequency contours of each sgnals and compares using dynamic time warping. Internally it applies the dtwDist function from the dtw package.

Let’s see if the dissimilarity from dtw represents the acoutic differences. First we need a binary matrix representing same recording with 0s, and different recording with 1s. The following functions does exactly that:

these 2 matrices can be compared with a mantel test:

As you can see there is a strong association between song type variation and acoustic similarity measured by means of DTW.

What about its performance compare to a more standard method like measuring a bunch of acoustic parameters?
We can calculate “acoustic distance” using acoustic parameters and then correlate it to the “recording id” matrix

Looks like DTW represents the acoustic variation a little better, although both methods produce significant correlations with relatively high mantel r’s.

DTW and acoustic parameter distances are also correlated: