Skip to content

Commit

Permalink
fix missing link to seewave::meanspec
Browse files Browse the repository at this point in the history
  • Loading branch information
maRce10 committed Mar 2, 2024
1 parent 69fafb8 commit 93c0658
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/excess_attenuation.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @return Object 'X' with an additional column, 'excess.attenuation', containing the computed excess attenuation values (in dB).
#' @export
#' @name excess_attenuation
#' @details Excess attenuation is the amplitude loss of a sound in excess due to spherical spreading (observed attenuation - expected attenuation). With every doubling of distance, sounds attenuate with a 6 dB loss of amplitude (Morton, 1975; Marten & Marler, 1977). Any additional loss of amplitude results in energy loss in excess of that expected to occur with distance via spherical spreading. So it represents power loss due to additional factors like vegetation or atmospheric conditions (Wiley & Richards, 1978). Low values indicate little additional attenuation. The goal of the function is to measure the excess attenuation on sounds in which a reference playback has been re-recorded at increasing distances. The 'sound.id' column must be used to indicate which sounds belonging to the same category (e.g. song-types). The function will then compare each sound type to the corresponding reference sound. Two approaches for computing excess attenuation are provided (see 'type' argument).
#' @details Excess attenuation is the amplitude loss of a sound in excess due to spherical spreading (observed attenuation - expected attenuation). With every doubling of distance, sounds attenuate with a 6 dB loss of amplitude (Morton, 1975; Marten & Marler, 1977). Any additional loss of amplitude results in energy loss in excess of that expected to occur with distance via spherical spreading. So it represents power loss due to additional factors like vegetation or atmospheric conditions (Wiley & Richards, 1978). Low values indicate little additional attenuation. The goal of the function is to measure the excess attenuation on sounds in which a reference playback has been re-recorded at increasing distances. The 'sound.id' column must be used to indicate which sounds belonging to the same category (e.g. song-types). The function will then compare each sound type to the corresponding reference sound. Two approaches for computing excess attenuation are provided (see 'type' argument). NAs will be returned if one of the envelopes is completely flat (e.g. no variation in amplitude).
#' @examples {
#' # load example data
#' data("test_sounds_est")
Expand Down
23 changes: 19 additions & 4 deletions R/internal_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,10 @@
)$y
}

# add little variation if all values ar the same so measurements can be taken on in (like envelope correlation)
if (all(nv == nv[1]))
nv[1] <- nv[1] + 0.0001

return(nv)
}

Expand Down Expand Up @@ -1256,12 +1260,11 @@
)
}


sig_env <- if (!rms)
# convert into envelope using warbleR if no rms
sig_env <- if (!rms)
mean(warbleR::envelope(x = clp@left)) else
seewave::rms(warbleR::envelope(x = clp@left))


return(sig_env)
}

Expand Down Expand Up @@ -1320,6 +1323,9 @@
ea <- (-20 * log10(sig_env_REF / X$sig_env[y])) - (20 * log10(1 / dist_SIG))
}

if (is.infinite(ea))
ea <- NA

return(ea)
}

Expand Down Expand Up @@ -1549,7 +1555,11 @@

# get RMS for signal
sig_rms <- seewave::rms(warbleR::envelope(signal[, 1]))


# convert to 0.0001 if sig_rms is 0 to avoid errors in SNR measurements
if (sig_rms == 0)
sig_rms <- 0.0001

# cut ambient noise before sound
noise1 <-
seewave::cutw(noise_sig,
Expand All @@ -1559,6 +1569,11 @@

# get RMS for background noise
bg_rms <- seewave::rms(warbleR::envelope(noise1[, 1]))

# convert to 0.0001 if bg_rms is 0 to avoid errors in SNR measurements
if (bg_rms == 0)
bg_rms <- 0.0001

}
} else {
sig_rms <- NA
Expand Down
5 changes: 3 additions & 2 deletions R/signal_to_noise_ratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' with the signal-to-noise ratio values (in dB).
#' @export
#' @name signal_to_noise_ratio
#' @details Signal-to-noise ratio (SNR) measures sound amplitude level in relation to ambient noise. Noise is measured on the background noise immediately before the test sound. A general margin in which ambient noise will be measured must be specified. Alternatively, a selection of ambient noise can be used as reference (see 'noise.ref' argument). When margins overlap with another sound nearby, SNR will be inaccurate, so margin length should be carefully considered. Any SNR less than or equal to one suggests background noise is equal to or overpowering the sound. The function will measure signal-to-noise ratio within the supplied frequency range (e.g. bandpass) of the reference signal ('bottom.freq' and 'top.freq' columns in 'X') by default (that is, when \code{bp = 'freq.range'}.
#' @details Signal-to-noise ratio (SNR) measures sound amplitude level in relation to ambient noise. Noise is measured on the background noise immediately before the test sound. A general margin in which ambient noise will be measured must be specified. Alternatively, a selection of ambient noise can be used as reference (see 'noise.ref' argument). When margins overlap with another sound nearby, SNR will be inaccurate, so margin length should be carefully considered. Any SNR less than or equal to one suggests background noise is equal to or overpowering the sound. The function will measure signal-to-noise ratio within the supplied frequency range (e.g. bandpass) of the reference signal ('bottom.freq' and 'top.freq' columns in 'X') by default (that is, when \code{bp = 'freq.range'}. SNR can be ~0 when both tail and signal have very low amplitude.
#' @examples {
#' # load example data
#' data("test_sounds_est")
Expand Down Expand Up @@ -86,6 +86,7 @@ signal_to_noise_ratio <-
path = path,
header = TRUE
)$sample.rate


# adjust wl based on hop.size
wl <- .adjust_wl(wl, X, hop.size, path)
Expand Down Expand Up @@ -118,7 +119,7 @@ signal_to_noise_ratio <-
}

# 'mar' is needed when not using equal duration
if (!eq.dur & is.null(mar)) {
if (!eq.dur & is.null(mar) & noise.ref == "adjacent") {
.stop("'mar' must be supplied when 'eq.dur = FALSE'")
}

Expand Down
2 changes: 1 addition & 1 deletion R/spcc.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spcc <-
comp_mat <- cbind(X$.sgnl.temp, X$reference)

# remove NA rows
comp_mat <- comp_mat[stats::complete.cases(comp_mat),]
comp_mat <- comp_mat[stats::complete.cases(comp_mat), , drop = FALSE]


# save previous warbleR options
Expand Down
11 changes: 9 additions & 2 deletions R/tail_to_signal_ratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' with the tail-to-signal ratio values (in dB).
#' @export
#' @name tail_to_signal_ratio
#' @details Tail-to-signal ratio (TSR) measures the ratio of power in the tail of reverberations to that in the test sound. A general margin in which reverberation tail will be measured must be specified. The function will measure TSR within the supplied frequency range (e.g. bandpass) of the reference sound ('bottom.freq' and 'top.freq' columns in 'X'). Two methods for computing reverberations are provided (see 'tsr.formula' argument). Note that 'tsr.formula' 2 is not equivalent to the original description of TSR in Dabelsteen et al. (1993) and is better referred to as tail-to-noise ratio. Tail-to-signal ratio values are typically negative as signals tend to have higher power than that in the reverberating tail.
#' @details Tail-to-signal ratio (TSR) measures the ratio of power in the tail of reverberations to that in the test sound. A general margin in which reverberation tail will be measured must be specified. The function will measure TSR within the supplied frequency range (e.g. bandpass) of the reference sound ('bottom.freq' and 'top.freq' columns in 'X'). Two methods for computing reverberations are provided (see 'tsr.formula' argument). Note that 'tsr.formula' 2 is not equivalent to the original description of TSR in Dabelsteen et al. (1993) and is better referred to as tail-to-noise ratio. Tail-to-signal ratio values are typically negative as signals tend to have higher power than that in the reverberating tail. TSR can be ~0 when both tail and signal have very low amplitude.
#' @examples {
#' # load example data
#'
Expand Down Expand Up @@ -195,10 +195,17 @@ tail_to_signal_ratio <- function(X,
# sound (or noise) RMS
sig_RMS <- seewave::rms(sig.env)

# get reference ambient noise RMS
# convert to 0.0001 if sig_RMS is 0 to avoid errors in STR measurements
if (sig_RMS == 0)
sig_RMS <- 0.0001

# get reference ambient noise RMS
tail_RMS <- seewave::rms(tail.env)

# convert to 0.0001 if tail_RMS is 0 to avoid errors in STR measurements
if (tail_RMS == 0)
tail_RMS <- 0.0001

# Calculate tail.to.signal ratio
str <- tail_RMS / sig_RMS

Expand Down
2 changes: 1 addition & 1 deletion man/excess_attenuation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/signal_to_noise_ratio.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/tail_to_signal_ratio.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vignettes/align_test_sounds.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ opts_chunk$set(fig.align = "center",

<img src="baRulho_sticker.png" alt="baRulho sticker" align="right" width = "25%" height="25%"/>


This vignette shows deals with two things: how to create synthetic sounds for playback experiments and how to align re-recorded sounds to their reference once playback has been conducted. Here is some terms that will be used in this vignettes and throughout the package.

&nbsp;

<div class="alert alert-info">

<font size="5">Glossary</font>
Expand Down
2 changes: 1 addition & 1 deletion vignettes/quantify_degradation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ sc

### Noise profiles

The function `noise_profile()` allows to estimate the frequency spectrum of ambient noise. This can be done on extended selection tables (using the segments containing no sound) or over entire sound files in the working directory (or path supplied). The function uses \code{\link[seewave]{meanspec}} internally to calculate frequency spectra. The following code measures the ambient noise profile for the recordings at distance >= 5m on the example extended selection table:
The function `noise_profile()` allows to estimate the frequency spectrum of ambient noise. This can be done on extended selection tables (using the segments containing no sound) or over entire sound files in the working directory (or path supplied). The function uses the seewave function `meanspec()` internally to calculate frequency spectra. The following code measures the ambient noise profile for the recordings at distance >= 5m on the example extended selection table:

```{r, eval = TRUE}
Expand Down

0 comments on commit 93c0658

Please sign in to comment.