rfft function

ArrayComplex rfft(
  1. Array x, {
  2. dynamic n,
})

Compute the one-dimensional discrete Fourier Transform for a Real input.

  • x An Array with the input
  • n : optional 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 is used. return An ArrayComplex with FFT output

References

1 "Fast Fourier Transform". https://rosettacode.org/wiki/Fast_Fourier_transform#C++. Retrieved 2019-07-23. 2. "what is numpy fft rfft and numpy fft irfft and its equivalent code in matlab". https://stackoverflow.com/questions/45778504/what-is-numpy-fft-rfft-and-numpy-fft-irfft-and-its-equivalent-code-in-matlab. Retrieved 2019-07-23.

Examples

var x = Array([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0]);

print(rfft(x));

Implementation

ArrayComplex rfft(Array x, {n}) {
  var buffer = arrayToComplexArray(x);
  var afft = fft(buffer, n: n);
  return afft.getRangeArray(0, (afft.length / 2).floor() + 1); //  return afft;
}