This function computes the inverse of the one-dimensional n-point discrete Fourier transform computed by fft using a wrapper of fft(z, inverse= TRUE)/length(z) with an extra argument making it similar to numpy.fft.ifft. For a general description of the algorithm and definitions, see stats::fft and numpy.fft.

sig_ifft(x, n = NULL)



A vector


Length of the transformed axis of the output. If n is smaller than the length of the input, the input is cropped. If it is larger, the input is padded with zeros. If n is not given, the length of the input along the axis specified by axis is used.


A vector


The input should be ordered in the same way as is returned by fft, i.e., (if I converted the indexes from python correctly)

  • a[1] should contain the zero frequency term,

  • a[2:ceiling(n/2)] should contain the positive-frequency terms,

  • a[ceiling(n/2) + 2:length(a)] should contain the negative-frequency terms, in increasing order starting from the most negative frequency.

  • For an even number of input points, a[ceiling(n/2)] represents the sum of the values at the positive and negative Nyquist frequencies, as the two are aliased together. See see numpy.fft for details.


If the input parameter n is larger than the size of the input, the input is padded by appending zeros at the end. Even though this is the common approach, it might lead to surprising results. If a different padding is desired, it must be performed before calling ifft.


a <- c(0, 4, 0, 0)
#> [1]  1+0i  0+1i -1+0i  0-1i
sig_ifft(sig_fft(a)) == a