From 85ce667d7b20fae58de4ecf4afc773549eb2a089 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Fri, 13 Sep 2019 23:10:23 +0200 Subject: [PATCH] Added more pilot symbols for precision frequency estimation This adds 4 pilot symbols each after 128 and 256 data symbols. These are used for precision frequency estimation and feed-forward correction, resulting in less decoder errors at the end of the packet. Due to this change, this system can no longer transmit packets shorter than 64 bytes! --- gr-hamnet70/grc/CMakeLists.txt | 4 +- ...et70_correct_frequency_from_pilot_syms.xml | 38 ++++ .../grc/hamnet70_insert_pilot_symbols.xml | 32 +++ gr-hamnet70/include/hamnet70/CMakeLists.txt | 4 +- .../correct_frequency_from_pilot_syms.h | 56 +++++ .../include/hamnet70/insert_pilot_symbols.h | 56 +++++ gr-hamnet70/lib/CMakeLists.txt | 2 + .../correct_frequency_from_pilot_syms_impl.cc | 210 ++++++++++++++++++ .../correct_frequency_from_pilot_syms_impl.h | 65 ++++++ gr-hamnet70/lib/insert_pilot_symbols_impl.cc | 107 +++++++++ gr-hamnet70/lib/insert_pilot_symbols_impl.h | 53 +++++ gr-hamnet70/python/CMakeLists.txt | 2 + .../qa_correct_frequency_from_pilot_syms.py | 41 ++++ gr-hamnet70/python/qa_insert_pilot_symbols.py | 41 ++++ gr-hamnet70/swig/hamnet70_swig.i | 6 + grc/hamnet70_demod_sc16qam.grc | 73 +++++- grc/hamnet70_mod_sc16qam.grc | 8 +- tmp/test_sc16qam.grc | 125 ++++++++++- 18 files changed, 903 insertions(+), 20 deletions(-) create mode 100644 gr-hamnet70/grc/hamnet70_correct_frequency_from_pilot_syms.xml create mode 100644 gr-hamnet70/grc/hamnet70_insert_pilot_symbols.xml create mode 100644 gr-hamnet70/include/hamnet70/correct_frequency_from_pilot_syms.h create mode 100644 gr-hamnet70/include/hamnet70/insert_pilot_symbols.h create mode 100644 gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.cc create mode 100644 gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.h create mode 100644 gr-hamnet70/lib/insert_pilot_symbols_impl.cc create mode 100644 gr-hamnet70/lib/insert_pilot_symbols_impl.h create mode 100755 gr-hamnet70/python/qa_correct_frequency_from_pilot_syms.py create mode 100755 gr-hamnet70/python/qa_insert_pilot_symbols.py diff --git a/gr-hamnet70/grc/CMakeLists.txt b/gr-hamnet70/grc/CMakeLists.txt index 8ff9626..aedba5e 100644 --- a/gr-hamnet70/grc/CMakeLists.txt +++ b/gr-hamnet70/grc/CMakeLists.txt @@ -24,5 +24,7 @@ install(FILES hamnet70_pid_controller.xml hamnet70_insert_delayed_tag.xml hamnet70_scrambler.xml - hamnet70_async_scrambler.xml DESTINATION share/gnuradio/grc/blocks + hamnet70_async_scrambler.xml + hamnet70_insert_pilot_symbols.xml + hamnet70_correct_frequency_from_pilot_syms.xml DESTINATION share/gnuradio/grc/blocks ) diff --git a/gr-hamnet70/grc/hamnet70_correct_frequency_from_pilot_syms.xml b/gr-hamnet70/grc/hamnet70_correct_frequency_from_pilot_syms.xml new file mode 100644 index 0000000..196ab09 --- /dev/null +++ b/gr-hamnet70/grc/hamnet70_correct_frequency_from_pilot_syms.xml @@ -0,0 +1,38 @@ + + + Correct Frequency from Pilot Symbols + hamnet70_correct_frequency_from_pilot_syms + [hamnet70] + import hamnet70 + hamnet70.correct_frequency_from_pilot_syms($pilot_sequence, $offsets, $phase_ref_offset, $start_tag) + + Pilot Sequence + pilot_sequence + complex_vector + + + Insertion Positions + offsets + int_vector + + + Phase Reference Index + phase_ref_offset + int + + + + Start Tag Key + start_tag + string + + + + in + complex + + + out + complex + + diff --git a/gr-hamnet70/grc/hamnet70_insert_pilot_symbols.xml b/gr-hamnet70/grc/hamnet70_insert_pilot_symbols.xml new file mode 100644 index 0000000..024699b --- /dev/null +++ b/gr-hamnet70/grc/hamnet70_insert_pilot_symbols.xml @@ -0,0 +1,32 @@ + + + Insert Pilot Symbols + hamnet70_insert_pilot_symbols + [hamnet70] + import hamnet70 + hamnet70.insert_pilot_symbols($pilot_sequence, $offsets, $length_tag) + + Pilot Sequence + pilot_sequence + complex_vector + + + Insertion Positions + offsets + int_vector + + + Length Tag Key + length_tag + string + + + + in + complex + + + out + complex + + diff --git a/gr-hamnet70/include/hamnet70/CMakeLists.txt b/gr-hamnet70/include/hamnet70/CMakeLists.txt index 0b2749f..cdd8f5d 100644 --- a/gr-hamnet70/include/hamnet70/CMakeLists.txt +++ b/gr-hamnet70/include/hamnet70/CMakeLists.txt @@ -29,5 +29,7 @@ install(FILES pid_controller.h insert_delayed_tag.h scrambler.h - async_scrambler.h DESTINATION include/hamnet70 + async_scrambler.h + insert_pilot_symbols.h + correct_frequency_from_pilot_syms.h DESTINATION include/hamnet70 ) diff --git a/gr-hamnet70/include/hamnet70/correct_frequency_from_pilot_syms.h b/gr-hamnet70/include/hamnet70/correct_frequency_from_pilot_syms.h new file mode 100644 index 0000000..c5259d7 --- /dev/null +++ b/gr-hamnet70/include/hamnet70/correct_frequency_from_pilot_syms.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 Thomas Kolb. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + + +#ifndef INCLUDED_HAMNET70_CORRECT_FREQUENCY_FROM_PILOT_SYMS_H +#define INCLUDED_HAMNET70_CORRECT_FREQUENCY_FROM_PILOT_SYMS_H + +#include +#include + +namespace gr { + namespace hamnet70 { + + /*! + * \brief <+description of block+> + * \ingroup hamnet70 + * + */ + class HAMNET70_API correct_frequency_from_pilot_syms : virtual public gr::block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * \brief Return a shared_ptr to a new instance of hamnet70::correct_frequency_from_pilot_syms. + * + * To avoid accidental use of raw pointers, hamnet70::correct_frequency_from_pilot_syms's + * constructor is in a private implementation + * class. hamnet70::correct_frequency_from_pilot_syms::make is the public interface for + * creating new instances. + */ + static sptr make(const std::vector &pilot_sequence, const std::vector &offsets, size_t phase_ref_offset = 0, const std::string &start_tag = "corr_est"); + }; + + } // namespace hamnet70 +} // namespace gr + +#endif /* INCLUDED_HAMNET70_CORRECT_FREQUENCY_FROM_PILOT_SYMS_H */ + diff --git a/gr-hamnet70/include/hamnet70/insert_pilot_symbols.h b/gr-hamnet70/include/hamnet70/insert_pilot_symbols.h new file mode 100644 index 0000000..d33521c --- /dev/null +++ b/gr-hamnet70/include/hamnet70/insert_pilot_symbols.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 Thomas Kolb. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + + +#ifndef INCLUDED_HAMNET70_INSERT_PILOT_SYMBOLS_H +#define INCLUDED_HAMNET70_INSERT_PILOT_SYMBOLS_H + +#include +#include + +namespace gr { + namespace hamnet70 { + + /*! + * \brief <+description of block+> + * \ingroup hamnet70 + * + */ + class HAMNET70_API insert_pilot_symbols : virtual public gr::tagged_stream_block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * \brief Return a shared_ptr to a new instance of hamnet70::insert_pilot_symbols. + * + * To avoid accidental use of raw pointers, hamnet70::insert_pilot_symbols's + * constructor is in a private implementation + * class. hamnet70::insert_pilot_symbols::make is the public interface for + * creating new instances. + */ + static sptr make(const std::vector &pilot_sequence, const std::vector &offsets, const std::string &length_tag); + }; + + } // namespace hamnet70 +} // namespace gr + +#endif /* INCLUDED_HAMNET70_INSERT_PILOT_SYMBOLS_H */ + diff --git a/gr-hamnet70/lib/CMakeLists.txt b/gr-hamnet70/lib/CMakeLists.txt index 1143942..7d8617f 100644 --- a/gr-hamnet70/lib/CMakeLists.txt +++ b/gr-hamnet70/lib/CMakeLists.txt @@ -33,6 +33,8 @@ list(APPEND hamnet70_sources insert_delayed_tag_impl.cc scrambler_impl.cc async_scrambler_impl.cc + insert_pilot_symbols_impl.cc + correct_frequency_from_pilot_syms_impl.cc ) set(hamnet70_sources "${hamnet70_sources}" PARENT_SCOPE) diff --git a/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.cc b/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.cc new file mode 100644 index 0000000..1fe3bdc --- /dev/null +++ b/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.cc @@ -0,0 +1,210 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 Thomas Kolb. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include +#include "correct_frequency_from_pilot_syms_impl.h" + +namespace gr { + namespace hamnet70 { + + correct_frequency_from_pilot_syms::sptr + correct_frequency_from_pilot_syms::make(const std::vector &pilot_sequence, const std::vector &offsets, size_t phase_ref_offset, const std::string &start_tag) + { + return gnuradio::get_initial_sptr + (new correct_frequency_from_pilot_syms_impl(pilot_sequence, offsets, phase_ref_offset, start_tag)); + } + + /* + * The private constructor + */ + correct_frequency_from_pilot_syms_impl::correct_frequency_from_pilot_syms_impl(const std::vector &pilot_sequence, const std::vector &offsets, size_t phase_ref_offset, const std::string &start_tag) + : gr::block("correct_frequency_from_pilot_syms", + gr::io_signature::make(1, 1, sizeof(gr_complex)), + gr::io_signature::make(1, 1, sizeof(gr_complex))), + d_pilot_sequence(pilot_sequence), + d_offsets(offsets), + d_phase_ref_offset(phase_ref_offset), + d_start_tag(pmt::intern(start_tag)), + d_items_required(*std::max_element(offsets.begin(), offsets.end()) + pilot_sequence.size()), + d_tag_found(false), + d_phase_inc_per_symbol(0.0f), + d_current_phase(0.0f) + { + set_tag_propagation_policy(TPP_CUSTOM); + } + + /* + * Our virtual destructor. + */ + correct_frequency_from_pilot_syms_impl::~correct_frequency_from_pilot_syms_impl() + { + } + + void + correct_frequency_from_pilot_syms_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required) + { + ninput_items_required[0] = noutput_items + d_pilot_sequence.size() * d_offsets.size(); + } + + int + correct_frequency_from_pilot_syms_impl::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *in = (const gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + + int consumed = 0, produced = 0; + + std::vector tags; + get_tags_in_window(tags, 0, 0, ninput_items[0], d_start_tag); + size_t tagidx = 0; + + for(int i = 0; i < ninput_items[0]; i++) { + if((tagidx < tags.size()) && (tags[tagidx].offset == nitems_read(0) + i)) { + d_packet.clear(); + d_tags_in_packet.clear(); + d_tag_found = true; + + tagidx++; + } + + if(!d_tag_found) { + // tag propagation + std::vector prop_tags; + get_tags_in_window(prop_tags, 0, consumed, consumed+1); + + for(tag_t &tag: prop_tags) { + tag.offset = nitems_written(0) + produced; + add_item_tag(0, tag); + } + + // calculate sample + d_current_phase += d_phase_inc_per_symbol; + out[produced++] = in[consumed++] * gr_expj(d_current_phase); + } else if(d_tag_found && d_packet.size() < d_items_required) { + // get and store tags for later insertion in the output stream + std::vector prop_tags; + get_tags_in_window(prop_tags, 0, consumed, consumed+1); + + for(tag_t &tag: prop_tags) { + tag.offset = d_packet.size(); + d_tags_in_packet.push_back(tag); + } + + d_packet.push_back(in[consumed++]); + } else if(d_packet.size() == d_items_required) { + + // frequency estimation + float phase_sum = 0.0f; + size_t last_off = d_phase_ref_offset; + float last_phase = 0.0f; + + for(size_t off: d_offsets) { + gr_complex sum(0, 0); + + size_t n = 0; + for(const gr_complex &ref_sym: d_pilot_sequence) { + sum += d_packet[off+n] * conj(ref_sym); + n++; + } + + sum /= n; + + float phase = gr::fast_atan2f(sum); // FIXME? unwrap + phase_sum += (phase - last_phase) / (off - last_off); + last_phase = phase; + last_off = off; + } + + d_phase_inc_per_symbol = -phase_sum / d_offsets.size(); + d_current_phase = (-(int)d_phase_ref_offset - 1) * d_phase_inc_per_symbol; + + //std::cout << "initial phase: " << d_current_phase << std::endl; + //std::cout << "phase increment: " << d_phase_inc_per_symbol << std::endl; + + size_t drop_start = 1; + size_t drop_end = 0; + size_t next_off_idx = 0; + + //std::cout << "packet = ["; + + std::vector::iterator tag_iter = d_tags_in_packet.begin(); + + for(size_t i = 0; i < d_packet.size(); i++) { + d_current_phase += d_phase_inc_per_symbol; + + if(i == drop_end) { + if(next_off_idx >= d_offsets.size()) { + drop_end = drop_start = d_packet.size(); // index cannot be reached + } else { + drop_start = d_offsets[next_off_idx]; + drop_end = d_offsets[next_off_idx] + d_pilot_sequence.size(); + + next_off_idx++; + } + } + + if(i >= drop_start) { + continue; + } + + // restore tags + while(tag_iter != d_tags_in_packet.end() && + tag_iter->offset <= i) { + tag_iter->offset = nitems_written(0) + produced; + add_item_tag(0, *tag_iter); + tag_iter++; + } + + gr_complex &item = d_packet[i]; + out[produced++] = item * gr_expj(d_current_phase); + + gr_complex &c = out[produced-1]; + //std::cout << c.real() << "+" << c.imag() << "j, "; + } + + //std::cout << "]" << std::endl; + + d_tag_found = false; + } + } + + + // Tell runtime system how many input items we consumed on + // each input stream. + consume_each (consumed); + + // Tell runtime system how many output items we produced. + return produced; + } + + } /* namespace hamnet70 */ +} /* namespace gr */ + diff --git a/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.h b/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.h new file mode 100644 index 0000000..5eec2e3 --- /dev/null +++ b/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 Thomas Kolb. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_HAMNET70_CORRECT_FREQUENCY_FROM_PILOT_SYMS_IMPL_H +#define INCLUDED_HAMNET70_CORRECT_FREQUENCY_FROM_PILOT_SYMS_IMPL_H + +#include + +#include + +namespace gr { + namespace hamnet70 { + + class correct_frequency_from_pilot_syms_impl : public correct_frequency_from_pilot_syms + { + private: + std::vector d_offsets; + std::vector d_pilot_sequence; + size_t d_phase_ref_offset; + pmt::pmt_t d_start_tag; + + std::vector d_tags_in_packet; + + std::vector d_packet; + + size_t d_items_required; + bool d_tag_found; + float d_phase_inc_per_symbol; + float d_current_phase; + + public: + correct_frequency_from_pilot_syms_impl(const std::vector &pilot_sequence, const std::vector &offsets, size_t phase_ref_offset, const std::string &start_tag); + ~correct_frequency_from_pilot_syms_impl(); + + // Where all the action really happens + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + + int general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } // namespace hamnet70 +} // namespace gr + +#endif /* INCLUDED_HAMNET70_CORRECT_FREQUENCY_FROM_PILOT_SYMS_IMPL_H */ + diff --git a/gr-hamnet70/lib/insert_pilot_symbols_impl.cc b/gr-hamnet70/lib/insert_pilot_symbols_impl.cc new file mode 100644 index 0000000..c3c0692 --- /dev/null +++ b/gr-hamnet70/lib/insert_pilot_symbols_impl.cc @@ -0,0 +1,107 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 Thomas Kolb. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "insert_pilot_symbols_impl.h" + +namespace gr { + namespace hamnet70 { + + insert_pilot_symbols::sptr + insert_pilot_symbols::make(const std::vector &pilot_sequence, const std::vector &offsets, const std::string &length_tag) + { + return gnuradio::get_initial_sptr + (new insert_pilot_symbols_impl(pilot_sequence, offsets, length_tag)); + } + + /* + * The private constructor + */ + insert_pilot_symbols_impl::insert_pilot_symbols_impl(const std::vector &pilot_sequence, const std::vector &offsets, const std::string &length_tag) + : gr::tagged_stream_block("insert_pilot_symbols", + gr::io_signature::make(1, 1, sizeof(gr_complex)), + gr::io_signature::make(1, 1, sizeof(gr_complex)), length_tag), + d_pilot_sequence(pilot_sequence), + d_offsets(offsets) + {} + + /* + * Our virtual destructor. + */ + insert_pilot_symbols_impl::~insert_pilot_symbols_impl() + { + } + + int + insert_pilot_symbols_impl::calculate_output_stream_length(const gr_vector_int &ninput_items) + { + int noutput_items = ninput_items[0] + d_pilot_sequence.size() * d_offsets.size(); + return noutput_items ; + } + + int + insert_pilot_symbols_impl::work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *in = (const gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + + size_t in_pos = 0; + size_t out_pos = 0; + size_t offset_idx = 0; + size_t cur_offset = d_offsets[0]; + + while(in_pos < ninput_items[0] && out_pos < noutput_items) { + if(in_pos == cur_offset) { + // insert preamble before cur_offset + for(const gr_complex &v : d_pilot_sequence) { + out[out_pos++] = v; + } + + offset_idx++; + if(offset_idx >= d_offsets.size()) { + // end of list reached => set to 0, which will never be valid + // again for this packet + cur_offset = 0; + } else { + cur_offset = d_offsets[offset_idx]; + } + } + + // copy input packet symbol + out[out_pos] = in[in_pos]; + + out_pos++; + in_pos++; + } + + // Tell runtime system how many output items we produced. + return out_pos; + } + + } /* namespace hamnet70 */ +} /* namespace gr */ + diff --git a/gr-hamnet70/lib/insert_pilot_symbols_impl.h b/gr-hamnet70/lib/insert_pilot_symbols_impl.h new file mode 100644 index 0000000..11ef2df --- /dev/null +++ b/gr-hamnet70/lib/insert_pilot_symbols_impl.h @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 Thomas Kolb. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_HAMNET70_INSERT_PILOT_SYMBOLS_IMPL_H +#define INCLUDED_HAMNET70_INSERT_PILOT_SYMBOLS_IMPL_H + +#include + +namespace gr { + namespace hamnet70 { + + class insert_pilot_symbols_impl : public insert_pilot_symbols + { + private: + std::vector d_offsets; + std::vector d_pilot_sequence; + + protected: + int calculate_output_stream_length(const gr_vector_int &ninput_items); + + public: + insert_pilot_symbols_impl(const std::vector &pilot_sequence, const std::vector &offsets, const std::string &length_tag); + ~insert_pilot_symbols_impl(); + + // Where all the action really happens + int work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } // namespace hamnet70 +} // namespace gr + +#endif /* INCLUDED_HAMNET70_INSERT_PILOT_SYMBOLS_IMPL_H */ + diff --git a/gr-hamnet70/python/CMakeLists.txt b/gr-hamnet70/python/CMakeLists.txt index 0be348d..9ef778e 100644 --- a/gr-hamnet70/python/CMakeLists.txt +++ b/gr-hamnet70/python/CMakeLists.txt @@ -49,3 +49,5 @@ set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig) #GR_ADD_TEST(qa_insert_delayed_tag ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_insert_delayed_tag.py) #GR_ADD_TEST(qa_scrambler ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_scrambler.py) #GR_ADD_TEST(qa_async_scrambler ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_async_scrambler.py) +#GR_ADD_TEST(qa_insert_pilot_symbols ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_insert_pilot_symbols.py) +#GR_ADD_TEST(qa_correct_frequency_from_pilot_syms ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_correct_frequency_from_pilot_syms.py) diff --git a/gr-hamnet70/python/qa_correct_frequency_from_pilot_syms.py b/gr-hamnet70/python/qa_correct_frequency_from_pilot_syms.py new file mode 100755 index 0000000..afaa345 --- /dev/null +++ b/gr-hamnet70/python/qa_correct_frequency_from_pilot_syms.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2019 Thomas Kolb. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +from gnuradio import blocks +import hamnet70_swig as hamnet70 + +class qa_correct_frequency_from_pilot_syms (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_t (self): + # set up fg + self.tb.run () + # check data + + +if __name__ == '__main__': + gr_unittest.run(qa_correct_frequency_from_pilot_syms, "qa_correct_frequency_from_pilot_syms.xml") diff --git a/gr-hamnet70/python/qa_insert_pilot_symbols.py b/gr-hamnet70/python/qa_insert_pilot_symbols.py new file mode 100755 index 0000000..8bd9697 --- /dev/null +++ b/gr-hamnet70/python/qa_insert_pilot_symbols.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2019 Thomas Kolb. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +from gnuradio import blocks +import hamnet70_swig as hamnet70 + +class qa_insert_pilot_symbols (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_t (self): + # set up fg + self.tb.run () + # check data + + +if __name__ == '__main__': + gr_unittest.run(qa_insert_pilot_symbols, "qa_insert_pilot_symbols.xml") diff --git a/gr-hamnet70/swig/hamnet70_swig.i b/gr-hamnet70/swig/hamnet70_swig.i index 9e29b71..88ca6d0 100644 --- a/gr-hamnet70/swig/hamnet70_swig.i +++ b/gr-hamnet70/swig/hamnet70_swig.i @@ -15,6 +15,8 @@ #include "hamnet70/insert_delayed_tag.h" #include "hamnet70/scrambler.h" #include "hamnet70/async_scrambler.h" +#include "hamnet70/insert_pilot_symbols.h" +#include "hamnet70/correct_frequency_from_pilot_syms.h" %} @@ -33,3 +35,7 @@ GR_SWIG_BLOCK_MAGIC2(hamnet70, insert_delayed_tag); GR_SWIG_BLOCK_MAGIC2(hamnet70, scrambler); %include "hamnet70/async_scrambler.h" GR_SWIG_BLOCK_MAGIC2(hamnet70, async_scrambler); +%include "hamnet70/insert_pilot_symbols.h" +GR_SWIG_BLOCK_MAGIC2(hamnet70, insert_pilot_symbols); +%include "hamnet70/correct_frequency_from_pilot_syms.h" +GR_SWIG_BLOCK_MAGIC2(hamnet70, correct_frequency_from_pilot_syms); diff --git a/grc/hamnet70_demod_sc16qam.grc b/grc/hamnet70_demod_sc16qam.grc index 0048b9f..800f7e8 100644 --- a/grc/hamnet70_demod_sc16qam.grc +++ b/grc/hamnet70_demod_sc16qam.grc @@ -585,7 +585,7 @@ _coordinate - (1269, 387) + (1525, 387) _rotation @@ -1543,7 +1543,7 @@ threshold - 0.997 + 0.999 @@ -1896,6 +1896,61 @@ 0xFF + + hamnet70_correct_frequency_from_pilot_syms + + alias + + + + comment + + + + affinity + + + + _enabled + 1 + + + _coordinate + (1254, 387) + + + _rotation + 0 + + + id + hamnet70_correct_frequency_from_pilot_syms_0 + + + offsets + [len(preamble)+128, len(preamble)+256+4] + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + phase_ref_offset + len(preamble)/2 + + + pilot_sequence + [1+1j, -1-1j, 1-1j, -1+1j] + + + start_tag + corr_est + + hamnet70_correct_phase_from_tag @@ -2182,7 +2237,7 @@ _coordinate - (1525, 467) + (1725, 467) _rotation @@ -2249,7 +2304,7 @@ optional - False + True vlen @@ -2444,7 +2499,7 @@ _coordinate - (1525, 411) + (1725, 411) _rotation @@ -2685,11 +2740,17 @@ in - hamnet70_correct_phase_from_tag_0 + hamnet70_correct_frequency_from_pilot_syms_0 analog_agc_xx_0 0 0 + + hamnet70_correct_phase_from_tag_0 + hamnet70_correct_frequency_from_pilot_syms_0 + 0 + 0 + hamnet70_freq_est_lr_0 hamnet70_pid_controller_0 diff --git a/grc/hamnet70_mod_sc16qam.grc b/grc/hamnet70_mod_sc16qam.grc index 9048a80..83ccfdc 100644 --- a/grc/hamnet70_mod_sc16qam.grc +++ b/grc/hamnet70_mod_sc16qam.grc @@ -1132,11 +1132,11 @@ _enabled - 2 + 1 _coordinate - (1980, 443) + (1980, 435) _rotation @@ -1150,6 +1150,10 @@ offsets [len(preamble)+128, len(preamble)+256] + + length_tag + packet_len + maxoutbuf 0 diff --git a/tmp/test_sc16qam.grc b/tmp/test_sc16qam.grc index 2d1a1fe..4ce553c 100644 --- a/tmp/test_sc16qam.grc +++ b/tmp/test_sc16qam.grc @@ -105,7 +105,7 @@ _coordinate - (957, 394) + (974, 51) gui_hint @@ -168,7 +168,7 @@ _coordinate - (837, 394) + (854, 51) gui_hint @@ -258,7 +258,7 @@ _enabled - True + 1 _coordinate @@ -1355,6 +1355,105 @@ firdes.WIN_BLACKMAN_hARRIS + + qtgui_sink_x + + bw + samp_rate/2 + + + alias + + + + fc + 0 + + + freqchangevar + None + + + comment + + + + affinity + + + + _enabled + 0 + + + fftsize + 8192 + + + _coordinate + (694, 554) + + + gui_hint + + + + _rotation + 0 + + + id + qtgui_sink_x_1 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + name + "Synced Symbols" + + + plotconst + True + + + plotfreq + True + + + plottime + True + + + plotwaterfall + True + + + showports + True + + + showrf + False + + + type + complex + + + rate + 1 + + + wintype + firdes.WIN_BLACKMAN_hARRIS + + qtgui_time_sink_x @@ -1391,7 +1490,7 @@ _coordinate - (710, 562) + (870, 487) gui_hint @@ -1655,7 +1754,7 @@ name - "" + "Synced" nconnections @@ -1663,11 +1762,11 @@ size - 1024 + 8192 srate - samp_rate + samp_rate/2 stemplot @@ -1695,7 +1794,7 @@ tr_tag - "corr_est" + "corr_start" type @@ -1703,7 +1802,7 @@ update_time - 0.10 + 1 ylabel @@ -1754,7 +1853,7 @@ _enabled - True + 1 _coordinate @@ -2155,6 +2254,12 @@ pdu_out print_pdu + + hamnet70_demod_sc16qam_0 + qtgui_sink_x_1 + 1 + 0 + hamnet70_demod_sc16qam_0 qtgui_time_sink_x_0