From 1515d895626fe2123d8a48dd3ccf55a90cfa240c Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Tue, 6 Feb 2024 03:16:21 +0000 Subject: [PATCH] slew counter/adjustment. --- grc/iqtlabs_retune_pre_fft.block.yml | 11 ++++--- include/gnuradio/iqtlabs/retune_pre_fft.h | 8 ++--- lib/retune_fft_impl.cc | 15 +++++---- lib/retune_fft_impl.h | 1 - lib/retune_pre_fft_impl.cc | 24 ++++++++------ lib/retune_pre_fft_impl.h | 2 +- lib/retuner_impl.cc | 32 ++++++++++++------- lib/retuner_impl.h | 11 ++++--- .../iqtlabs/bindings/retune_pre_fft_python.cc | 3 +- python/iqtlabs/qa_retune_fft.py | 1 + 10 files changed, 65 insertions(+), 43 deletions(-) diff --git a/grc/iqtlabs_retune_pre_fft.block.yml b/grc/iqtlabs_retune_pre_fft.block.yml index ddf5b039..628b9abb 100644 --- a/grc/iqtlabs_retune_pre_fft.block.yml +++ b/grc/iqtlabs_retune_pre_fft.block.yml @@ -16,6 +16,7 @@ documentation: |- parameters: nfft: number of FFT points. + samp_rate: sample rate. fft_batch_size: number of vectors to batch. tag: expected PMT tag containing center frequency (generally "rx_freq" for Soapy or UHD sources). @@ -39,8 +40,8 @@ templates: imports: from gnuradio import iqtlabs make: > iqtlabs.retune_pre_fft( - ${nfft}, ${fft_batch_size}, ${tag}, ${freq_start}, ${freq_end}, - ${tune_step_hz}, ${tune_step_fft}, ${skip_tune_step_fft}, + ${nfft}, ${samp_rate}, ${fft_batch_size}, ${tag}, ${freq_start}, + ${freq_end}, ${tune_step_hz}, ${tune_step_fft}, ${skip_tune_step_fft}, ${tuning_ranges}, ${tag_now}, ${low_power_hold_down}, ${slew_rx_time}) @@ -49,8 +50,8 @@ cpp_templates: declarations: 'gr::iqtlabs::retune_pre_fft::sptr ${id};' make: > this->${id} = gr::iqtlabs::retune_pre_fft::make( - ${nfft}, ${fft_batch_size}, ${tag}, {freq_start}, ${freq_end}, - ${tune_step_hz}, ${tune_step_fft}, ${skip_tune_step_fft}, + ${nfft}, ${samp_rate}, ${fft_batch_size}, ${tag}, {freq_start}, + ${freq_end}, ${tune_step_hz}, ${tune_step_fft}, ${skip_tune_step_fft}, ${tuning_ranges}, ${tag_now}, ${low_power_hold_down}, ${slew_rx_time}); link: ['libgnuradio-iqtlabs.so'] @@ -58,6 +59,8 @@ cpp_templates: parameters: - id: nfft dtype: int + - id: samp_rate + dtype: int - id: fft_batch_size dtype: int - id: tag diff --git a/include/gnuradio/iqtlabs/retune_pre_fft.h b/include/gnuradio/iqtlabs/retune_pre_fft.h index 77e2b2a4..e1b1d587 100644 --- a/include/gnuradio/iqtlabs/retune_pre_fft.h +++ b/include/gnuradio/iqtlabs/retune_pre_fft.h @@ -229,10 +229,10 @@ class IQTLABS_API retune_pre_fft : virtual public gr::block { * creating new instances. */ - static sptr make(size_t nfft, size_t fft_batch_size, const std::string &tag, - uint64_t freq_start, uint64_t freq_end, - uint64_t tune_step_hz, uint64_t tune_step_fft, - uint64_t skip_tune_step_fft, + static sptr make(size_t nfft, uint64_t samp_rate, size_t fft_batch_size, + const std::string &tag, uint64_t freq_start, + uint64_t freq_end, uint64_t tune_step_hz, + uint64_t tune_step_fft, uint64_t skip_tune_step_fft, const std::string &tuning_ranges, bool tag_now, bool low_power_hold_down, bool slew_rx_time); }; diff --git a/lib/retune_fft_impl.cc b/lib/retune_fft_impl.cc index 232e871e..079a4826 100644 --- a/lib/retune_fft_impl.cc +++ b/lib/retune_fft_impl.cc @@ -252,14 +252,13 @@ retune_fft_impl::retune_fft_impl( 2 /* min outputs */, 2 /* max outputs */, std::vector{(int)sizeof(output_type), (int)(nfft * sizeof(input_type))})), - retuner_impl(freq_start, freq_end, tune_step_hz, tune_step_fft, + retuner_impl(samp_rate, freq_start, freq_end, tune_step_hz, tune_step_fft, skip_tune_step_fft, tuning_ranges, tag_now, low_power_hold_down, slew_rx_time), - tag_(pmt::intern(tag)), nfft_(nfft), samp_rate_(samp_rate), - fft_min_(fft_min), fft_max_(fft_max), sample_count_(0), sdir_(sdir), - write_step_fft_(write_step_fft), write_step_fft_count_(write_step_fft), - bucket_range_(bucket_range), description_(description), - rotate_secs_(rotate_secs), pre_fft_(pre_fft), + tag_(pmt::intern(tag)), nfft_(nfft), fft_min_(fft_min), fft_max_(fft_max), + sample_count_(0), sdir_(sdir), write_step_fft_(write_step_fft), + write_step_fft_count_(write_step_fft), bucket_range_(bucket_range), + description_(description), rotate_secs_(rotate_secs), pre_fft_(pre_fft), peak_fft_range_(peak_fft_range) { bucket_offset_ = round(float((nfft_ - round(bucket_range_ * nfft_)) / 2)); unsigned int alignment = volk_get_alignment(); @@ -342,7 +341,7 @@ void retune_fft_impl::sum_items_(const input_type *in) { void retune_fft_impl::add_output_tags_(TIME_T rx_time, FREQ_T rx_freq, size_t rel) { - OUTPUT_TAGS(rx_time, rx_freq, 1, rel); + OUTPUT_TAGS(apply_rx_time_slew_(rx_time), rx_freq, 1, rel); } void retune_fft_impl::process_items_(size_t c, const input_type *&in, @@ -351,6 +350,7 @@ void retune_fft_impl::process_items_(size_t c, const input_type *&in, for (size_t i = 0; i < c; ++i, in += nfft_) { if (skip_fft_count_) { --skip_fft_count_; + slew_samples_ += nfft_; continue; } // Discard windows where max power, is less than requested minimum. @@ -366,6 +366,7 @@ void retune_fft_impl::process_items_(size_t c, const input_type *&in, continue; } if (in_hold_down_ && total_tune_count_ > 1) { + slew_samples_ += nfft_; continue; } std::memcpy((void *)fft_output, (const void *)in, diff --git a/lib/retune_fft_impl.h b/lib/retune_fft_impl.h index ffd7f3cb..4cab672f 100644 --- a/lib/retune_fft_impl.h +++ b/lib/retune_fft_impl.h @@ -244,7 +244,6 @@ class retune_fft_impl : public retune_fft, base_impl, retuner_impl { pmt::pmt_t tag_; size_t nfft_; size_t peak_fft_range_; - uint64_t samp_rate_; uint64_t write_step_fft_; uint64_t rotate_secs_; double bucket_range_; diff --git a/lib/retune_pre_fft_impl.cc b/lib/retune_pre_fft_impl.cc index 90476ddc..ebfc5f20 100644 --- a/lib/retune_pre_fft_impl.cc +++ b/lib/retune_pre_fft_impl.cc @@ -211,22 +211,22 @@ namespace gr { namespace iqtlabs { retune_pre_fft::sptr -retune_pre_fft::make(size_t nfft, size_t fft_batch_size, const std::string &tag, - uint64_t freq_start, uint64_t freq_end, - uint64_t tune_step_hz, uint64_t tune_step_fft, - uint64_t skip_tune_step_fft, +retune_pre_fft::make(size_t nfft, uint64_t samp_rate, size_t fft_batch_size, + const std::string &tag, uint64_t freq_start, + uint64_t freq_end, uint64_t tune_step_hz, + uint64_t tune_step_fft, uint64_t skip_tune_step_fft, const std::string &tuning_ranges, bool tag_now, bool low_power_hold_down, bool slew_rx_time) { return gnuradio::make_block_sptr( - nfft, fft_batch_size, tag, freq_start, freq_end, tune_step_hz, + nfft, samp_rate, fft_batch_size, tag, freq_start, freq_end, tune_step_hz, tune_step_fft, skip_tune_step_fft, tuning_ranges, tag_now, low_power_hold_down, slew_rx_time); } retune_pre_fft_impl::retune_pre_fft_impl( - size_t nfft, size_t fft_batch_size, const std::string &tag, - uint64_t freq_start, uint64_t freq_end, uint64_t tune_step_hz, - uint64_t tune_step_fft, uint64_t skip_tune_step_fft, + size_t nfft, uint64_t samp_rate, size_t fft_batch_size, + const std::string &tag, uint64_t freq_start, uint64_t freq_end, + uint64_t tune_step_hz, uint64_t tune_step_fft, uint64_t skip_tune_step_fft, const std::string &tuning_ranges, bool tag_now, bool low_power_hold_down, bool slew_rx_time) : gr::block( @@ -235,7 +235,7 @@ retune_pre_fft_impl::retune_pre_fft_impl( sizeof(block_type)), gr::io_signature::make(1 /* min outputs */, 1 /* max outputs */, sizeof(block_type) * nfft * fft_batch_size)), - retuner_impl(freq_start, freq_end, tune_step_hz, tune_step_fft, + retuner_impl(samp_rate, freq_start, freq_end, tune_step_hz, tune_step_fft, skip_tune_step_fft, tuning_ranges, tag_now, low_power_hold_down, slew_rx_time), nfft_(nfft), fft_batch_size_(fft_batch_size), tag_(pmt::intern(tag)) { @@ -249,7 +249,8 @@ retune_pre_fft_impl::~retune_pre_fft_impl() {} void retune_pre_fft_impl::add_output_tags_(TIME_T rx_time, FREQ_T rx_freq, size_t rel) { - OUTPUT_TAGS(rx_time, rx_freq, 0, (rel / fft_batch_size_)); + OUTPUT_TAGS(apply_rx_time_slew_(rx_time), rx_freq, 0, + (rel / fft_batch_size_)); } void retune_pre_fft_impl::forecast(int noutput_items, @@ -270,6 +271,7 @@ void retune_pre_fft_impl::process_items_(size_t c, const block_type *&in, for (size_t i = 0; i < c; ++i, in += nfft_) { if (skip_fft_count_) { --skip_fft_count_; + slew_samples_ += nfft_; continue; } bool all_zeros = all_zeros_(in); @@ -278,6 +280,7 @@ void retune_pre_fft_impl::process_items_(size_t c, const block_type *&in, in_hold_down_ = false; add_output_tags_(last_rx_time_, last_rx_freq_, produced); } else if (total_tune_count_ > 1) { + slew_samples_ += nfft_; continue; } } @@ -294,6 +297,7 @@ void retune_pre_fft_impl::process_items_(size_t c, const block_type *&in, for (size_t i = 0; i < c; ++i, in += nfft_) { if (skip_fft_count_) { --skip_fft_count_; + slew_samples_ += nfft_; continue; } std::memcpy((void *)out, (void *)in, sizeof(block_type) * nfft_); diff --git a/lib/retune_pre_fft_impl.h b/lib/retune_pre_fft_impl.h index 097ec3f4..2f42a0ba 100644 --- a/lib/retune_pre_fft_impl.h +++ b/lib/retune_pre_fft_impl.h @@ -228,7 +228,7 @@ class retune_pre_fft_impl : public retune_pre_fft, base_impl, retuner_impl { boost::scoped_ptr total_; public: - retune_pre_fft_impl(size_t nfft, size_t fft_batch_size, + retune_pre_fft_impl(size_t nfft, size_t samp_rate, size_t fft_batch_size, const std::string &tag, uint64_t freq_start, uint64_t freq_end, uint64_t tune_step_hz, uint64_t tune_step_fft, uint64_t skip_tune_step_fft, diff --git a/lib/retuner_impl.cc b/lib/retuner_impl.cc index 9b29b9ae..181e06a3 100644 --- a/lib/retuner_impl.cc +++ b/lib/retuner_impl.cc @@ -208,19 +208,20 @@ namespace gr { namespace iqtlabs { -retuner_impl::retuner_impl(uint64_t freq_start, uint64_t freq_end, - uint64_t tune_step_hz, uint64_t tune_step_fft, - uint64_t skip_tune_step_fft, +retuner_impl::retuner_impl(uint64_t samp_rate, uint64_t freq_start, + uint64_t freq_end, uint64_t tune_step_hz, + uint64_t tune_step_fft, uint64_t skip_tune_step_fft, const std::string &tuning_ranges, bool tag_now, bool low_power_hold_down, bool slew_rx_time) - : freq_start_(freq_start), freq_end_(freq_end), tune_step_hz_(tune_step_hz), - tune_step_fft_(tune_step_fft), skip_tune_step_fft_(skip_tune_step_fft), - tag_now_(tag_now), slew_rx_time_(slew_rx_time), - low_power_hold_down_(low_power_hold_down), tuning_range_(0), - last_tuning_range_(0), tuning_range_step_(0), last_rx_freq_(0), - last_rx_time_(0), last_sweep_start_(0), fft_count_(0), pending_retune_(0), - total_tune_count_(0), tune_freq_(0), skip_fft_count_(skip_tune_step_fft), - in_hold_down_(false), reset_tags_(false) { + : samp_rate_(samp_rate), freq_start_(freq_start), freq_end_(freq_end), + tune_step_hz_(tune_step_hz), tune_step_fft_(tune_step_fft), + skip_tune_step_fft_(skip_tune_step_fft), tag_now_(tag_now), + slew_rx_time_(slew_rx_time), low_power_hold_down_(low_power_hold_down), + tuning_range_(0), last_tuning_range_(0), tuning_range_step_(0), + last_rx_freq_(0), last_rx_time_(0), last_sweep_start_(0), fft_count_(0), + pending_retune_(0), total_tune_count_(0), tune_freq_(0), + skip_fft_count_(skip_tune_step_fft), in_hold_down_(false), + reset_tags_(false), slew_samples_(0) { parse_tuning_ranges_(tuning_ranges); if (low_power_hold_down_ && !stare_mode_) { reset_tags_ = true; @@ -321,6 +322,15 @@ void retuner_impl::next_retune_(TIME_T host_now) { if (reset_tags_) { in_hold_down_ = true; } + slew_samples_ = 0; +} + +TIME_T retuner_impl::apply_rx_time_slew_(TIME_T rx_time) { + if (slew_rx_time_) { + TIME_T slew_time = slew_samples_ / TIME_T(samp_rate_); + return rx_time + slew_time; + } + return rx_time; } } /* namespace iqtlabs */ diff --git a/lib/retuner_impl.h b/lib/retuner_impl.h index 6f3e4c39..6d19932c 100644 --- a/lib/retuner_impl.h +++ b/lib/retuner_impl.h @@ -226,14 +226,16 @@ typedef struct { class retuner_impl { public: - retuner_impl(uint64_t freq_start, uint64_t freq_end, uint64_t tune_step_hz, - uint64_t tune_step_fft, uint64_t skip_tune_step_fft, - const std::string &tuning_ranges, bool tag_now, - bool low_power_hold_down, bool slew_rx_time); + retuner_impl(uint64_t samp_rate, uint64_t freq_start, uint64_t freq_end, + uint64_t tune_step_hz, uint64_t tune_step_fft, + uint64_t skip_tune_step_fft, const std::string &tuning_ranges, + bool tag_now, bool low_power_hold_down, bool slew_rx_time); void add_range_(uint64_t freq_start, uint64_t freq_end); bool need_retune_(size_t n); void parse_tuning_ranges_(const std::string &tuning_ranges); void next_retune_(TIME_T host_now); + TIME_T apply_rx_time_slew_(TIME_T rx_time); + uint64_t samp_rate_; uint64_t freq_start_; uint64_t freq_end_; uint64_t tune_step_hz_; @@ -254,6 +256,7 @@ class retuner_impl { size_t fft_count_; size_t pending_retune_; size_t total_tune_count_; + size_t slew_samples_; std::vector tuning_ranges_; bool stare_mode_; bool in_hold_down_; diff --git a/python/iqtlabs/bindings/retune_pre_fft_python.cc b/python/iqtlabs/bindings/retune_pre_fft_python.cc index fc28cc16..1b915e48 100644 --- a/python/iqtlabs/bindings/retune_pre_fft_python.cc +++ b/python/iqtlabs/bindings/retune_pre_fft_python.cc @@ -14,7 +14,7 @@ /* BINDTOOL_GEN_AUTOMATIC(0) */ /* BINDTOOL_USE_PYGCCXML(0) */ /* BINDTOOL_HEADER_FILE(retune_pre_fft.h) */ -/* BINDTOOL_HEADER_FILE_HASH(a40fbc21c2cdc0aac7419b17997d001c) */ +/* BINDTOOL_HEADER_FILE_HASH(b7616b720066a13e82470e7cfe4fc614) */ /***********************************************************************************/ #include @@ -40,6 +40,7 @@ void bind_retune_pre_fft(py::module& m) .def(py::init(&retune_pre_fft::make), py::arg("nfft"), + py::arg("samp_rate"), py::arg("fft_batch_size"), py::arg("tag"), py::arg("freq_start"), diff --git a/python/iqtlabs/qa_retune_fft.py b/python/iqtlabs/qa_retune_fft.py index 8ff73a0f..084012be 100755 --- a/python/iqtlabs/qa_retune_fft.py +++ b/python/iqtlabs/qa_retune_fft.py @@ -287,6 +287,7 @@ def retune_fft(self, fft_roll): iqtlabs_retune_pre_fft_0 = retune_pre_fft( points, + samp_rate, 1, "rx_freq", int(freq_start),