Compare signals from selection tables to a set of templates using cross-correlation
Posted on January 12, 2019
I got the following question about cross-correlation:
“We would like to compare every call within a selection table to a template of each owl, and get peak correlation coefficients on each call separately”
One way to do this would be putting the unidentified and template signals together into a single selection table, and then running cross-correlation. However, this will also compare all unidentified signals against each other, which can be very inefficient. A better way would be running a loop that compares each row in a selection table to the set of template songs and then put the results back into the selection table. This post shows how to do exactly that.
First set up the example data and global options:
We’ll use the example data set from the NatureSounds package. This data has long-billed hermit songs from different song types (see ‘lek.song.type’ column). Check out the full description of the data here.
The first step is to create an example selection table for unidentified songs (or calls if working with owl vocalizations) and another one for the template songs. In the following code we get 3 examples for each song type in the (extended) selection table (unk.songs) and 1 of each song type in a template set (tempts):
We can look at the spectrograms for the 2 sets as follows:
As you can see the templates have a single example of each of the 3 song types in the ‘unk.songs’ selection table.
Now we have to create a routine that will compare each row in the ‘unk.songs’ selection table to each template and put the results in a data frame:
Let’s take a look at the output (excluding irrelevant columns):
The last 3 columns show the cross-correlation scores for each of the 3 templates, respectively. Note that the highest scores correspond to the templates belonging to the same song type category (highllighted cells).
The code can go faster by using parallel computing. This can be done using the pblapply function (instead of lapply) from the pbapply package setting the argument cl.