[Rd] suggested addition to fft man page

Hiroyuki Kawakatsu hkawakat at gmail.com
Sun Jun 1 17:41:31 CEST 2008


Hi,

May I request that the formula for fft() be included in the man page?
This is the second time I had to check what fft() does... In fact,
fft.Rd has
  %%
  %% Here, we should really have a nice  \deqn{}{} giving the definition
  %% of the DFT !
  %%
Below is a suggested snippet (not necessarily "nice") to be added to
fft.Rd; please feel free to improve it.

  %%---begin{hiroyuki}
  \code{y <- fft(z)} returns
  \deqn{y[h] = \sum_{k=1}^n z[k] \exp(-2\pi i (k-1)(h-1)/n)}{%
    y[h] = sum_{k=1}^{n} z[k]*exp(-2*pi*1i*(k-1)*(h-1)/n)}
  for \eqn{h = 1,\ldots,n}{h = 1, ..., n} where n = \code{length(y)}. If
  \code{inverse} is \code{TRUE}, \eqn{\exp(-2\pi\ldots)}{exp(-2*pi...)}
  is replaced with \eqn{\exp(2\pi\ldots)}{exp(2*pi...)}.
  %%---end{hiroyuki}

Thanks for your consideration,
h.
p.s. fft.c was not "readable" so i used the following code to check the formula:

# to check fft formula
fft_slow <- function(z, inverse=FALSE) {
  n <- length(z)
  kdx <- seq(0, n-1)
  sgn <- ifelse(inverse, 1, -1)
  y <- rep(NA, n)
  for (h in 1:n) y[h] <- sum(z*exp(sgn*2*pi*1i*kdx*(h-1)/n))
  y
}

set.seed(1)
n <- 2^3
for (i in 1:10) {
  z <- complex(n, rnorm(n), rnorm(n))
#print(z)
  cat(sprintf("diff(inv=F) = %5.3e, diff(inv=T) = %5.3e\n",
              max(abs(fft(z) - fft_slow(z))),
              max(abs(fft(z, inverse=TRUE) - fft_slow(z, inverse=TRUE)))))
}

-- 
----------------------------------
Hiroyuki Kawakatsu
Business School
Dublin City University
Dublin 9, Ireland
Tel +353 (0)1 700 7496



More information about the R-devel mailing list