Skip to content

Commit

Permalink
Merge pull request #208 from anarkiwi/clk5
Browse files Browse the repository at this point in the history
add slew time adjustment.
  • Loading branch information
anarkiwi authored Feb 6, 2024
2 parents 40a1968 + 1515d89 commit b6046f6
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 43 deletions.
11 changes: 7 additions & 4 deletions grc/iqtlabs_retune_pre_fft.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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})
Expand All @@ -49,15 +50,17 @@ 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']

parameters:
- id: nfft
dtype: int
- id: samp_rate
dtype: int
- id: fft_batch_size
dtype: int
- id: tag
Expand Down
8 changes: 4 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,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);
};
Expand Down
15 changes: 8 additions & 7 deletions lib/retune_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,13 @@ retune_fft_impl::retune_fft_impl(
2 /* min outputs */, 2 /* max outputs */,
std::vector<int>{(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();
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion lib/retune_fft_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
24 changes: 14 additions & 10 deletions lib/retune_pre_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<retune_pre_fft_impl>(
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(
Expand All @@ -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)) {
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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;
}
}
Expand All @@ -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_);
Expand Down
2 changes: 1 addition & 1 deletion lib/retune_pre_fft_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ 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 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,
Expand Down
32 changes: 21 additions & 11 deletions lib/retuner_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
11 changes: 7 additions & 4 deletions lib/retuner_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -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_range_t> tuning_ranges_;
bool stare_mode_;
bool in_hold_down_;
Expand Down
3 changes: 2 additions & 1 deletion python/iqtlabs/bindings/retune_pre_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_pre_fft.h) */
/* BINDTOOL_HEADER_FILE_HASH(a40fbc21c2cdc0aac7419b17997d001c) */
/* BINDTOOL_HEADER_FILE_HASH(b7616b720066a13e82470e7cfe4fc614) */
/***********************************************************************************/

#include <pybind11/complex.h>
Expand All @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions python/iqtlabs/qa_retune_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit b6046f6

Please sign in to comment.