# frac_pow_domfreq
#
# Applies a Fast Fourier Transform to a time-series signal and identifies proportion of the power spectrum represented by the dominant frequency (i.e. frequency with the largest modulus)
# Used in Staudenmayer et al 2015 supplementary code, written to be applied using tapply
#
# signal = A time series signal
#
# Library dependencies: N/A
frac.pow.dom.freq <- function(signal, samp_freq = 80)
{
mods <- Mod(fft(signal))
mods <- mods[-1]
n <- length(mods)
n <- floor(n/2)
freq <- samp_freq*(1:n)/(2*n)
mods <- mods[1:n]
rat <- max(mods)/sum(mods)
mods[is.na(mods)] <- 0
if (sd(signal)==0)
rat <- 0
return(rat)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.