2#include <NDEVR/Buffer.h>
3#include <NDEVR/Angle.h>
11 template<
class t_type>
23 for (
uint04 k = 0; k < size; k++)
24 temp[k + offset] = in_out[k + offset];
25 dft(temp.begin(offset), in_out.begin(offset), size, 1);
30 uint04 even_offset = offset;
31 uint04 odd_offset = offset + size / 2;
34 for (
uint04 k = 0; k < size / 2; k++)
35 temp[k + even_offset] = in_out[2 * k + offset];
38 for (
uint04 k = 0; k < size / 2; k++)
39 temp[k + odd_offset] = in_out[2 * k + 1 + offset];
41 fft(temp, in_out, even_offset, size / 2);
42 fft(temp, in_out, odd_offset, size / 2);
45 for (
uint04 k = 0; k < size / 2; k++)
48 std::complex<t_type> wk(std::cos(kth), std::sin(kth));
49 in_out[k + even_offset] = temp[k + even_offset] + (wk * temp[k + odd_offset]);
50 in_out[k + odd_offset] = temp[k + even_offset] - (wk * temp[k + odd_offset]);
54 static void dft(
const std::complex<t_type> f[], std::complex<t_type> ftilde[],
uint04 N,
uint04 step)
56 std::complex<t_type> w = std::polar(1.0, -2.0 * PI<t_type>() / N);
57 std::complex<t_type> wn = 1.0;
58 for (
uint04 n = 0; n < N; n++)
61 std::complex<t_type> wm = 1.0;
63 for (
uint04 m = 0, mpos = 0; m < N; m++, mpos += step)
66 ftilde[n] += f[mpos] * wm;
75 for (
uint04 i = 0; i < size; i++)
76 in_out[i + offset] = std::conj(in_out[i + offset]);
79 fft(in_out, temp, offset, size);
82 t_type factor = 1.0 / size;
83 for (
uint04 i = 0; i < size; i++)
84 in_out[i + offset] = std::conj(in_out[i + offset]) * factor;
92 static void iFFT(
const std::complex<t_type> ftilde[], std::complex<t_type> f[],
uint04 N)
97 for (
uint04 m = 0; m < N; m++)
98 ftildeConjugate[m] = std::conj(ftilde[m]);
100 fft(ftildeConjugate, f, N, 1);
102 t_type factor = 1.0 / N;
103 for (
uint04 m = 0; m < N; m++)
104 f[m] = std::conj(f[m]) * factor;
108 static void FT(
Buffer<std::complex<t_type>>& in_out)
112 fft(in_out, temp, 0, temp.
size());
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
constexpr t_index_type size() const
Definition Buffer.hpp:1461
void setSize(t_index_type new_size)
Definition Buffer.hpp:1413
static void iFFT(const std::complex< t_type > ftilde[], std::complex< t_type > f[], uint04 N)
Definition FFT.h:92
static void fft(Buffer< std::complex< t_type > > &in_out, Buffer< std::complex< t_type > > &temp, uint04 offset, uint04 size)
Definition FFT.h:16
static void IFT(Buffer< std::complex< t_type > > &in_out)
Definition FFT.h:114
static void dft(const std::complex< t_type > f[], std::complex< t_type > ftilde[], uint04 N, uint04 step)
Definition FFT.h:54
static void ifft(Buffer< std::complex< t_type > > &in_out, Buffer< std::complex< t_type > > &temp, uint04 offset, uint04 size)
Definition FFT.h:72
static void FT(Buffer< std::complex< t_type > > &in_out)
Definition FFT.h:108
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181