R/bifreqs_function.R

#' Bifrequencies in the principal domain.
#'
#' The bifreqs function returns a tuple of (k1, k2) pairs
#' which determine the pairs of frequencies where the second order
#' cumulant spectra is calculated to build the statiotest test
#' statistic.
#'
#' @param L A number.
#' @param N A number.
#' @return A matrix of bifrequencies with two columns and number of rows
#' corresponding to how many bifrequencies are in the principal domain,
#' number that depends on the selected frame length L.
#' @examples
#' bifreqs(50, 1000)

#' @export
bifreqs <- function(L = NULL, N = NULL) {

  #we should leave the arguments as is, to have flexibility

  il <- 1
  iu <- floor(L / 2)

  ###########################
  #Calculate the number of 2cum, kc; this will not vary unless
  #il and iu will, which they do if we change L
  #use one of the trapping values il = 1; iu = L/2;

  kc <- 0
  k1 <- 0
  k2 <- 0

  for (k1 in il:iu){
    for (k2 in (({-k1} + 1):(k1 - 1))){
      if (k2 != 0){
        kc <- kc + 1
      }
    }
  }


  ##################################################
  #hold k1 in first col of tup and k2 in second col of tup

  tup2 <- matrix(rep(0 , 2 * kc), nrow = kc, ncol = 2)

  tc <- 0


  for(k1 in ((il + 1):iu)){
    for(k2 in (il:(k1 - 1))){

      tc <- tc + 1 #counts k1, k2 pairs

      tup2[ tc, 1 ] <- k1
      tup2[ tc, 2 ] <- k2

    }# end do over k2
  } #end do over k1

  for (k1 in ((il + 1):iu)){
    for (k2 in (il:(k1 - 1))){

      #tc counts how many k1, k2 pairs
      tc <- tc + 1

      tup2[ tc, 1 ] <- k1
      tup2[ tc, 2 ] <- k2
    }
  }

  #########################################

  tup2

} #bifreqs function
D-Roberts/statiotest documentation built on May 6, 2019, 12:55 p.m.