From 738bcdca857c641aad24a36e7369b98bffabad9b Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Fri, 20 Oct 2023 04:27:25 +0000 Subject: [PATCH] output filtered FFT points from retune_fft. --- grc/iqtlabs_retune_fft.block.yml | 4 ++++ lib/retune_fft_impl.cc | 41 ++++++++++++++++++++++++-------- lib/retune_fft_impl.h | 6 +++-- python/iqtlabs/qa_retune_fft.py | 7 ++++-- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/grc/iqtlabs_retune_fft.block.yml b/grc/iqtlabs_retune_fft.block.yml index 5cdcf526..3dd30c93 100644 --- a/grc/iqtlabs_retune_fft.block.yml +++ b/grc/iqtlabs_retune_fft.block.yml @@ -138,6 +138,10 @@ outputs: domain: stream dtype: byte vlen: 1 + - label: fft_output + domain: stream + dtype: float + vlen: ${ nfft } - label: tune domain: message - label: json diff --git a/lib/retune_fft_impl.cc b/lib/retune_fft_impl.cc index 222ac230..902e615d 100644 --- a/lib/retune_fft_impl.cc +++ b/lib/retune_fft_impl.cc @@ -244,8 +244,10 @@ retune_fft_impl::retune_fft_impl( : gr::block("retune_fft", gr::io_signature::make(1 /* min inputs */, 1 /* max inputs */, vlen * sizeof(input_type)), - gr::io_signature::make(1 /* min outputs */, 1 /*max outputs */, - sizeof(output_type))), + gr::io_signature::makev( + 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, skip_tune_step_fft, tuning_ranges), tag_(pmt::intern(tag)), vlen_(vlen), nfft_(nfft), samp_rate_(samp_rate), @@ -312,7 +314,9 @@ void retune_fft_impl::sum_items_(const input_type *in) { } } -void retune_fft_impl::process_items_(size_t c, const input_type *&in) { +size_t retune_fft_impl::process_items_(size_t c, const input_type *&in, + const input_type *&fft_output) { + size_t fft_output_items = 0; for (size_t i = 0; i < c; ++i) { for (size_t j = 0; j < (vlen_ / nfft_); ++j, in += nfft_) { if (skip_fft_count_) { @@ -326,9 +330,13 @@ void retune_fft_impl::process_items_(size_t c, const input_type *&in) { if (in_max < fft_min_) { continue; } + std::memcpy((void *)fft_output, (const void *)in, + nfft_ * sizeof(input_type)); + fft_output += nfft_; write_items_(in); sum_items_(in); ++sample_count_; + ++fft_output_items; if (need_retune_(1)) { if (!pre_fft_) { retune_now_(); @@ -336,11 +344,13 @@ void retune_fft_impl::process_items_(size_t c, const input_type *&in) { } } } + return fft_output_items; } void retune_fft_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required) { ninput_items_required[0] = 1; + ninput_items_required[1] = noutput_items * (vlen_ / nfft_); } void retune_fft_impl::output_buckets_( @@ -441,14 +451,16 @@ void retune_fft_impl::process_buckets_(uint64_t rx_freq, double rx_time) { } void retune_fft_impl::process_tags_(const input_type *in, size_t in_count, - size_t in_first) { + size_t in_first, + const input_type *fft_output) { std::vector all_tags, rx_freq_tags; std::vector rx_times; get_tags_in_window(all_tags, 0, 0, in_count); get_tags(tag_, all_tags, rx_freq_tags, rx_times, in_count); + size_t fft_output_items = 0; if (rx_freq_tags.empty()) { - process_items_(in_count, in); + fft_output_items += process_items_(in_count, in, fft_output); } else { for (size_t t = 0; t < rx_freq_tags.size(); ++t) { const auto &tag = rx_freq_tags[t]; @@ -457,7 +469,7 @@ void retune_fft_impl::process_tags_(const input_type *in, size_t in_count, in_first += rel; if (rel > 0) { - process_items_(rel, in); + fft_output_items += process_items_(rel, in, fft_output); } const uint64_t rx_freq = (uint64_t)pmt::to_double(tag.value); @@ -469,6 +481,8 @@ void retune_fft_impl::process_tags_(const input_type *in, size_t in_count, process_buckets_(rx_freq, rx_time); } } + + produce(1, fft_output_items); } int retune_fft_impl::general_work(int noutput_items, @@ -482,16 +496,23 @@ int retune_fft_impl::general_work(int noutput_items, auto to = from + leftover; std::copy(from, to, out); out_buf_.erase(from, to); - return leftover; + produce(0, leftover); + produce(1, 0); + return WORK_CALLED_PRODUCE; } + const input_type *fft_output = + static_cast(output_items[1]); const input_type *in = static_cast(input_items[0]); - size_t in_count = ninput_items[0]; + + float max_input_items = noutput_items * nfft_ / vlen_; + size_t in_count = std::min(ninput_items[0], int(max_input_items)); size_t in_first = nitems_read(0); - process_tags_(in, in_count, in_first); + process_tags_(in, in_count, in_first, fft_output); consume_each(in_count); + produce(0, 0); - return 0; + return WORK_CALLED_PRODUCE; } } /* namespace iqtlabs */ } /* namespace gr */ diff --git a/lib/retune_fft_impl.h b/lib/retune_fft_impl.h index 854b8c39..1120d090 100644 --- a/lib/retune_fft_impl.h +++ b/lib/retune_fft_impl.h @@ -224,7 +224,8 @@ class retune_fft_impl : public retune_fft, base_impl, retuner_impl { void retune_now_(); void write_items_(const input_type *in); void sum_items_(const input_type *in); - void process_items_(size_t c, const input_type *&in); + size_t process_items_(size_t c, const input_type *&in, + const input_type *&fft_output); void output_buckets_(const std::string &name, const std::list> &buckets, std::stringstream &ss); @@ -232,7 +233,8 @@ class retune_fft_impl : public retune_fft, base_impl, retuner_impl { void send_retune_(uint64_t tune_freq); void process_buckets_(uint64_t rx_freq, double rx_time); void write_buckets_(double host_now, uint64_t rx_freq); - void process_tags_(const input_type *in, size_t in_count, size_t in_first); + void process_tags_(const input_type *in, size_t in_count, size_t in_first, + const input_type *fft_output); void write_(const char *data, size_t len); void open_(const std::string &file); void close_(); diff --git a/python/iqtlabs/qa_retune_fft.py b/python/iqtlabs/qa_retune_fft.py index 0b0a2f68..d8a1911f 100755 --- a/python/iqtlabs/qa_retune_fft.py +++ b/python/iqtlabs/qa_retune_fft.py @@ -270,8 +270,8 @@ def retune_fft(self, fft_roll): points = int(2048) samp_rate = int(points * points) tune_step_hz = samp_rate - tune_step_fft = int(64) - skip_tune_step_fft = int(2) + tune_step_fft = int(256) + skip_tune_step_fft = int(16) freq_start = int(1e9 / samp_rate) * samp_rate freq_end = int(1.1e9 / samp_rate) * samp_rate freq_mid = ((freq_end - freq_start) / 2) + freq_start @@ -339,6 +339,8 @@ def retune_fft(self, fft_roll): ) blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1, test_file, False) blocks_file_sink_0.set_unbuffered(False) + blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float * points) + blocks_complex_to_mag_0 = blocks.complex_to_mag(points) blocks_nlog10_ff_0 = blocks.nlog10_ff(20, points, 0) vr1 = vector_roll(points) @@ -360,6 +362,7 @@ def retune_fft(self, fft_roll): self.tb.connect((fft_vxx_0, 0), (vr1, 0)) self.tb.connect((vr1, 0), (blocks_complex_to_mag_0, 0)) self.tb.connect((iqtlabs_retune_fft_0, 0), (blocks_file_sink_0, 0)) + self.tb.connect((iqtlabs_retune_fft_0, 1), (blocks_null_sink_0, 0)) self.tb.connect((iqtlabs_retune_pre_fft_0, 0), (window, 0)) self.tb.connect((window, 0), (fft_vxx_0, 0)) self.tb.connect((blocks_throttle_0, 0), (iqtlabs_retune_pre_fft_0, 0))