Skip to content

Commit 84f7b3d

Browse files
committed
Implement dft
1 parent b9acf8c commit 84f7b3d

File tree

1 file changed

+13
-0
lines changed
  • contents/cooley_tukey/code/c++

1 file changed

+13
-0
lines changed

contents/cooley_tukey/code/c++/fft.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ using std::size_t;
2020
using complex = std::complex<double>;
2121
static const double pi = 3.14159265358979323846264338327950288419716;
2222

23+
template <typename Iter>
24+
void dft(Iter X, Iter last) {
25+
const auto N = last - X;
26+
std::vector<complex> tmp(N);
27+
for (auto i = 0; i < N; ++i) {
28+
for (auto j = 0; j < N; ++j) {
29+
using namespace std::literals::complex_literals;
30+
tmp[i] += X[j] * exp(-2.0 * M_PI * i * j / N * 1i);
31+
}
32+
}
33+
std::copy(std::begin(tmp), std::end(tmp), X);
34+
}
35+
2336
// `cooley_tukey` does the cooley-tukey algorithm, recursively
2437
template <typename Iter>
2538
void cooley_tukey(Iter first, Iter last) {

0 commit comments

Comments
 (0)