diff --git a/CMakeLists.txt b/CMakeLists.txt index ccb689a..66fb76a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ add_executable(blah2 ${PROJECT_SOURCE_DIR}/process/detection/Centroid.cpp ${PROJECT_SOURCE_DIR}/process/detection/Interpolate.cpp ${PROJECT_SOURCE_DIR}/process/spectrum/SpectrumAnalyser.cpp + ${PROJECT_SOURCE_DIR}/process/meta/HammingNumber.cpp ${PROJECT_SOURCE_DIR}/data/IqData.cpp ${PROJECT_SOURCE_DIR}/data/Map.cpp ${PROJECT_SOURCE_DIR}/data/Detection.cpp @@ -74,6 +75,7 @@ include_directories("${PROJECT_SOURCE_DIR}/process/ambiguity/") include_directories("${PROJECT_SOURCE_DIR}/process/clutter/") include_directories("${PROJECT_SOURCE_DIR}/process/detection/") include_directories("${PROJECT_SOURCE_DIR}/process/spectrum/") +include_directories("${PROJECT_SOURCE_DIR}/process/meta/") include_directories("${PROJECT_SOURCE_DIR}/data/") include_directories("${PROJECT_SOURCE_DIR}/data/meta/") @@ -82,6 +84,7 @@ add_executable(testAmbiguity ${PROJECT_TEST_DIR}/unit/process/ambiguity/TestAmbiguity.cpp ${PROJECT_SOURCE_DIR}/data/IqData.cpp ${PROJECT_SOURCE_DIR}/data/Map.cpp - ${PROJECT_SOURCE_DIR}/process/ambiguity/Ambiguity.cpp) + ${PROJECT_SOURCE_DIR}/process/ambiguity/Ambiguity.cpp + ${PROJECT_SOURCE_DIR}/process/meta/HammingNumber.cpp) target_link_libraries(testAmbiguity catch2 fftw3 fftw3_threads) set_target_properties(testAmbiguity PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_TEST_DIR}") diff --git a/src/process/ambiguity/Ambiguity.cpp b/src/process/ambiguity/Ambiguity.cpp index 05ddf3e..6a3d683 100644 --- a/src/process/ambiguity/Ambiguity.cpp +++ b/src/process/ambiguity/Ambiguity.cpp @@ -183,45 +183,6 @@ Map> *Ambiguity::process(IqData *x, IqData *y) return map_.get(); } -/** - * @brief Hamming number generator - * - * @author Nigel Galloway - * @cite https://rosettacode.org/wiki/Hamming_numbers - * @todo Can this be done with constexpr??? - */ -class HammingGenerator { -private: - std::vector _H, _hp, _hv, _x; -public: - bool operator!=(const HammingGenerator &other) const { return true; } - HammingGenerator begin() const { return *this; } - HammingGenerator end() const { return *this; } - unsigned int operator*() const { return _x.back(); } - HammingGenerator(const std::vector &pfs) : _H(pfs), _hp(pfs.size(), 0), _hv({pfs}), _x({1}) {} - const HammingGenerator &operator++() - { - for (int i = 0; i < _H.size(); i++) - for (; _hv[i] <= _x.back(); _hv[i] = _x[++_hp[i]] * _H[i]) - ; - _x.push_back(_hv[0]); - for (int i = 1; i < _H.size(); i++) - if (_hv[i] < _x.back()) - _x.back() = _hv[i]; - return *this; - } -}; - - -uint32_t next_hamming(uint32_t value) { - for (auto i : HammingGenerator({2,3,5})) { - if (i > value) { - return i; - } - } - return 0; -} - std::ostream& operator<<(std::ostream& str, const Ambiguity::PerformanceStats& stats) { return str << "Total time: " << stats.process_time_ms << "ms\n" << "Range FFT time: " << stats.range_fft_time_ms << "ms\n" << diff --git a/src/process/ambiguity/Ambiguity.h b/src/process/ambiguity/Ambiguity.h index 5c0dc06..5d93094 100644 --- a/src/process/ambiguity/Ambiguity.h +++ b/src/process/ambiguity/Ambiguity.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -126,9 +127,4 @@ private: PerformanceStats latest_performance_; }; -/// @brief Calculate the next 5-smooth Hamming Number larger than value -/// @param value Value to round -/// @return value rounded to Hamming number -uint32_t next_hamming(uint32_t value); - std::ostream& operator<<(std::ostream& str, const Ambiguity::PerformanceStats& stats); \ No newline at end of file diff --git a/src/process/meta/HammingNumber.cpp b/src/process/meta/HammingNumber.cpp new file mode 100644 index 0000000..5621159 --- /dev/null +++ b/src/process/meta/HammingNumber.cpp @@ -0,0 +1,40 @@ +#include "HammingNumber.h" + +bool HammingNumber::operator!=(const HammingNumber &other) const { + return true; +} + +HammingNumber HammingNumber::begin() const { + return *this; +} + +HammingNumber HammingNumber::end() const { + return *this; +} + +unsigned int HammingNumber::operator*() const { + return _x.back(); +} + +HammingNumber::HammingNumber(const std::vector &pfs) + : _H(pfs), _hp(pfs.size(), 0), _hv({pfs}), _x({1}) {} + +const HammingNumber &HammingNumber::operator++() { + for (int i = 0; i < _H.size(); i++) + for (; _hv[i] <= _x.back(); _hv[i] = _x[++_hp[i]] * _H[i]) + ; + _x.push_back(_hv[0]); + for (int i = 1; i < _H.size(); i++) + if (_hv[i] < _x.back()) + _x.back() = _hv[i]; + return *this; +} + +uint32_t next_hamming(uint32_t value) { + for (auto i : HammingNumber({2, 3, 5})) { + if (i > value) { + return i; + } + } + return 0; +} diff --git a/src/process/meta/HammingNumber.h b/src/process/meta/HammingNumber.h new file mode 100644 index 0000000..9f511ac --- /dev/null +++ b/src/process/meta/HammingNumber.h @@ -0,0 +1,34 @@ +/// @file HammingNumber.h +/// @class HammingNumber +/// @brief Hamming number generator +/// @author Nigel Galloway +/// @cite https://rosettacode.org/wiki/Hamming_numbers +/// @todo Can this be done with constexpr??? + +#ifndef HAMMING_GENERATOR_H +#define HAMMING_GENERATOR_H + +#include +#include + +class HammingNumber +{ + + private: + std::vector _H, _hp, _hv, _x; + + public: + bool operator!=(const HammingNumber &other) const; + HammingNumber begin() const; + HammingNumber end() const; + unsigned int operator*() const; + HammingNumber(const std::vector &pfs); + const HammingNumber &operator++(); +}; + +/// @brief Calculate the next 5-smooth Hamming Number larger than value +/// @param value Value to round +/// @return value rounded to Hamming number +uint32_t next_hamming(uint32_t value); + +#endif \ No newline at end of file diff --git a/src/process/spectrum/SpectrumAnalyser.h b/src/process/spectrum/SpectrumAnalyser.h index 7140cca..7057500 100644 --- a/src/process/spectrum/SpectrumAnalyser.h +++ b/src/process/spectrum/SpectrumAnalyser.h @@ -4,6 +4,7 @@ /// @details Simple decimate and FFT on CPI IQ data for frequency spectrum. /// @author 30hours /// @todo Potentially create k spectrum plots from sub-CPIs. +/// @todo FFT with HammingNumber class. #ifndef SPECTRUMANALYSER_H #define SPECTRUMANALYSER_H