-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from jkennel/master
Multivariate psd methods thanks to @jkennel
- Loading branch information
Showing
29 changed files
with
1,242 additions
and
121 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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#' coherence | ||
#' | ||
#' calculate coherency from the spectra and cross-spectra | ||
#' | ||
#' @param pgram \code{numeric array} must be multivariate | ||
#' | ||
#' | ||
#' @return list of coherency | ||
#' | ||
#' @export | ||
#' | ||
#' | ||
coherence <- function(pgram) { | ||
|
||
dims = dim(pgram) | ||
n_ser <- dims[2] | ||
n_r <- dims[1] | ||
|
||
if (n_ser == 1) { | ||
warning('Cannot calculate coherency for a single periodogram') | ||
return(NA) | ||
} | ||
|
||
coh <- matrix(NA_real_, nrow = n_r, ncol = (n_ser - 1)) | ||
|
||
for (i in 2L:(n_ser)) { | ||
coh[, i-1] <- Re(Mod(pgram[, 1, i])^2 / (pgram[, 1, 1] * pgram[, i, i])) | ||
} | ||
|
||
return(coh) | ||
} | ||
|
||
#' phase | ||
#' | ||
#' calculate phase from the spectra and cross-spectra | ||
#' | ||
#' @param pgram \code{numeric array} must be multivariate | ||
#' | ||
#' | ||
#' @return list of phase | ||
#' | ||
#' @export | ||
#' | ||
phase <- function(pgram) { | ||
|
||
dims = dim(pgram) | ||
n_ser <- dims[2] | ||
n_r <- dims[1] | ||
|
||
if (n_ser == 1) { | ||
warning('Cannot calculate phase for a single periodogram') | ||
return(NA) | ||
} | ||
|
||
phase <- matrix(NA_real_, nrow = n_r, ncol = (n_ser - 1)) | ||
|
||
for (i in 2L:(n_ser)) { | ||
|
||
phase[, i-1] <- Arg(pgram[, 1, i]) | ||
|
||
} | ||
|
||
return(phase) | ||
} |
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
Oops, something went wrong.