R/jitter.R

Defines functions jitter_rel jitter_abs jitter

Documented in jitter

#' Calculate the jitter in a Wave object
#'
#' Jitter is a measure of the variability of periods in the waveform. Relative
#' jitter is scaled by the jitter in the analysed waveform.
#'
#' @param wave A Wave object
#' @param method One of "absolute" or "relative"
#' @export
#' @return A vector of zero crossing locations
#' @examples
#' \dontrun{
#' jitter(sheep, method="absolute")
#' jitter(sheep, method="relative")
#' }
jitter <- function(wave, method="absolute") {
  if (method=="absolute") {
    return(jitter_abs(wave))
  }
  if (method=="relative") {
    return(jitter_rel(wave))
  }
}

jitter_abs <- function(wave)  {
  validateIsWave(wave)
  zc <- zerocross(wave)
  t <- diff(zc)
  n <- length(t)

  j <- sum(abs(diff(t))) / (n - 1)
  return(j)
}

jitter_rel <- function(wave) {
  validateIsWave(wave)
  zc <- zerocross(wave)
  t <- diff(zc)
  n <- length(t)

  j <- sum(abs(diff(t))) / (n - 1)
  j <- j/mean(t)
  return(j)
}

Try the sonicscrewdriver package in your browser

Any scripts or data that you put into this service are public.

sonicscrewdriver documentation built on May 2, 2021, 5:06 p.m.