Here I am going to show how to detect signals using the awesome package monitoR. What I am showing here is similar but much less detailed than the quick start vignette of the monitoR package. So I encourage to look at the vignette if you want to learn more about it.

This package searches for the signals in sound files using previously defined templates. It can search for several templates in the same run. I will show how the package works using the sound files and data examples that come with the warbleRpackage. These are recordings from long-billed hermits, each one singing a diferent song type.

First we need to load the packages:

library(warbleR)
library(monitoR)

We need to create the templates. We just have to select and example from each sound file and provide the start and end as well as the frequency range of the signal. We will load the long-billed hermit sound:

#write files in temporal file
# setwd(file.path(tempdir()))

# load sound files and data
data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "manualoc.df"))

#write files to disk
writeWave(Phae.long1,"Phae.long1.wav")
writeWave(Phae.long2,"Phae.long2.wav")
writeWave(Phae.long3,"Phae.long3.wav")
writeWave(Phae.long4,"Phae.long4.wav")

and create the templates:

phae1T1<-makeCorTemplate("Phae.long1.wav", t.lim=c(manualoc.df$start[2],manualoc.df$end[2]),wl = 300,ovlp=90,
    frq.lim=c(1, 11), dens=1, name="phae11")

## 
## Automatic point selection.
## 
## Done.
phae2T1<-makeCorTemplate("Phae.long2.wav", t.lim=c(manualoc.df$start[5],manualoc.df$end[5]),wl = 300,ovlp=90,
       frq.lim=c(1, 11), dens=1, name="phae21")

## 
## Automatic point selection.
## 
## Done.
phae3T1<-makeCorTemplate("Phae.long3.wav", t.lim=c(manualoc.df$start[7],manualoc.df$end[7]),wl = 300,ovlp=90,
       frq.lim=c(1, 11), dens=1, name="phae31")

## 
## Automatic point selection.
## 
## Done.
phae4T1<-makeCorTemplate("Phae.long4.wav", t.lim=c(manualoc.df$start[9],manualoc.df$end[9]),wl = 300,ovlp=90,
       frq.lim=c(1, 11), dens=1, name="phae41")

## 
## Automatic point selection.
## 
## Done.

Now we put together all templates in a single object:

ctemps<-combineCorTemplates(phae1T1, phae2T1, phae3T1, phae4T1)

Now that we have the templates we can search fo those “acoustic patterns” in a sound file. As the function usese cross-correlation to determine the similarity to the templates we need to select a correlation method. In this case we use pearson correlation. Lets do it first with the template from the Phae.long1.wav file

cm<-"pearson"
cscoresPhae1<-corMatch(survey = "Phae.long1.wav",templates = phae1T1, parallel = T,show.prog = F, time.source = "fileinfo",
                  cor.method = cm,warn=F,write.wav = T)
## 
## Starting  phae11 . . .
##  Fourier transform on survey . . .
##  Continuing. . .
## 
##  Done.

And now lets look at the results detecting each template in its original file:

cdetectsPhae1<-findPeaks(cscoresPhae1, parallel = TRUE)
## 
## Done with  phae11
## Done
# View results
plot(cdetectsPhae1, hit.marker="points")

We can do the same for each sound file:

cscoresPhae2<-corMatch(survey = "Phae.long2.wav",templates = phae2T1, parallel = T,show.prog = F, time.source = "fileinfo",
                  cor.method = cm,warn=F,write.wav = T)
## 
## Starting  phae21 . . .
##  Fourier transform on survey . . .
##  Continuing. . .
## 
##  Done.
cdetectsPhae2<-findPeaks(cscoresPhae2, parallel = TRUE)
## 
## Done with  phae21
## Done
# View results
plot(cdetectsPhae2, hit.marker="points")

cscoresPhae3<-corMatch(survey = "Phae.long3.wav",templates = phae3T1, parallel = T,show.prog = F, time.source = "fileinfo",
                  cor.method = cm,warn=F,write.wav = T)
## 
## Starting  phae31 . . .
##  Fourier transform on survey . . .
##  Continuing. . .
## 
##  Done.
cdetectsPhae3<-findPeaks(cscoresPhae3, parallel = TRUE)
## 
## Done with  phae31
## Done
# View results
plot(cdetectsPhae3, hit.marker="points")

cscoresPhae4<-corMatch(survey = "Phae.long4.wav",templates = phae4T1, parallel = T,show.prog = F, time.source = "fileinfo",
                  cor.method = cm,warn=F,write.wav = T)
## 
## Starting  phae41 . . .
##  Fourier transform on survey . . .
##  Continuing. . .
## 
##  Done.
cdetectsPhae4<-findPeaks(cscoresPhae4, parallel = TRUE)
## 
## Done with  phae41
## Done
# View results
plot(cdetectsPhae4, hit.marker="points")

We can also run all templates on a single sound file:

cscoresPhae4all<-corMatch(survey = "Phae.long1.wav",templates = ctemps, parallel = T,show.prog = F, time.source = "fileinfo",
                  cor.method = cm,warn=F,write.wav = T)
## 
## Starting  phae11 . . .
##  Fourier transform on survey . . .
##  Continuing. . .
## 
##  Done.
## 
## Starting  phae21 . . .
##  Done.
## 
## Starting  phae31 . . .
##  Done.
## 
## Starting  phae41 . . .
##  Done.
cdetectsPhae4all<-findPeaks(cscoresPhae4all, parallel = TRUE)
## 
## Done
# View results
plot(cdetectsPhae4all, hit.marker="points")