From fe94cfa45ae7134293058132ee7a33c506940f35 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 14 Oct 2015 12:05:09 -0700 Subject: [PATCH] De-std::vector MatchedFilter, was chewing up far too much memory. --- firmware/baseband/matched_filter.cpp | 19 ------------- firmware/baseband/matched_filter.hpp | 40 +++++++++++++++++----------- firmware/baseband/proc_fsk.cpp | 3 --- firmware/baseband/proc_fsk.hpp | 4 +-- 4 files changed, 26 insertions(+), 40 deletions(-) diff --git a/firmware/baseband/matched_filter.cpp b/firmware/baseband/matched_filter.cpp index 50bfadd3..706d2b89 100644 --- a/firmware/baseband/matched_filter.cpp +++ b/firmware/baseband/matched_filter.cpp @@ -24,24 +24,5 @@ namespace dsp { namespace matched_filter { -bool MatchedFilter::execute_once( - const sample_t input -) { - samples[samples.size() - decimation_factor + decimation_phase] = input; - - advance_decimation_phase(); - if( is_new_decimation_cycle() ) { - output = std::inner_product(samples.cbegin(), samples.cend(), taps.cbegin(), sample_t { 0.0f, 0.0f }); - shift_by_decimation_factor(); - return true; - } else { - return false; - } -} - -void MatchedFilter::shift_by_decimation_factor() { - std::rotate(samples.begin(), samples.begin() + decimation_factor, samples.end()); -} - } /* namespace matched_filter */ } /* namespace dsp */ diff --git a/firmware/baseband/matched_filter.hpp b/firmware/baseband/matched_filter.hpp index 2a09c4ad..d72e481c 100644 --- a/firmware/baseband/matched_filter.hpp +++ b/firmware/baseband/matched_filter.hpp @@ -22,11 +22,12 @@ #ifndef __MATCHED_FILTER_H__ #define __MATCHED_FILTER_H__ +#include "baseband_ais.hpp" + #include #include #include -#include #include #include @@ -35,46 +36,53 @@ namespace dsp { namespace matched_filter { +template class MatchedFilter { public: using sample_t = std::complex; using tap_t = std::complex; - using taps_t = std::vector; + using taps_t = std::array; MatchedFilter( + const taps_t& taps, size_t decimation_factor = 1 - ) : decimation_factor { decimation_factor } + ) : taps(taps), + decimation_factor { decimation_factor } { } - template - void set_taps(const T& new_taps) { - taps.assign(new_taps.cbegin(), new_taps.cend()); - taps.shrink_to_fit(); - - samples.assign(new_taps.size(), 0); - samples.shrink_to_fit(); - } - bool execute_once( const sample_t input - ); + ) { + samples[samples.size() - decimation_factor + decimation_phase] = input; + + advance_decimation_phase(); + if( is_new_decimation_cycle() ) { + output = std::inner_product(samples.cbegin(), samples.cend(), taps.cbegin(), sample_t { 0.0f, 0.0f }); + shift_by_decimation_factor(); + return true; + } else { + return false; + } + } sample_t get_output() const { return output; } private: - using samples_t = std::vector; + using samples_t = std::array; samples_t samples; - taps_t taps; + const taps_t taps; size_t decimation_factor { 1 }; size_t decimation_phase { 0 }; sample_t output; - void shift_by_decimation_factor(); + void shift_by_decimation_factor() { + std::rotate(samples.begin(), samples.begin() + decimation_factor, samples.end()); + } void advance_decimation_phase() { decimation_phase = (decimation_phase + 1) % decimation_factor; diff --git a/firmware/baseband/proc_fsk.cpp b/firmware/baseband/proc_fsk.cpp index 55edc77b..4500506d 100644 --- a/firmware/baseband/proc_fsk.cpp +++ b/firmware/baseband/proc_fsk.cpp @@ -30,9 +30,6 @@ FSKProcessor::FSKProcessor( MessageHandlerMap& message_handlers ) : message_handlers(message_handlers) { - mf_0.set_taps(baseband::ais::rrc_taps_8_n); - mf_1.set_taps(baseband::ais::rrc_taps_8_p); - message_handlers.register_handler(Message::ID::FSKConfiguration, [this](const Message* const p) { auto m = reinterpret_cast(p); diff --git a/firmware/baseband/proc_fsk.hpp b/firmware/baseband/proc_fsk.hpp index 3224581f..f5dddc46 100644 --- a/firmware/baseband/proc_fsk.hpp +++ b/firmware/baseband/proc_fsk.hpp @@ -57,8 +57,8 @@ private: const fir_taps_real<64>& channel_filter_taps = taps_64_lp_031_070_tfilter; dsp::decimate::FIRAndDecimateBy2Complex<64> channel_filter { channel_filter_taps.taps }; - dsp::matched_filter::MatchedFilter mf_0 { 1 }; - dsp::matched_filter::MatchedFilter mf_1 { 1 }; + dsp::matched_filter::MatchedFilter<8> mf_0 { baseband::ais::rrc_taps_8_n, 1 }; + dsp::matched_filter::MatchedFilter<8> mf_1 { baseband::ais::rrc_taps_8_p, 1 }; clock_recovery::ClockRecovery clock_recovery { static_cast(sampling_rate / 4),