File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,19 @@ using std::size_t;
20
20
using complex = std::complex<double >;
21
21
static const double pi = 3.14159265358979323846264338327950288419716 ;
22
22
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
+
23
36
// `cooley_tukey` does the cooley-tukey algorithm, recursively
24
37
template <typename Iter>
25
38
void cooley_tukey (Iter first, Iter last) {
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ In the end, the code looks like:
119
119
{% sample lang="c" %}
120
120
[ import:20-39, lang:"c_cpp"] ( code/c/fft.c )
121
121
{% sample lang="cpp" %}
122
- [ import:27-57 , lang:"c_cpp"] ( code/c++/fft.cpp )
122
+ [ import:36-67 , lang:"c_cpp"] ( code/c++/fft.cpp )
123
123
{% sample lang="hs" %}
124
124
[ import:6-19, lang:"haskell"] ( code/haskell/fft.hs )
125
125
{% sample lang="py" %}
You can’t perform that action at this time.
0 commit comments