diff --git a/firmware/baseband/matched_filter.cpp b/firmware/baseband/matched_filter.cpp index 706d2b89..9ef7fdd9 100644 --- a/firmware/baseband/matched_filter.cpp +++ b/firmware/baseband/matched_filter.cpp @@ -24,5 +24,24 @@ namespace dsp { namespace matched_filter { +bool MatchedFilter::execute_once( + const sample_t input +) { + samples_[taps_count_ - decimation_factor + decimation_phase] = input; + + advance_decimation_phase(); + if( is_new_decimation_cycle() ) { + output = std::inner_product(&samples_[0], &samples_[taps_count_], &taps_[0], sample_t { 0.0f, 0.0f }); + shift_by_decimation_factor(); + return true; + } else { + return false; + } +} + +void MatchedFilter::shift_by_decimation_factor() { + std::rotate(&samples_[0], &samples_[decimation_factor], &samples_[taps_count_]); +} + } /* namespace matched_filter */ } /* namespace dsp */ diff --git a/firmware/baseband/matched_filter.hpp b/firmware/baseband/matched_filter.hpp index d72e481c..902b743f 100644 --- a/firmware/baseband/matched_filter.hpp +++ b/firmware/baseband/matched_filter.hpp @@ -23,6 +23,7 @@ #define __MATCHED_FILTER_H__ #include "baseband_ais.hpp" +#include "utility.hpp" #include @@ -36,53 +37,50 @@ namespace dsp { namespace matched_filter { -template class MatchedFilter { public: using sample_t = std::complex; using tap_t = std::complex; - using taps_t = std::array; + using taps_t = tap_t[]; MatchedFilter( - const taps_t& taps, + const tap_t* const taps, + const size_t taps_count, size_t decimation_factor = 1 - ) : taps(taps), + ) : samples_ { std::make_unique(taps_count) }, + taps_ { std::make_unique(taps_count) }, + taps_count_ { taps_count }, decimation_factor { decimation_factor } + { + std::copy(&taps[0], &taps[taps_count], &taps_[0]); + } + + template + MatchedFilter( + const T& taps, + size_t decimation_factor = 1 + ) : MatchedFilter(taps.data(), taps.size(), decimation_factor) { } - 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; - } - } + bool execute_once(const sample_t input); sample_t get_output() const { return output; } private: - using samples_t = std::array; + using samples_t = sample_t[]; - samples_t samples; - const taps_t taps; + const std::unique_ptr samples_; + const std::unique_ptr taps_; + const size_t taps_count_; size_t decimation_factor { 1 }; size_t decimation_phase { 0 }; sample_t output; - void shift_by_decimation_factor() { - std::rotate(samples.begin(), samples.begin() + decimation_factor, samples.end()); - } + void shift_by_decimation_factor(); void advance_decimation_phase() { decimation_phase = (decimation_phase + 1) % decimation_factor; diff --git a/firmware/baseband/proc_fsk.hpp b/firmware/baseband/proc_fsk.hpp index f5dddc46..7d82ac16 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<8> mf_0 { baseband::ais::rrc_taps_8_n, 1 }; - dsp::matched_filter::MatchedFilter<8> mf_1 { baseband::ais::rrc_taps_8_p, 1 }; + dsp::matched_filter::MatchedFilter mf_0 { baseband::ais::rrc_taps_8_n, 1 }; + dsp::matched_filter::MatchedFilter mf_1 { baseband::ais::rrc_taps_8_p, 1 }; clock_recovery::ClockRecovery clock_recovery { static_cast(sampling_rate / 4),