getEntropy: Entropy

Description Usage Arguments Details Value Examples

View source: R/utilities_math.R

Description

Internal soundgen function.

Usage

1
getEntropy(x, type = c("weiner", "shannon")[1], normalize = FALSE)

Arguments

x

vector of non-negative floats, e.g. a power spectrum. NB: all non-negative values are recoded as 1e-10!

type

'shannon' for Shannon (information) entropy, 'weiner' for Weiner entropy

normalize

if TRUE, Shannon entropy is normalized by the length of input vector to range from 0 to 1. It has no affect on Weiner entropy.

Details

Returns Weiner or Shannon entropy of an input vector such as a power spectrum. Non-negative input values are recoded as as a small positive number (1e-10). If all elements are zero, returns NA.

Value

Float between 0 and 1 or NA

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Here are four simplified power spectra, each with 9 frequency bins:
s = list(
  c(rep(0, 4), 1, rep(0, 4)),       # a single peak in spectrum
  c(0, 0, 1, 0, 0, .75, 0, 0, .5),  # perfectly periodic, with 3 harmonics
  rep(0, 9),                        # a silent frame
  rep(1, 9)                         # white noise
)

# Weiner entropy is ~0 for periodic, NA for silent, 1 for white noise
sapply(s, function(x) round(soundgen:::getEntropy(x), 2))

# Shannon entropy is ~0 for periodic with a single harmonic, moderate for
# periodic with multiple harmonics, NA for silent, highest for white noise
sapply(s, function(x) round(soundgen:::getEntropy(x, type = 'shannon'), 2))

# Normalized Shannon entropy - same but forced to be 0 to 1
sapply(s, function(x) round(soundgen:::getEntropy(x,
  type = 'shannon', normalize = TRUE), 2))

tatters/soundgen_beta documentation built on May 14, 2019, 9 a.m.