From 5d2bbca3c0458eed8728a60596728714ee649cdc Mon Sep 17 00:00:00 2001 From: Michel Crucifix <michel.crucifix@uclouvain.be> Date: Thu, 3 Oct 2024 12:00:07 +0200 Subject: [PATCH] added period axis on standard graph + made print nicer --- R/mfft_real.R | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/R/mfft_real.R b/R/mfft_real.R index 82668ee..9ca1735 100644 --- a/R/mfft_real.R +++ b/R/mfft_real.R @@ -208,9 +208,19 @@ as.data.frame.mfft_deco <- function(x) {data.frame(Freq=x$Freq, Amp=x$Amp, Phase #' @rdname mfft_deco #' @export -plot.mfft_deco <- function (M,...){ +plot.mfft_deco <- function (M,periods=FALSE,...){ # O <- order(M$Freq) - plot(abs(M$Freq), abs(M$Amp),'h',...) + plot(abs(M$Freq), abs(M$Amp),'h',ylab="Amplitudes", xlab="", ...) + if (periods) { + frequencies <- pretty(range(M$Freq/(2*pi))) + labels <- as.character(1/frequencies) + if (0 %in% frequencies) labels[which(frequencies == 0)] = "∞" + axis(1, line=3, at=2*pi*frequencies, labels=labels) + mtext("Rate", 1, 2) + mtext("Period", 1, 4) + } else { + mtext("Rate", 1, 3) + } points(abs(M$Freq), abs(M$Amp),'p',...) } @@ -223,12 +233,10 @@ lines.mfft_deco <- function (M,...){ } - - #' @rdname mfft_deco #' @export print.mfft_deco <- function (M,...){ - print.data.frame(as.data.frame(M)) + print.data.frame(cbind(as.data.frame(M), Period=2*pi/M$Freq)) } -- GitLab