diff --git a/firmware/baseband/spectrum_collector.cpp b/firmware/baseband/spectrum_collector.cpp index 0d288bee..ebe55a24 100644 --- a/firmware/baseband/spectrum_collector.cpp +++ b/firmware/baseband/spectrum_collector.cpp @@ -103,6 +103,31 @@ void SpectrumCollector::post_message(const buffer_c16_t& data) { } } +template +static typename T::value_type spectrum_window_none(const T& s, const size_t i) { + static_assert(power_of_two(s.size()), "Array size must be power of 2"); + return s[i]; +}; + +template +static typename T::value_type spectrum_window_hamming_3(const T& s, const size_t i) { + static_assert(power_of_two(s.size()), "Array size must be power of 2"); + constexpr size_t mask = s.size() - 1; + // Three point Hamming window. + return s[i] * 0.54f + (s[(i-1) & mask] + s[(i+1) & mask]) * -0.23f; +}; + +template +static typename T::value_type spectrum_window_blackman_3(const T& s, const size_t i) { + static_assert(power_of_two(s.size()), "Array size must be power of 2"); + constexpr size_t mask = s.size() - 1; + // Three term Blackman window. + constexpr float alpha = 0.42f; + constexpr float beta = 0.5f * 0.5f; + constexpr float gamma = 0.08f * 0.05f; + return s[i] * alpha - (s[(i-1) & mask] + s[(i+1) & mask]) * beta + (s[(i-2) & mask] + s[(i+2) & mask]) * gamma; +}; + void SpectrumCollector::update() { // Called from idle thread (after EVT_MASK_SPECTRUM is flagged) if( streaming && channel_spectrum_request_update ) { @@ -114,9 +139,7 @@ void SpectrumCollector::update() { spectrum.channel_filter_pass_frequency = channel_filter_pass_frequency; spectrum.channel_filter_stop_frequency = channel_filter_stop_frequency; for(size_t i=0; i