Skip to content

Commit

Permalink
Merge pull request #211 from anarkiwi/tj
Browse files Browse the repository at this point in the history
Tuning jitter adjustment.
  • Loading branch information
anarkiwi committed Feb 8, 2024
2 parents 9d8634b + 2344bcd commit 5d11327
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 124 deletions.
20 changes: 13 additions & 7 deletions grc/iqtlabs_retune_fft.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ documentation: |-
(generally "rx_freq" for Soapy or UHD sources).
nfft: number of FFT points.
samp_rate: sample rate.
tune_jitter_hz: if > 0, jitter tune interval.
freq_start: frequency to start scan at in Hz (overridden by tuning_ranges).
freq_end: frequency to end scan at in Hz (overridden by tuning_ranges).
tune_step_hz: increment frequency by this value each retuning step.
Expand Down Expand Up @@ -70,18 +71,21 @@ documentation: |-
templates:
imports: from gnuradio import iqtlabs
make: >
iqtlabs.retune_fft(${tag}, ${nfft}, ${samp_rate}, ${freq_start},
${freq_end}, ${tune_step_hz}, ${tune_step_fft}, ${skip_tune_step_fft},
${fft_min}, ${fft_max}, ${sdir}, ${write_step_fft}, ${bucket_range},
${tuning_ranges}, ${description}, ${rotate_secs}, ${pre_fft}, ${tag_now},
${low_power_hold_down), ${slew_rx_time}, ${peak_fft_range})
iqtlabs.retune_fft(
${tag}, ${nfft}, ${samp_rate}, ${tune_jitter_hz},
${freq_start}, ${freq_end}, ${tune_step_hz}, ${tune_step_fft},
${skip_tune_step_fft}, ${fft_min}, ${fft_max}, ${sdir}, ${write_step_fft},
${bucket_range}, ${tuning_ranges}, ${description}, ${rotate_secs},
${pre_fft}, ${tag_now}, ${low_power_hold_down), ${slew_rx_time},
${peak_fft_range})
cpp_templates:
includes: ['#include <gnuradio/iqtlabs/retune_fft.h>']
declarations: 'gr::iqtlabs::retune_fft::sptr ${id};'
make: >
this->${id} = gr::iqtlabs::retune_fft::make(${tag}, ${nfft},
${samp_rate}, ${freq_start}, ${freq_end}, ${tune_step_hz}, ${tune_step_fft},
this->${id} = gr::iqtlabs::retune_fft::make(
${tag}, ${nfft}, ${samp_rate}, ${tune_jitter_hz},
${freq_start}, ${freq_end}, ${tune_step_hz}, ${tune_step_fft},
${skip_tune_step_fft}, ${fft_min}, ${fft_max}, ${sdir}, ${write_step_fft},
${bucket_range}, ${tuning_ranges}, ${description}, ${rotate_secs},
${pre_fft}, ${tag_now}, ${low_power_hold_down), ${slew_rx_time},
Expand All @@ -103,6 +107,8 @@ parameters:
dtype: int
- id: samp_rate
dtype: int
- id: tune_jitter_hz
dtype: int
- id: freq_start
dtype: raw
- id: freq_end
Expand Down
19 changes: 11 additions & 8 deletions grc/iqtlabs_retune_pre_fft.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ documentation: |-
parameters:
nfft: number of FFT points.
samp_rate: sample rate.
tune_jitter_hz: if > 0, jitter tune interval.
fft_batch_size: number of vectors to batch.
tag: expected PMT tag containing center frequency
(generally "rx_freq" for Soapy or UHD sources).
Expand All @@ -40,27 +41,29 @@ templates:
imports: from gnuradio import iqtlabs
make: >
iqtlabs.retune_pre_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})
${nfft}, ${samp_rate}, ${tune_jitter_hz} ${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})
cpp_templates:
includes: ['#include <gnuradio/iqtlabs/retune_pre_fft.h>']
declarations: 'gr::iqtlabs::retune_pre_fft::sptr ${id};'
make: >
this->${id} = gr::iqtlabs::retune_pre_fft::make(
${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});
${nfft}, ${samp_rate}, ${tune_jitter_hz}, ${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']

parameters:
- id: nfft
dtype: int
- id: samp_rate
dtype: int
- id: tune_jitter_hz
dtype: int
- id: fft_batch_size
dtype: int
- id: tag
Expand Down
11 changes: 6 additions & 5 deletions include/gnuradio/iqtlabs/retune_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ class IQTLABS_API retune_fft : virtual public gr::block {
* creating new instances.
*/
static sptr make(const std::string &tag, size_t nfft, 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, double fft_min, double fft_max,
const std::string &sdir, uint64_t write_step_fft,
double bucket_range, const std::string &tuning_ranges,
uint64_t tune_jitter_hz, uint64_t freq_start,
uint64_t freq_end, uint64_t tune_step_hz,
uint64_t tune_step_fft, uint64_t skip_tune_step_fft,
double fft_min, double fft_max, const std::string &sdir,
uint64_t write_step_fft, double bucket_range,
const std::string &tuning_ranges,
const std::string &description, uint64_t rotate_secs,
bool pre_fft, bool tag_now, bool low_power_hold_down,
bool slew_rx_time, size_t peak_fft_range);
Expand Down
9 changes: 5 additions & 4 deletions include/gnuradio/iqtlabs/retune_pre_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ class IQTLABS_API retune_pre_fft : virtual public gr::block {
* creating new instances.
*/

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,
static sptr make(size_t nfft, uint64_t samp_rate, uint64_t tune_jitter_hz,
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);
};
Expand Down
52 changes: 29 additions & 23 deletions lib/retune_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,42 +219,41 @@ const pmt::pmt_t JSON_KEY = pmt::mp("json");
const boost::iostreams::zstd_params zstd_params =
boost::iostreams::zstd_params(boost::iostreams::zstd::default_compression);

retune_fft::sptr
retune_fft::make(const std::string &tag, size_t nfft, 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,
double fft_min, double fft_max, const std::string &sdir,
uint64_t write_step_fft, double bucket_range,
const std::string &tuning_ranges,
const std::string &description, uint64_t rotate_secs,
bool pre_fft, bool tag_now, bool low_power_hold_down,
bool slew_rx_time, size_t peak_fft_range) {
retune_fft::sptr retune_fft::make(
const std::string &tag, size_t nfft, uint64_t samp_rate,
uint64_t tune_jitter_hz, uint64_t freq_start, uint64_t freq_end,
uint64_t tune_step_hz, uint64_t tune_step_fft, uint64_t skip_tune_step_fft,
double fft_min, double fft_max, const std::string &sdir,
uint64_t write_step_fft, double bucket_range,
const std::string &tuning_ranges, const std::string &description,
uint64_t rotate_secs, bool pre_fft, bool tag_now, bool low_power_hold_down,
bool slew_rx_time, size_t peak_fft_range) {
return gnuradio::make_block_sptr<retune_fft_impl>(
tag, nfft, samp_rate, freq_start, freq_end, tune_step_hz, tune_step_fft,
skip_tune_step_fft, fft_min, fft_max, sdir, write_step_fft, bucket_range,
tuning_ranges, description, rotate_secs, pre_fft, tag_now,
tag, nfft, samp_rate, tune_jitter_hz, freq_start, freq_end, tune_step_hz,
tune_step_fft, skip_tune_step_fft, fft_min, fft_max, sdir, write_step_fft,
bucket_range, tuning_ranges, description, rotate_secs, pre_fft, tag_now,
low_power_hold_down, slew_rx_time, peak_fft_range);
}

retune_fft_impl::retune_fft_impl(
const std::string &tag, size_t nfft, 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, double fft_min,
double fft_max, const std::string &sdir, uint64_t write_step_fft,
double bucket_range, const std::string &tuning_ranges,
const std::string &description, uint64_t rotate_secs, bool pre_fft,
bool tag_now, bool low_power_hold_down, bool slew_rx_time,
size_t peak_fft_range)
uint64_t tune_jitter_hz, uint64_t freq_start, uint64_t freq_end,
uint64_t tune_step_hz, uint64_t tune_step_fft, uint64_t skip_tune_step_fft,
double fft_min, double fft_max, const std::string &sdir,
uint64_t write_step_fft, double bucket_range,
const std::string &tuning_ranges, const std::string &description,
uint64_t rotate_secs, bool pre_fft, bool tag_now, bool low_power_hold_down,
bool slew_rx_time, size_t peak_fft_range)
: gr::block("retune_fft",
gr::io_signature::make(1 /* min inputs */, 1 /* max inputs */,
nfft * sizeof(input_type)),
gr::io_signature::makev(
2 /* min outputs */, 2 /* max outputs */,
std::vector<int>{(int)sizeof(output_type),
(int)(nfft * sizeof(input_type))})),
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),
retuner_impl(samp_rate, tune_jitter_hz, 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), 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),
Expand All @@ -274,6 +273,13 @@ retune_fft_impl::retune_fft_impl(
[this](const pmt::pmt_t &msg) { next_retune_(host_now_()); });
set_tag_propagation_policy(TPP_DONT);
reset_items_();
// If the pre-FFT block is handling tuning, then it will have already sent
// a tuning message, start at tuning step 1.
// We still need the retuner class to keep state, so we know which tuning
// range we are in and if we have started a new sweep.
if (pre_fft) {
need_retune_(1);
}
}

void retune_fft_impl::reset_items_() {
Expand Down
3 changes: 2 additions & 1 deletion lib/retune_fft_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ class retune_fft_impl : public retune_fft, base_impl, retuner_impl {

public:
retune_fft_impl(const std::string &tag, size_t nfft, uint64_t samp_rate,
uint64_t freq_start, uint64_t freq_end, uint64_t tune_step_hz,
uint64_t tune_jitter_hz, uint64_t freq_start,
uint64_t freq_end, uint64_t tune_step_hz,
uint64_t tune_step_fft, uint64_t skip_tune_step_fft,
double fft_min, double fft_max, const std::string &sdir,
uint64_t write_step_fft, double bucket_range,
Expand Down
35 changes: 17 additions & 18 deletions lib/retune_pre_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,34 +210,33 @@
namespace gr {
namespace iqtlabs {

retune_pre_fft::sptr
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) {
retune_pre_fft::sptr retune_pre_fft::make(
size_t nfft, uint64_t samp_rate, uint64_t tune_jitter_hz,
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<retune_pre_fft_impl>(
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);
nfft, samp_rate, tune_jitter_hz, 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, 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)
size_t nfft, uint64_t samp_rate, uint64_t tune_jitter_hz,
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(
"retune_pre_fft",
gr::io_signature::make(1 /* min inputs */, 1 /* max inputs */,
sizeof(block_type)),
gr::io_signature::make(1 /* min outputs */, 1 /* max outputs */,
sizeof(block_type) * nfft * fft_batch_size)),
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),
retuner_impl(samp_rate, tune_jitter_hz, 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)) {
message_port_register_out(TUNE_KEY);
unsigned int alignment = volk_get_alignment();
Expand Down
9 changes: 5 additions & 4 deletions lib/retune_pre_fft_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,11 @@ class retune_pre_fft_impl : public retune_pre_fft, base_impl, retuner_impl {
boost::scoped_ptr<float> total_;

public:
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,
retune_pre_fft_impl(size_t nfft, uint64_t samp_rate, uint64_t tune_jitter_hz,
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);
~retune_pre_fft_impl();
Expand Down
38 changes: 24 additions & 14 deletions lib/retuner_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,25 @@
namespace gr {
namespace iqtlabs {

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,
retuner_impl::retuner_impl(uint64_t samp_rate, uint64_t tune_jitter_hz,
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)
: 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) {
: samp_rate_(samp_rate), tune_jitter_hz_(tune_jitter_hz),
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) {
std::random_device rand_dev;
// cppcheck-suppress useInitializationList
rand_gen_ = std::mt19937(rand_dev());
rand_dist_ = std::uniform_int_distribution<int>(0, (int)tune_jitter_hz);
parse_tuning_ranges_(tuning_ranges);
if (low_power_hold_down_ && !stare_mode_) {
reset_tags_ = true;
Expand Down Expand Up @@ -304,8 +309,13 @@ void retuner_impl::next_retune_(TIME_T host_now) {
return;
}
size_t range_steps = tuning_ranges_[tuning_range_].steps;
tune_freq_ = std::min(tune_freq_ + tune_step_hz_,
tuning_ranges_[tuning_range_].freq_end);
tune_freq_ = tune_freq_ + tune_step_hz_;
if (!stare_mode_ && tune_jitter_hz_ > 0) {
tune_freq_ -= tune_jitter_hz_;
FREQ_T offset = rand_dist_(rand_gen_);
tune_freq_ += offset;
}
tune_freq_ = std::min(tune_freq_, tuning_ranges_[tuning_range_].freq_end);
++tuning_range_step_;
if (last_sweep_start_ == 0) {
last_sweep_start_ = host_now;
Expand Down
8 changes: 6 additions & 2 deletions lib/retuner_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
#include "iqtlabs_types.h"
#include <cstddef>
#include <cstdint>
#include <random>
#include <string>
#include <vector>

Expand All @@ -226,8 +227,8 @@ typedef struct {

class retuner_impl {
public:
retuner_impl(uint64_t samp_rate, uint64_t freq_start, uint64_t freq_end,
uint64_t tune_step_hz, uint64_t tune_step_fft,
retuner_impl(uint64_t samp_rate, uint64_t tune_jitter_hz, 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);
Expand All @@ -236,6 +237,7 @@ class retuner_impl {
void next_retune_(TIME_T host_now);
TIME_T apply_rx_time_slew_(TIME_T rx_time);
uint64_t samp_rate_;
uint64_t tune_jitter_hz_;
uint64_t freq_start_;
uint64_t freq_end_;
uint64_t tune_step_hz_;
Expand All @@ -261,6 +263,8 @@ class retuner_impl {
bool stare_mode_;
bool in_hold_down_;
bool reset_tags_;
std::mt19937 rand_gen_;
std::uniform_int_distribution<int> rand_dist_;
};
} /* namespace iqtlabs */
} /* namespace gr */
1 change: 1 addition & 0 deletions python/iqtlabs/bindings/failed_conversions.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
./include/gnuradio/iqtlabs/retune_pre_fft.hError occurred while running CASTXML xml file does not exist
./include/gnuradio/iqtlabs/retune_fft.hError occurred while running CASTXML xml file does not exist
3 changes: 2 additions & 1 deletion python/iqtlabs/bindings/retune_fft_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(retune_fft.h) */
/* BINDTOOL_HEADER_FILE_HASH(b79ce98f7df88b5148f31e77fe929369) */
/* BINDTOOL_HEADER_FILE_HASH(b719d36e60bfabb3278dde87340455f0) */
/***********************************************************************************/

#include <pybind11/complex.h>
Expand All @@ -40,6 +40,7 @@ void bind_retune_fft(py::module& m)
py::arg("tag"),
py::arg("nfft"),
py::arg("samp_rate"),
py::arg("tune_jitter_hz"),
py::arg("freq_start"),
py::arg("freq_end"),
py::arg("tune_step_hz"),
Expand Down
Loading

0 comments on commit 5d11327

Please sign in to comment.