getThreshold: Calculate thresholds for rain detection in audio files

View source: R/getThreshold.r

getThresholdR Documentation

Calculate thresholds for rain detection in audio files

Description

Calculate minimum and 2nd quartile thresholds for Power Spectrum Density (PSD) and Signal-to-Noise (s2n) ratio from files known to contain rain, at multiple frequency bands - defaults to 2 bands (0.6-1.2 kHz and 4.4-5.6 kHz). For use by the classifyRain() function in order to detect the presence of rain in audio files

Usage

getThreshold(wav, freqLo = c(0.6, 4.4), freqHi = c(1.2, 5.6), parallel = 0)

Arguments

wav

A vector of wav filenames (including directories) of known rain recordings. Or, the output matrix from getMetrics function.

freqLo

A numeric vector of Lower frequency cut offs for each band.

freqHi

A numeric vector of Higher frequency cut offs for each band.

parallel

Numeric (or logical). Defaults to 0 - no parallel processing. If 'TRUE' will use multicore processing with the parallel package (Windows only; must be loaded), with number of cores - 2. Otherwise, a positive integer specifies number of cores to use. If wav is a single wav object it makes no sense to use parallel here (rather use hardRain functions within a larger parallelised loop).

Value

a matrix of min and Q2 thresholds (rows) for psd and s2n at each band (columns) in freqLo and freqHi

Examples


# Calculate thresholds using 5 files of training data (known rain recordings in wav files).
# Only five files are used here for purposes of this example - but see recommendations in Metcalf et al. 2019

# Get filenames of training data
train.fn <- list.files(system.file("extdata/rain", package = "hardRain"), "\\.wav$", full.names = T)

# Calculate the threshold using default settings
trBR <- getThreshold(train.fn, fn = "spec")
trBR

Cdevenish/hardRain documentation built on Jan. 10, 2025, 3:39 a.m.