1 #ifndef MHO_FastFourierTransformUtilities_HH__
2 #define MHO_FastFourierTransformUtilities_HH__
35 static void Conjugate(
unsigned int N, std::complex< XFloatType >* array)
37 for(
unsigned int i = 0; i < N; i++)
39 array[i] = std::conj(array[i]);
51 static void Conjugate(
unsigned int N, std::complex< XFloatType >* array,
unsigned int stride)
53 for(
unsigned int i = 0; i < N; i++)
55 array[i * stride] = std::conj(array[i * stride]);
119 static void FFTRadixTwo_DIT(
unsigned int N, XFloatType* data, XFloatType* twiddle,
unsigned int stride = 1)
123 unsigned int butterfly_width;
124 unsigned int n_butterfly_groups;
125 unsigned int group_start;
126 unsigned int butterfly_index;
127 unsigned int access_stride = 2 * stride;
132 for(
unsigned int stage = 0; stage < logN; stage++)
137 n_butterfly_groups = N / (2 * butterfly_width);
139 for(
unsigned int n = 0; n < n_butterfly_groups; n++)
142 group_start = 2 * n * butterfly_width;
143 for(
unsigned int k = 0; k < butterfly_width; k++)
145 butterfly_index = group_start + k;
146 H0 = data + (access_stride * butterfly_index);
147 H1 = H0 + access_stride * butterfly_width;
148 W = twiddle + 2 * n_butterfly_groups * k;
170 XFloatType H00, H01, H10, H11, W0, W1, alpha_i, alpha_r;
179 alpha_r = W0 * H10 - W1 * H11;
180 alpha_i = W1 * H10 + W0 * H11;
204 static void FFTRadixTwo_DIF(
unsigned int N, XFloatType* data, XFloatType* twiddle,
unsigned int stride = 1)
208 unsigned int butterfly_width;
209 unsigned int n_butterfly_groups;
210 unsigned int group_start;
211 unsigned int butterfly_index;
212 unsigned int access_stride = 2 * stride;
217 for(
unsigned int stage = 0; stage < logN; stage++)
223 butterfly_width = N / (2 * n_butterfly_groups);
224 for(
unsigned int n = 0; n < n_butterfly_groups; n++)
227 group_start = 2 * n * butterfly_width;
228 for(
unsigned int k = 0; k < butterfly_width; k++)
230 butterfly_index = group_start + k;
232 H0 = data + (access_stride * butterfly_index);
233 H1 = H0 + access_stride * butterfly_width;
234 W = twiddle + 2 * n_butterfly_groups * k;
256 XFloatType H00, H01, H10, H11, W0, W1, alpha_i, alpha_r, h1_r, h1_i;
277 alpha_r = W0 * H10 - W1 * H11;
278 alpha_i = W1 * H10 + W0 * H11;
299 static void FFTRadixTwo_DIT(
unsigned int N, std::complex< XFloatType >* data, std::complex< XFloatType >* twiddle,
300 unsigned int stride = 1)
302 FFTRadixTwo_DIT(N, (XFloatType*)&(data[0]), (XFloatType*)&(twiddle[0]), stride);
314 static void FFTRadixTwo_DIF(
unsigned int N, std::complex< XFloatType >* data, std::complex< XFloatType >* twiddle,
315 unsigned int stride = 1)
317 FFTRadixTwo_DIF(N, (XFloatType*)&(data[0]), (XFloatType*)&(twiddle[0]), stride);
333 unsigned int M = 2 * (N - 1);
364 std::complex< XFloatType >* scale, std::complex< XFloatType >* circulant)
367 unsigned int mid = M - N + 1;
368 for(
unsigned int i = 0; i < N; i++)
371 circulant[i] = std::conj(scale[i]);
374 for(
unsigned int i = mid; i < M; i++)
377 circulant[i] = std::conj(scale[M - i]);
380 for(
unsigned int i = N; i < mid; i++)
406 static void FFTBluestein(
unsigned int N,
unsigned int M, std::complex< XFloatType >* data,
407 std::complex< XFloatType >* twiddle, std::complex< XFloatType >* conj_twiddle,
408 std::complex< XFloatType >* scale, std::complex< XFloatType >* circulant,
409 std::complex< XFloatType >* workspace,
unsigned int stride = 1)
414 for(
unsigned int i = 0; i < N; i++)
416 workspace[i] = data[i * stride] * scale[i];
420 for(
unsigned int i = N; i < M; i++)
422 workspace[i] = std::complex< XFloatType >(0.0, 0.0);
428 FFTRadixTwo_DIF(M, (XFloatType*)(&(workspace[0])), (XFloatType*)(&(twiddle[0])));
432 for(
unsigned int i = 0; i < M; i++)
434 workspace[i] *= circulant[i];
440 FFTRadixTwo_DIT(M, (XFloatType*)(&(workspace[0])), (XFloatType*)(&(conj_twiddle[0])));
444 XFloatType norm = 1.0 / ((XFloatType)M);
445 for(
unsigned int i = 0; i < N; i++)
447 data[i * stride] = norm * workspace[i] * scale[i];
470 for(
unsigned int i = 0; i < N; i++)
473 twiddle[i] = std::complex< float >(std::cos((2.0 * M_PI * di) / dN), std::sin((2.0 * M_PI * di) / dN));
491 for(
unsigned int i = 0; i < N; i++)
494 twiddle[i] = std::complex< double >(std::cos((2.0 * M_PI * di) / dN), std::sin((2.0 * M_PI * di) / dN));
507 std::complex< long double >* twiddle)
513 for(
unsigned int i = 0; i < N; i++)
516 twiddle[i] = std::complex< long double >(cosl((2.0 * M_PIl * di) / dN), sinl((2.0 * M_PIl * di) / dN));
533 std::complex< float >* twiddle)
538 for(std::size_t i = 0; i < log2N; i++)
540 twiddle[i] = std::complex< float >(std::cos((2.0 * M_PI * di) / dN), std::sin((2.0 * M_PI * di) / dN));
554 std::complex< double >* twiddle)
559 for(std::size_t i = 0; i < log2N; i++)
561 twiddle[i] = std::complex< double >(std::cos((2.0 * M_PI * di) / dN), std::sin((2.0 * M_PI * di) / dN));
575 std::complex< long double >* twiddle)
580 for(std::size_t i = 0; i < log2N; i++)
582 twiddle[i] = std::complex< long double >(std::cos((2.0 * M_PI * di) / dN), std::sin((2.0 * M_PI * di) / dN));
605 std::complex< float >* scale)
608 float theta = M_PI / ((float)N);
612 for(
unsigned int i = 0; i < N; i++)
614 i2 = i * i % (2 * N);
616 scale[i] = std::complex< float >(std::cos(x), std::sin(x));
636 std::complex< double >* scale)
639 double theta = M_PI / ((double)N);
643 for(
unsigned int i = 0; i < N; i++)
645 i2 = i * i % (2 * N);
647 scale[i] = std::complex< double >(cos(x), sin(x));
667 std::complex< long double >* scale)
670 long double theta = M_PIl / ((
long double)N);
674 for(
unsigned int i = 0; i < N; i++)
676 i2 = i * i % (2 * N);
678 scale[i] = std::complex< long double >(cosl(x), sinl(x));
static unsigned int NextLowestPowerOfTwo(unsigned int N)
Calculates the next lowest power of two for a given unsigned integer.
Definition: MHO_BitReversalPermutation.cc:35
static unsigned int TwoToThePowerOf(unsigned int N)
Calculates 2 raised to the power of N using bit shifting.
Definition: MHO_BitReversalPermutation.cc:29
static bool IsPowerOfTwo(unsigned int N)
Checks if an unsigned integer is a power of two.
Definition: MHO_BitReversalPermutation.cc:10
static unsigned int LogBaseTwo(unsigned int N)
Calculates the logarithm base two of an unsigned integer N using bitwise operations.
Definition: MHO_BitReversalPermutation.cc:17
Definition: MHO_ChannelLabeler.hh:17