MCPcopy Create free account
hub / github.com/algorithm-archivists/algorithm-archive / main

Function main

contents/cooley_tukey/code/cpp/fft.cpp:109–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109int main() {
110 // initalize the FFT inputs
111 std::random_device random_device;
112 std::mt19937 rng(random_device());
113 std::uniform_real_distribution<double> distribution(0.0, 1.0);
114
115 std::array<complex, 64> initial;
116 std::generate(
117 begin(initial), end(initial), [&] { return distribution(rng); });
118
119 auto recursive = initial;
120 auto iterative = initial;
121
122 // Preform an FFT on the arrays.
123 cooley_tukey(begin(recursive), end(recursive));
124 iterative_cooley_tukey(begin(iterative), end(iterative));
125
126 // Check if the arrays are approximately equivalent
127 std::cout << std::right << std::setw(16) << "idx" << std::setw(16) << "rec"
128 << std::setw(16) << "it" << std::setw(16) << "subtracted" << '\n';
129 for (size_t i = 0; i < initial.size(); ++i) {
130 auto rec = recursive[i];
131 auto it = iterative[i];
132 std::cout << std::setw(16) << i << std::setw(16) << std::abs(rec)
133 << std::setw(16) << std::abs(it) << std::setw(16)
134 << (std::abs(rec) - std::abs(it)) << '\n';
135 }
136}

Callers

nothing calls this directly

Calls 5

absFunction · 0.85
cooley_tukeyFunction · 0.70
iterative_cooley_tukeyFunction · 0.70
sizeMethod · 0.65
generateFunction · 0.50

Tested by

no test coverage detected