2#include <NDEVR/Buffer.h>
3#include <NDEVR/Angle.h>
14 template<
class t_type>
26 for (
uint04 k = 0; k < size; k++)
27 temp[k + offset] = in_out[k + offset];
28 dft(temp.begin(offset), in_out.begin(offset), size, 1);
33 uint04 even_offset = offset;
34 uint04 odd_offset = offset + size / 2;
37 for (
uint04 k = 0; k < size / 2; k++)
38 temp[k + even_offset] = in_out[2 * k + offset];
41 for (
uint04 k = 0; k < size / 2; k++)
42 temp[k + odd_offset] = in_out[2 * k + 1 + offset];
44 fft(temp, in_out, even_offset, size / 2);
45 fft(temp, in_out, odd_offset, size / 2);
48 for (
uint04 k = 0; k < size / 2; k++)
51 std::complex<t_type> wk(std::cos(kth), std::sin(kth));
52 in_out[k + even_offset] = temp[k + even_offset] + (wk * temp[k + odd_offset]);
53 in_out[k + odd_offset] = temp[k + even_offset] - (wk * temp[k + odd_offset]);
57 static void dft(
const std::complex<t_type> f[], std::complex<t_type> ftilde[],
uint04 N,
uint04 step)
59 std::complex<t_type> w = std::polar(1.0, -2.0 * PI<t_type>() / N);
60 std::complex<t_type> wn = 1.0;
61 for (
uint04 n = 0; n < N; n++)
64 std::complex<t_type> wm = 1.0;
66 for (
uint04 m = 0, mpos = 0; m < N; m++, mpos += step)
69 ftilde[n] += f[mpos] * wm;
78 for (
uint04 i = 0; i < size; i++)
79 in_out[i + offset] = std::conj(in_out[i + offset]);
82 fft(in_out, temp, offset, size);
85 t_type factor = 1.0 / size;
86 for (
uint04 i = 0; i < size; i++)
87 in_out[i + offset] = std::conj(in_out[i + offset]) * factor;
95 static void iFFT(
const std::complex<t_type> ftilde[], std::complex<t_type> f[],
uint04 N)
100 for (
uint04 m = 0; m < N; m++)
101 ftildeConjugate[m] = std::conj(ftilde[m]);
103 fft(ftildeConjugate, f, N, 1);
105 t_type factor = 1.0 / N;
106 for (
uint04 m = 0; m < N; m++)
107 f[m] = std::conj(f[m]) * factor;
111 static void FT(
Buffer<std::complex<t_type>>& in_out)
115 fft(in_out, temp, 0, temp.
size());
#define lib_assert(expression, message)
Definition LibAssert.h:61
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
constexpr t_index_type size() const
Definition Buffer.hpp:823
void setSize(t_index_type new_size)
Definition Buffer.hpp:803
Logic for implenting Fast Fourier Transform, a mathematical algorithm that converts signals from the ...
Definition FFT.h:16
static void iFFT(const std::complex< t_type > ftilde[], std::complex< t_type > f[], uint04 N)
Definition FFT.h:95
static void fft(Buffer< std::complex< t_type > > &in_out, Buffer< std::complex< t_type > > &temp, uint04 offset, uint04 size)
Definition FFT.h:19
static void IFT(Buffer< std::complex< t_type > > &in_out)
Definition FFT.h:117
static void dft(const std::complex< t_type > f[], std::complex< t_type > ftilde[], uint04 N, uint04 step)
Definition FFT.h:57
static void ifft(Buffer< std::complex< t_type > > &in_out, Buffer< std::complex< t_type > > &temp, uint04 offset, uint04 size)
Definition FFT.h:75
static void FT(Buffer< std::complex< t_type > > &in_out)
Definition FFT.h:111
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149