diff --git a/firmware/baseband/channel_decimator.hpp b/firmware/baseband/channel_decimator.hpp index 9ec773f8..3177a121 100644 --- a/firmware/baseband/channel_decimator.hpp +++ b/firmware/baseband/channel_decimator.hpp @@ -38,12 +38,6 @@ public: By32, }; - ChannelDecimator( - DecimationFactor f - ) : decimation_factor { f } - { - } - void set_decimation_factor(const DecimationFactor f) { decimation_factor = f; } @@ -75,7 +69,7 @@ private: dsp::decimate::DecimateBy2CIC3 cic_3; dsp::decimate::DecimateBy2CIC3 cic_4; - DecimationFactor decimation_factor { DecimationFactor::By32 }; + DecimationFactor decimation_factor = DecimationFactor::By32; buffer_c16_t execute_decimation(buffer_c8_t buffer); }; diff --git a/firmware/baseband/clock_recovery.hpp b/firmware/baseband/clock_recovery.hpp index a8d40b42..3289729f 100644 --- a/firmware/baseband/clock_recovery.hpp +++ b/firmware/baseband/clock_recovery.hpp @@ -90,7 +90,11 @@ private: class FixedErrorFilter { public: FixedErrorFilter( - const float weight = (1.0f / 16.0f) + ) { + } + + FixedErrorFilter( + const float weight ) : weight_ { weight } { } @@ -106,28 +110,25 @@ public: } private: - const float weight_; + float weight_ { 1.0f / 16.0f }; }; template class ClockRecovery { public: ClockRecovery( - const float sampling_rate, - const float symbol_rate, - const ErrorFilter error_filter, std::function symbol_handler - ) : resampler(sampling_rate, symbol_rate * timing_error_detector.samples_per_symbol), - error_filter { error_filter }, - symbol_handler { symbol_handler } + ) : symbol_handler { symbol_handler } { } void configure( const float sampling_rate, - const float symbol_rate + const float symbol_rate, + ErrorFilter error_filter ) { resampler.configure(sampling_rate, symbol_rate * timing_error_detector.samples_per_symbol); + error_filter = error_filter; } void operator()( diff --git a/firmware/baseband/dsp_decimate.hpp b/firmware/baseband/dsp_decimate.hpp index cbb6204b..9cc90b88 100644 --- a/firmware/baseband/dsp_decimate.hpp +++ b/firmware/baseband/dsp_decimate.hpp @@ -89,21 +89,20 @@ public: * processed will be a multiple of the taps_count. */ FIRAndDecimateComplex( - const size_t taps_count, - const size_t decimation_factor - ) : samples_ { std::make_unique(taps_count) }, - taps_reversed_ { std::make_unique(taps_count) }, - taps_count_ { taps_count }, - decimation_factor_ { decimation_factor } + ) : taps_count_ { 0 }, + decimation_factor_ { 1 } { } template - FIRAndDecimateComplex( + void configure( const T& taps, const size_t decimation_factor - ) : FIRAndDecimateComplex(taps.size(), decimation_factor) - { + ) { + samples_ = std::make_unique(taps.size()); + taps_reversed_ = std::make_unique(taps.size()); + taps_count_ = taps.size(); + decimation_factor_ = decimation_factor; std::reverse_copy(taps.cbegin(), taps.cend(), &taps_reversed_[0]); } @@ -115,10 +114,10 @@ public: private: using samples_t = sample_t[]; - const std::unique_ptr samples_; - const std::unique_ptr taps_reversed_; - const size_t taps_count_; - const size_t decimation_factor_; + std::unique_ptr samples_; + std::unique_ptr taps_reversed_; + size_t taps_count_; + size_t decimation_factor_; }; class DecimateBy2CIC4Real { diff --git a/firmware/baseband/linear_resampler.hpp b/firmware/baseband/linear_resampler.hpp index 2de41f2c..d889a2c2 100644 --- a/firmware/baseband/linear_resampler.hpp +++ b/firmware/baseband/linear_resampler.hpp @@ -27,15 +27,6 @@ namespace interpolation { class LinearResampler { public: - constexpr LinearResampler( - const float input_rate, - const float output_rate - ) : last_sample { 0.0f }, - phase { 0.0f }, - phase_increment { calculate_increment(input_rate, output_rate) } - { - } - void configure( const float input_rate, const float output_rate @@ -63,9 +54,9 @@ public: } private: - float last_sample; - float phase; - float phase_increment; + float last_sample { 0.0f }; + float phase { 0.0f }; + float phase_increment { 0.0f }; static constexpr float calculate_increment(const float input_rate, const float output_rate) { return input_rate / output_rate; diff --git a/firmware/baseband/matched_filter.hpp b/firmware/baseband/matched_filter.hpp index 284898b0..e065590c 100644 --- a/firmware/baseband/matched_filter.hpp +++ b/firmware/baseband/matched_filter.hpp @@ -43,25 +43,17 @@ public: using taps_t = tap_t[]; - MatchedFilter( - const tap_t* const taps, - const size_t taps_count, - size_t decimation_factor = 1 - ) : samples_ { std::make_unique(taps_count) }, - taps_reversed_ { std::make_unique(taps_count) }, - taps_count_ { taps_count }, - decimation_factor { decimation_factor } - { - std::reverse_copy(&taps[0], &taps[taps_count], &taps_reversed_[0]); - } - - template - MatchedFilter( + template + void configure( const T& taps, size_t decimation_factor = 1 - ) : MatchedFilter(taps.data(), taps.size(), decimation_factor) - { - } + ) { + samples_ = std::make_unique(taps.size()); + taps_reversed_ = std::make_unique(taps.size()); + taps_count_ = taps.size(); + decimation_factor = decimation_factor; + std::reverse_copy(taps.cbegin(), taps.cend(), &taps_reversed_[0]); + } bool execute_once(const sample_t input); @@ -72,9 +64,9 @@ public: private: using samples_t = sample_t[]; - const std::unique_ptr samples_; - const std::unique_ptr taps_reversed_; - const size_t taps_count_; + std::unique_ptr samples_; + std::unique_ptr taps_reversed_; + size_t taps_count_ { 0 }; size_t decimation_factor { 1 }; size_t decimation_phase { 0 }; float output; diff --git a/firmware/baseband/proc_am_audio.hpp b/firmware/baseband/proc_am_audio.hpp index 994ff74d..6c0d91e5 100644 --- a/firmware/baseband/proc_am_audio.hpp +++ b/firmware/baseband/proc_am_audio.hpp @@ -33,12 +33,17 @@ class NarrowbandAMAudio : public BasebandProcessor { public: + NarrowbandAMAudio() { + decimator.set_decimation_factor(ChannelDecimator::DecimationFactor::By32); + channel_filter.configure(channel_filter_taps.taps, 2); + } + void execute(buffer_c8_t buffer) override; private: - ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By32 }; + ChannelDecimator decimator; const fir_taps_real<64>& channel_filter_taps = taps_64_lp_031_070_tfilter; - dsp::decimate::FIRAndDecimateComplex channel_filter { channel_filter_taps.taps, 2 }; + dsp::decimate::FIRAndDecimateComplex channel_filter; dsp::demodulate::AM demod; IIRBiquadFilter audio_hpf { audio_hpf_config }; }; diff --git a/firmware/baseband/proc_fsk.cpp b/firmware/baseband/proc_fsk.cpp index 42d6edbd..df75299c 100644 --- a/firmware/baseband/proc_fsk.cpp +++ b/firmware/baseband/proc_fsk.cpp @@ -44,7 +44,10 @@ FSKProcessor::~FSKProcessor() { void FSKProcessor::configure(const FSKConfiguration new_configuration) { // TODO: Matched filter characteristics are hard-coded for the moment. YUCK! - clock_recovery.configure(sampling_rate / 4, new_configuration.symbol_rate); + decimator.set_decimation_factor(ChannelDecimator::DecimationFactor::By16); + channel_filter.configure(channel_filter_taps.taps, 8); + mf.configure(baseband::ais::rrc_taps_128_decim_4_p, 1); + clock_recovery.configure(new_configuration.symbol_rate * 2, new_configuration.symbol_rate, { 0.0555f }); packet_builder.configure( { new_configuration.access_code, new_configuration.access_code_length, new_configuration.access_code_tolerance }, { new_configuration.unstuffing_pattern, new_configuration.unstuffing_length } diff --git a/firmware/baseband/proc_fsk.hpp b/firmware/baseband/proc_fsk.hpp index 2aae07b7..5e993c60 100644 --- a/firmware/baseband/proc_fsk.hpp +++ b/firmware/baseband/proc_fsk.hpp @@ -53,18 +53,12 @@ public: void execute(buffer_c8_t buffer) override; private: - const size_t sampling_rate = 76800; - - ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By16 }; - const fir_taps_real<64>& channel_filter_taps = taps_64_lp_031_070_tfilter; - dsp::decimate::FIRAndDecimateComplex channel_filter { channel_filter_taps.taps, 8 }; - - dsp::matched_filter::MatchedFilter mf { baseband::ais::rrc_taps_128_decim_4_p, 1 }; + ChannelDecimator decimator; + const fir_taps_real<64>& channel_filter_taps = taps_64_lp_042_078_tfilter; + dsp::decimate::FIRAndDecimateComplex channel_filter; + dsp::matched_filter::MatchedFilter mf; clock_recovery::ClockRecovery clock_recovery { - static_cast(sampling_rate / 4), - 9600, - { 0.0555f }, [this](const float symbol) { this->consume_symbol(symbol); } }; symbol_coding::NRZIDecoder nrzi_decode; diff --git a/firmware/baseband/proc_nfm_audio.hpp b/firmware/baseband/proc_nfm_audio.hpp index 42922ede..f3553387 100644 --- a/firmware/baseband/proc_nfm_audio.hpp +++ b/firmware/baseband/proc_nfm_audio.hpp @@ -34,12 +34,17 @@ class NarrowbandFMAudio : public BasebandProcessor { public: + NarrowbandFMAudio() { + decimator.set_decimation_factor(ChannelDecimator::DecimationFactor::By32); + channel_filter.configure(channel_filter_taps.taps, 2); + } + void execute(buffer_c8_t buffer) override; private: - ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By32 }; + ChannelDecimator decimator; const fir_taps_real<64>& channel_filter_taps = taps_64_lp_042_078_tfilter; - dsp::decimate::FIRAndDecimateComplex channel_filter { channel_filter_taps.taps, 2 }; + dsp::decimate::FIRAndDecimateComplex channel_filter; dsp::demodulate::FM demod { 48000, 7500 }; IIRBiquadFilter audio_hpf { audio_hpf_config }; diff --git a/firmware/baseband/proc_wfm_audio.hpp b/firmware/baseband/proc_wfm_audio.hpp index 01e09f4c..3a0eb65c 100644 --- a/firmware/baseband/proc_wfm_audio.hpp +++ b/firmware/baseband/proc_wfm_audio.hpp @@ -33,10 +33,14 @@ class WidebandFMAudio : public BasebandProcessor { public: + WidebandFMAudio() { + decimator.set_decimation_factor(ChannelDecimator::DecimationFactor::By4); + } + void execute(buffer_c8_t buffer) override; private: - ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By4 }; + ChannelDecimator decimator; dsp::demodulate::FM demod { 768000, 75000 }; dsp::decimate::DecimateBy2CIC4Real audio_dec_1;