6#ifndef THEORETICA_FFT_H
7#define THEORETICA_FFT_H
9#include "../core/bit_op.h"
10#include "../algebra/algebra_types.h"
11#include "../algebra/algebra.h"
12#include "../complex/complex.h"
28 template<
typename ReturnVector = cvec,
typename InputVector = cvec>
29 inline ReturnVector
fft(
const InputVector& x,
bool inverse =
false) {
33 const unsigned int N = x.size();
37 const unsigned int log2N =
ilog2(N);
40 if (N != (
unsigned int) (1 << log2N)) {
48 for (
unsigned int p = 1; p <= log2N; p++) {
50 const unsigned int m = 1 << p;
51 const unsigned int offset = m / 2;
53 complex<real> w (1.0, 0.0);
56 const complex<real> phase = complex<real>(
57 cos(sign * 2 *
PI / m),
58 sin(sign * 2 *
PI / m)
61 for (
unsigned int j = 0; j < offset; j++) {
63 for (
unsigned int i = j; i < N; i += m) {
65 const complex<real> t = w * k[i + offset];
66 k[i + offset] = k[i] - t;
87 template<
typename ReturnVector = cvec,
typename InputVector = cvec>
88 inline ReturnVector
ifft(
const InputVector& k) {
Vector & vec_error(Vector &v)
Overwrite the given vector with the error vector with NaN values.
Definition algebra.h:62
ReturnVector fft(const InputVector &x, bool inverse=false)
Compute the Fast Fourier Transform of a set of data points.
Definition fft.h:29
ReturnVector ifft(const InputVector &k)
Compute the Inverse Fast Fourier Transform of a set of data points.
Definition fft.h:88
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
double real
A real number, defined as a floating point type.
Definition constants.h:198
complex< T > inverse(complex< T > z)
Compute the conjugate of a complex number.
Definition complex_analysis.h:35
UnsignedIntType ilog2(UnsignedIntType x)
Find the integer logarithm of x.
Definition real_analysis.h:550
dual2 cos(dual2 x)
Compute the cosine of a second order dual number.
Definition dual2_functions.h:86
dual2 sin(dual2 x)
Compute the sine of a second order dual number.
Definition dual2_functions.h:72
constexpr real PI
The Pi mathematical constant.
Definition constants.h:216
void swap_bit_reverse(Vector &x, unsigned int m)
Swap the elements of a vector pair-wise, by exchanging elements with indices related by bit reversion...
Definition bit_op.h:90