diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 60ec641..4a4d21b 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -21,8 +21,7 @@ include_directories(${GTEST_INCLUDE_DIR}) find_package(PkgConfig REQUIRED) pkg_search_module(FFTW REQUIRED fftw3) include_directories(${FFTW_INCLUDE_DIRS}) -FILE(GLOB commonSources ${ROOT_DIR}/Src/common/FFT.cpp - ${ROOT_DIR}/Src/common/algorithms.cpp) +FILE(GLOB commonSources ${ROOT_DIR}/Src/common/FFT.cpp) function(gen_test app_name test_file) add_executable(${app_name} diff --git a/Tests/common/test_fft.cpp b/Tests/common/test_fft.cpp index 576eadd..be15abb 100644 --- a/Tests/common/test_fft.cpp +++ b/Tests/common/test_fft.cpp @@ -5,15 +5,15 @@ */ #include +#include #include // For std::clamp #include #include // For std::fabs #include // for tuple - #include "FFT.hpp" unsigned int seed = 1; - +std::random_device rd; // Will be used to obtain a seed for the random number engine template auto IsInRange(T lo, T hi) { return AllOf(Ge((lo)), Le((hi))); @@ -99,18 +99,17 @@ class MultiSignalsSinGenerator { void init() { signals_generator.resize(n_signals); uint16_t max_amplitude = 0; + std::uniform_int_distribution dist(0, max_freq); + for (int j = 0; j < n_signals; j++) { - uint16_t freq_hz = std::rand() % (max_freq - min_freq) + min_freq; - uint16_t amplitude = 1 + std::rand() % 100; + uint16_t freq_hz = dist(rd) % (max_freq - min_freq) + min_freq; + uint16_t amplitude = 1 + dist(rd) % 100; signals_generator[j] = SinSignalGenerator(sample_rate_hz, freq_hz, amplitude); if (amplitude > max_amplitude) { max_amplitude = amplitude; dominant_sig.insert(dominant_sig.begin(), std::make_tuple(amplitude, freq_hz)); } } - for (auto dominant : dominant_sig) { - std::cout <<"dominant freq: " << std::get<1>(dominant) << "\n"; - } // sort by amplitude value std::sort(dominant_sig.begin(), dominant_sig.end()); } @@ -223,8 +222,9 @@ class TestFFTOneSignalParametrized : public TestFFTBase dist(0, 8); + auto n_updates = (dist(rd) % 8 + 2) * fft_parameters.window_size; for (int i = 0; i < n_updates + 10; i++) { for (int j = 0; j < fft_parameters.n_axes; j++) { input[j] = signals_generator[j].get_next_sample(); } fft.update(input); } - print_fft_results(); + // To print FFT results for debug uncomment the following line + // print_fft_results(); for (int axis = 0; axis < fft_parameters.n_axes; axis++) { check_axis(axis); } @@ -323,8 +326,9 @@ class TestFFTOnMultiSignalsParametrized : public TestFFTBase(dominant)) << "\n"; } - std::cout << "peak freq: \n"; for (int peak_index = 0; peak_index < MAX_NUM_PEAKS; peak_index++) { - std::cout << fft.peak_frequencies[axis][peak_index] << "\n"; for (auto dominant : signal_generator.dominant_sig) { if (IsBetweenInclusive(fft.peak_frequencies[axis][peak_index], (int)std::get<1>(dominant) - abs_error,