Bluestein’s Algorithm is an algorithm that computes for a polynomial in time and space.

Algorithm

Lemma

Let

then

  1. Let . Apply the Fast Fourier Transform to find and .
  2. Use the results from 0 to find .
  3. Apply the Inverse Fast Fourier Transform to find .
  4. For each in , apply the lemma to find .

This algorithm solves the problem in time and space.

std::vector<std::complex<double>> bluestein(int n, const std::vector<std::complex<double>> &a, std::complex<double> z, int m) {
	std::vector<std::complex<double>> f(n);
	for (int i = 0; i < n; i++) {
		f[n - i - 1] = a[i] / std::pow(z, 1. * i * i / 2);
	}
	std::vector<std::complex<double>> g(n + m);
	for (int i = 0; i < n + m; i++) {
		g[i] = std::pow(z, 1. * i * i / 2);
	}
 
	int k = std::bit_ceil<u32>(2 * n + m - 1);
	f.resize(k, 0), g.resize(k, 0);
	fft(k, f), fft(k, g);
	for (int i = 0; i < k; i++) {
		f[i] *= g[i];
	}
	ifft(k, f);
 
	std::vector<std::complex<double>> res(m);
	for (int i = 0; i < m; i++) {
		res[i] = f[n - 1 + i] / std::pow(z, 1. * i * i / 2);
	}
	return res;
}