From de108397947ac48aa3beeabe6caacb4d873d6f96 Mon Sep 17 00:00:00 2001 From: Guillaume Courrier Date: Tue, 26 Nov 2019 18:01:16 +0100 Subject: [PATCH] Finalisation de l'algorithme de calcul de la FFT --- tests/examples/test-fft.cpp | 41 +++++++++++++++++++++++++++++++++++-- tests/src/math.hpp | 31 +++++++++++++++------------- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/tests/examples/test-fft.cpp b/tests/examples/test-fft.cpp index 1531742..fb759e0 100644 --- a/tests/examples/test-fft.cpp +++ b/tests/examples/test-fft.cpp @@ -1,13 +1,50 @@ #include #include +#include +#include + +void create_plot_file(std::string filename, const math::csignal& tfd) { + std::ofstream data_file(filename + ".data"); + for (int i=0; i 1) { + n = atoi(argv[1]); + } for (int i=0; i<100; ++i) { - s.push_back(std::sin(2*math::pi()*50*i/100)); + s.push_back(math::complex(std::sin(2*math::pi()*f0*float(i)/fe), 0)); } - math::csignal tfd = math::fft(s); + math::csignal tfd; + clock_t begin = std::clock(); + + for (int i=0; i #include #include -#include namespace math { @@ -44,41 +43,45 @@ namespace math { csignal fft_rec(const csignal& input) { int size = input.size(); - if (size == 1) { + if (size <= 1) { return input; } else { csignal odd; csignal even; - std::back_insert_iterator odd_back_it(odd); - std::back_insert_iterator even_back_it(even); + auto odd_back_it = std::back_inserter(odd); + auto even_back_it = std::back_inserter(even); bool insert_in_even = false; for (auto it = input.begin(); it != input.end(); ++it) { if (insert_in_even) { - *even_back_it++ = *it; + *(even_back_it++) = *it; insert_in_even = false; } else { - *odd_back_it++ = *it; + *(odd_back_it++) = *it; insert_in_even = true; } } csignal odd_fft = fft_rec(odd); csignal even_fft = fft_rec(even); - csignal res; - res.reserve(size); + csignal res(size, complex()); - for (int k = 0; k