twiddleFactors function

Float64x2List twiddleFactors(
  1. int n
)

Returns the twiddle factors for an FFT of size n. Aka the complex n-th roots of 1.

Implementation

Float64x2List twiddleFactors(int n) {
  final twiddles = Float64x2List(n);
  final dt = -2 * math.pi / n;
  final half = n ~/ 2;
  for (int i = 0; i <= half; ++i) {
    final t = i * dt;
    twiddles[i] = Float64x2(math.cos(t), math.sin(t));
  }
  for (int i = (n + 1) ~/ 2; i < n; ++i) {
    final a = twiddles[n - i];
    twiddles[i] = Float64x2(a.x, -a.y);
  }
  return twiddles;
}