Skip to content

Commit

Permalink
Merge pull request #131 from anarkiwi/out2
Browse files Browse the repository at this point in the history
output filtered FFT points from retune_fft.
  • Loading branch information
anarkiwi authored Oct 20, 2023
2 parents f784098 + 738bcdc commit 756c348
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
4 changes: 4 additions & 0 deletions grc/iqtlabs_retune_fft.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 31 additions & 10 deletions lib/retune_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>{(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),
Expand Down Expand Up @@ -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_) {
Expand All @@ -326,21 +330,27 @@ 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_();
}
}
}
}
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_(
Expand Down Expand Up @@ -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<tag_t> all_tags, rx_freq_tags;
std::vector<double> 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];
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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<const input_type *>(output_items[1]);
const input_type *in = static_cast<const input_type *>(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 */
6 changes: 4 additions & 2 deletions lib/retune_fft_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,17 @@ 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<std::pair<double, double>> &buckets,
std::stringstream &ss);
void reopen_(double host_now, uint64_t rx_freq);
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_();
Expand Down
7 changes: 5 additions & 2 deletions python/iqtlabs/qa_retune_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down

0 comments on commit 756c348

Please sign in to comment.