2#include <NDEVR/Buffer.h>
3#include <NDEVR/Angle.h>
14 template<
class t_type>
33 for (
uint04 k = 0; k < size; k++)
34 temp[k + offset] = in_out[k + offset];
35 dft(temp.begin(offset), in_out.begin(offset), size, 1);
38 lib_assert(size % 2 == 0,
"Bad FFT");
40 uint04 even_offset = offset;
41 uint04 odd_offset = offset + size / 2;
44 for (
uint04 k = 0; k < size / 2; k++)
45 temp[k + even_offset] = in_out[2 * k + offset];
48 for (
uint04 k = 0; k < size / 2; k++)
49 temp[k + odd_offset] = in_out[2 * k + 1 + offset];
51 fft(temp, in_out, even_offset, size / 2);
52 fft(temp, in_out, odd_offset, size / 2);
55 for (
uint04 k = 0; k < size / 2; k++)
58 std::complex<t_type> wk(std::cos(kth), std::sin(kth));
59 in_out[k + even_offset] = temp[k + even_offset] + (wk * temp[k + odd_offset]);
60 in_out[k + odd_offset] = temp[k + even_offset] - (wk * temp[k + odd_offset]);
70 static void dft(
const std::complex<t_type> f[], std::complex<t_type> ftilde[],
uint04 N,
uint04 step)
72 std::complex<t_type> w = std::polar(1.0, -2.0 *
PI<t_type>() / N);
73 std::complex<t_type> wn = 1.0;
74 for (
uint04 n = 0; n < N; n++)
77 std::complex<t_type> wm = 1.0;
79 for (
uint04 m = 0, mpos = 0; m < N; m++, mpos += step)
82 ftilde[n] += f[mpos] * wm;
98 for (
uint04 i = 0; i < size; i++)
99 in_out[i + offset] = std::conj(in_out[i + offset]);
102 fft(in_out, temp, offset, size);
105 t_type factor = 1.0 / size;
106 for (
uint04 i = 0; i < size; i++)
107 in_out[i + offset] = std::conj(in_out[i + offset]) * factor;
121 static void iFFT(
const std::complex<t_type> ftilde[], std::complex<t_type> f[],
uint04 N)
124 ftildeConjugate.setSize(N);
126 for (
uint04 m = 0; m < N; m++)
127 ftildeConjugate[m] = std::conj(ftilde[m]);
129 fft(ftildeConjugate, f, N, 1);
131 t_type factor = 1.0 / N;
132 for (
uint04 m = 0; m < N; m++)
133 f[m] = std::conj(f[m]) * factor;
141 static void FT(
Buffer<std::complex<t_type>>& in_out)
144 temp.setSize(in_out.size());
145 fft(in_out, temp, 0, temp.size());
154 temp.setSize(in_out.size());
155 ifft(in_out, temp, 0, temp.size());
The equivelent of std::vector but with a bit more control.
Provides Fast Fourier Transform logic for converting signals between the time and frequency domains.
static void dft(const std::complex< t_type > f[], std::complex< t_type > ftilde[], uint04 N, uint04 step)
Computes the basic Discrete Fourier Transform for arbitrary-length input.
static void ifft(Buffer< std::complex< t_type > > &in_out, Buffer< std::complex< t_type > > &temp, uint04 offset, uint04 size)
Computes the inverse FFT by conjugating, applying the forward FFT, then conjugating and scaling the r...
static void fft(Buffer< std::complex< t_type > > &in_out, Buffer< std::complex< t_type > > &temp, uint04 offset, uint04 size)
Computes the in-place Fast Fourier Transform using the Cooley-Tukey algorithm.
static void IFT(Buffer< std::complex< t_type > > &in_out)
Computes the inverse Fourier Transform on a buffer of complex values in place.
static void iFFT(const std::complex< t_type > ftilde[], std::complex< t_type > f[], uint04 N)
Computes the inverse FFT from a frequency-domain array into a time-domain array.
static void FT(Buffer< std::complex< t_type > > &in_out)
Computes the forward Fourier Transform on a buffer of complex values in place.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
static constexpr t_float_type PI()
Returns the value of PI to a given precision.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.