-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
110 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
#' Beat spectrum complexity | ||
#' | ||
#' This function computes a \code{beatSpectrum} and calculates some basic measurements of its complexity. | ||
#' The complexity value is calculated as the maximum identified repeating period (in seconds) divided by | ||
#' the number of peaks. | ||
#' | ||
#' @param wave A Wave object | ||
#' @param plot If TRUE a spectorgram overlaid with the peaks is plotted. | ||
#' @return A list of the complexity, a vector of the peak periods, and the number of peaks. | ||
#' @examples | ||
#' \dontrun{ | ||
#' beatComplexity(sheep) | ||
#' beatComplexity(sheep, plot=TRUE) | ||
#' } | ||
#' @export | ||
#' | ||
|
||
beatComplexity <-function( | ||
wave, | ||
plot=FALSE | ||
) { | ||
bs <- beatSpectrum(wave) | ||
#bs$power <- bs$power / max(bs$power) | ||
|
||
e <- c(0,diff(sign(diff(bs$power))),0) | ||
|
||
bs <- beatSpectrum(wave) | ||
|
||
|
||
e <- c(0,diff(sign(diff(bs$power))),0) | ||
peaks <- e==-2 | ||
|
||
if (plot) { | ||
plot(bs$period, bs$power, type="l") | ||
plot(bs$period, bs$power, type="l") | ||
abline(v=bs$period[peaks], col="green") | ||
} | ||
|
||
c <- max(bs$period[peaks]) / length(peaks) | ||
|
||
#ToDo: return period range, number of peaks as list | ||
return(c) | ||
|
||
} | ||
|
||
r <- list( | ||
"complexity" = max(bs$period[peaks]) / length(bs$period[peaks]), | ||
"peak.periods" = bs$period[peaks], | ||
"num.peaks" = length(bs$period[peaks]) | ||
) | ||
return(r) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.