Skip to content
Extraits de code Groupes Projets
Valider 5feb65ad rédigé par Michel Crucifix's avatar Michel Crucifix
Parcourir les fichiers

mffft

parent 199394e5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -5,6 +5,7 @@ S3method(lines,mfft_deco)
S3method(plot,SSAObject)
S3method(plot,memObject)
S3method(plot,mfft_deco)
S3method(plot,mmfft)
S3method(plot,periodogram)
S3method(plot,wavelet)
S3method(print,mfft_deco)
......
......@@ -26,6 +26,7 @@ mmfft <- function(xdata, seglength = length(xdata) %/% 16, ...){
}
#' @rdname mmfft
#' @export
plot.mmfft <- function(x){
freqrange <-
c(min(sapply(x, function(xs) min(xs$Freq))),
......@@ -35,7 +36,6 @@ plot.mmfft <- function(x){
c(min(sapply(x, function(xs) min(xs$Amp))),
max(sapply(x, function(xs) max(xs$Amp))))
print(amprange)
amp2lwd <- function(amp){ 3*amp/amprange[2] }
length <- attr(x, "nsections") *
......@@ -48,17 +48,13 @@ plot.mmfft <- function(x){
tstart <- attr(x,"start")
tend <- tstart + nsec * tsec
print(freqrange)
print(c(tstart, tend))
plot(c(tstart, tend), freqrange, type='n', xlab='Time', ylab='Rate')
for (iseq in seq(nsec)){
trange <- tstart + c(iseq-1,iseq)*tsec
obj <- x[[iseq]]
nfreq <- length(obj$Freq)
print(obj$Amp)
lwds <- sapply(obj$Amp, amp2lwd)
print(lwds)
for (j in seq(nfreq)){
lines(trange, rep(obj$Freq[j],2), lwd=lwds[j])
}
......@@ -66,7 +62,3 @@ plot.mmfft <- function(x){
}
......@@ -6,6 +6,7 @@
#' @importFrom RcppAlgos comboGeneral
#' @param omegas: vector of references frequencies, optionally with rownames,
#' @param keepPositives : if TRUE, then only keeps positive combinations of frequencies
#' @param fractions : defaults 1. Set 2 to include double-periods, and 3 triple-periods.
#' @return a vector with combination of tones and explicit rownames, using, if available, the
#' rownames provided in the input vector omega
#' @author Michel Crucifix
......@@ -14,7 +15,24 @@
#' omegas <- c( 0.123, 0.14312, 0.33251, 0.554313)
#' print(toneCombinations(omegas))
toneCombinations <- function(omegas, keepPositives=TRUE){
toneCombinations <- function(omegas, fractions=1, keepPositives=TRUE){
if (fractions == 2){
local({
tmp <- c(as.numeric(omegas), as.numeric(omegas)/2)
names(tmp) <- c(names(omegas), sprintf("%s/2", names(omegas)))
omegas <<- tmp
})
}
if (fractions == 3){
local({
tmp <- c(as.numeric(omegas), as.numeric(omegas)/2, as.numeric(omegas)/3)
names(tmp) <- c(names(omegas), sprintf("%s/2", names(omegas)), sprintf("%s/3", names(omegas)))
omegas <<- tmp
})
}
twoomegas <- c(-omegas,omegas)
indices <- c(-seq(length(omegas)), seq(length(omegas)))
result = rbind(
......@@ -75,6 +93,7 @@ generate_name <- function(invec,char="s", labels = NULL){
#'
#' @param infreq : input frequencies
#' @param omegas : reference frequencies (a numeric vector which may contain explicit row names)
#' @param fractions : 1, 2, or 3 depending on willing to include singe, double or triple periods
#' @param tol1 : acceptable tolerance for being considered as a certain attribution
#' (if several frequencies match the criteria, the closest will be taken)
#' @param tol2 : acceptable tolerance for being considered as a likely or plausible
......@@ -93,9 +112,9 @@ generate_name <- function(invec,char="s", labels = NULL){
#' plot(outfreqs, outamps, type='h')
#' text(outfreqs, outamps+0.1, attributions)
#'
attributeTones <- function(infreq , omegas, tol1 = 1.e-6, tol2 = 1.e-4) {
attributeTones <- function(infreq , omegas, fractions=1, tol1 = 1.e-6, tol2 = 1.e-4) {
attributions <- rep("", length(infreq))
combis <- toneCombinations(omegas)
combis <- toneCombinations(omegas, fractions=fractions)
for (i in seq(infreq)){
deltas <- abs(infreq[i] - combis)
bestSuspect <- which.min(abs(infreq[i] - combis))
......
......@@ -4,13 +4,15 @@
\alias{attributeTones}
\title{Attribution of combination of tones}
\usage{
attributeTones(infreq, omegas, tol1 = 1e-06, tol2 = 1e-04)
attributeTones(infreq, omegas, fractions = 1, tol1 = 1e-06, tol2 = 1e-04)
}
\arguments{
\item{infreq}{: input frequencies}
\item{omegas}{: reference frequencies (a numeric vector which may contain explicit row names)}
\item{fractions}{: 1, 2, or 3 depending on willing to include singe, double or triple periods}
\item{tol1}{: acceptable tolerance for being considered as a certain attribution
(if several frequencies match the criteria, the closest will be taken)}
......
......@@ -4,9 +4,11 @@
\alias{toneCombinations}
\title{Generation of combination of tones}
\usage{
toneCombinations(omegas, keepPositives = TRUE)
toneCombinations(omegas, fractions = 1, keepPositives = TRUE)
}
\arguments{
\item{fractions}{: defaults 1. Set 2 to include double-periods, and 3 triple-periods.}
\item{keepPositives}{: if TRUE, then only keeps positive combinations of frequencies}
\item{omegas:}{vector of references frequencies, optionally with rownames,}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter