| activity | R Documentation |
Calculate the Acoustic Activity Matrix using the methodology proposed in Burivalova 2018
activity(
soundfile,
channel = "stereo",
timeBin = 60,
dbThreshold = -90,
targetSampRate = NULL,
wl = 512,
window = signal::hamming(wl),
overlap = ceiling(length(window)/2),
histbreaks = "FD",
DCfix = TRUE,
powthr = 10,
bgnthr = 0.8,
beta = TRUE
)
soundfile |
tuneR Wave object or path to a valid audio |
channel |
channel where the saturation values will be extract from. Available channels are: |
timeBin |
size (in seconds) of the time bin. Set to |
dbThreshold |
minimum allowed value of dB for the spectrograms. Set to |
targetSampRate |
desired sample rate of the audios. This argument is only used to down sample the audio. If |
wl |
window length of the spectrogram. Defaults to |
window |
window used to smooth the spectrogram. Switch to |
overlap |
overlap between the spectrogram windows. Defaults to |
histbreaks |
breaks used to calculate Background Noise. Available breaks are: |
DCfix |
if the DC offset should be removed before the metrics are calculated. Defaults to |
powthr |
single numeric value to calculate the activity matrix for soundscape power (in dB). Defaults to |
bgnthr |
single numeric value to calculate the activity matrix for background noise (in %). Defaults to |
beta |
how BGN thresholds are calculated. If |
To calculate the activity matrix, we use the methodology proposed by Burivalova 2018. We begin by applying the following formula to each time bin of the recording:
a_{mf} = 1\ if (BGN_{mf} > \theta_{1})\ or\ (POW_{mf} > \theta_{2});\ otherwise,\ a_{mf} = 0,
Where \theta_{1} equals the threshold of BGN values and \theta_{2} equals the threshold of dB values. We set 1 to active and 0 to inactive frequency windows.
This function returns a 0 and 1 matrix containing the activity for all time bins of the inputted file. The matrix's number of rows will equal to half the set window length (wl) and number of columns will equal the number of bins. Cells with the value of 1 represent the acoustically active frequency of a bin.
Burivalova, Z., Towsey, M., Boucher, T., Truskinger, A., Apelis, C., Roe, P., & Game, E. T. (2018). Using soundscapes to detect variable degrees of human influence on tropical forests in Papua New Guinea. Conservation Biology, 32(1), 205-215. https://doi.org/10.1111/cobi.12968
if (require("ggplot2")) {
library(ggplot2)
# We are going to load a sample noise.matrix object to demonstrate the basic usage of singleSat()
# To understand about the origin of this noise.matrix, check: ?sampleBGN
data("sampleBGN")
# View the sample noise.matrix object
sampleBGN
# Run the function
sat <- activity(sampleBGN)
# Now we can plot the results for the left channel
satLeft <- sat[,1:3]
satDim <- dim(satLeft)
numericTime <- seq(0, sum(sampleBGN@timeBins), by = sampleBGN@timeBins[1])
labels <- paste0(numericTime[-length(numericTime)], "-", numericTime[-1], "s")
satDF <- data.frame(BIN = rep(paste0("BIN", seq(satDim[2])), each = satDim[1]),
WIN = rep(seq(satDim[1]), satDim[2]),
ACT = factor(c(sat), levels = c(0,1)))
ggplot(satDF, aes(x = BIN, y = WIN, fill = ACT)) +
geom_tile() +
theme_bw() +
scale_fill_manual(values = c("white", "black")) +
scale_y_continuous(expand = c(0,0)) +
scale_x_discrete(expand = c(0,0), labels = labels) +
labs(x = "Time Bin", y = "Spectral Window") +
guides(fill = guide_legend(title = "Activity"))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.