[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 01/03: digital: add correlate access code t
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 01/03: digital: add correlate access code tagging block with soft inputs |
Date: |
Mon, 10 Apr 2017 15:42:57 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 4b92a2d4bedce2850807af2f1afea8678f77bc07
Author: Sean Nowlan <address@hidden>
Date: Thu Jan 26 16:56:05 2017 -0500
digital: add correlate access code tagging block with soft inputs
---
...ml => digital_correlate_access_code_tag_xx.xml} | 23 +++-
gr-digital/include/gnuradio/digital/CMakeLists.txt | 1 +
.../digital/correlate_access_code_tag_ff.h | 72 +++++++++++
gr-digital/lib/CMakeLists.txt | 1 +
.../lib/correlate_access_code_tag_ff_impl.cc | 135 +++++++++++++++++++++
gr-digital/lib/correlate_access_code_tag_ff_impl.h | 61 ++++++++++
.../python/digital/qa_correlate_access_code.py | 18 +++
.../python/digital/qa_correlate_access_code_tag.py | 36 +++++-
gr-digital/swig/digital_swig0.i | 3 +
9 files changed, 343 insertions(+), 7 deletions(-)
diff --git a/gr-digital/grc/digital_correlate_access_code_tag_bb.xml
b/gr-digital/grc/digital_correlate_access_code_tag_xx.xml
similarity index 59%
rename from gr-digital/grc/digital_correlate_access_code_tag_bb.xml
rename to gr-digital/grc/digital_correlate_access_code_tag_xx.xml
index 7d43f1b..83ccb42 100644
--- a/gr-digital/grc/digital_correlate_access_code_tag_bb.xml
+++ b/gr-digital/grc/digital_correlate_access_code_tag_xx.xml
@@ -6,9 +6,24 @@
-->
<block>
<name>Correlate Access Code - Tag</name>
- <key>digital_correlate_access_code_tag_bb</key>
+ <key>digital_correlate_access_code_tag_xx</key>
<import>from gnuradio import digital</import>
- <make>digital.correlate_access_code_tag_bb($access_code, $threshold,
$tagname)</make>
+ <make>digital.correlate_access_code_tag_$(type.fcn)($access_code,
$threshold, $tagname)</make>
+ <param>
+ <name>IO Type</name>
+ <key>type</key>
+ <type>enum</type>
+ <option>
+ <name>Byte</name>
+ <key>byte</key>
+ <opt>fcn:bb</opt>
+ </option>
+ <option>
+ <name>Float</name>
+ <key>float</key>
+ <opt>fcn:ff</opt>
+ </option>
+ </param>
<param>
<name>Access Code</name>
<key>access_code</key>
@@ -27,10 +42,10 @@
</param>
<sink>
<name>in</name>
- <type>byte</type>
+ <type>$type</type>
</sink>
<source>
<name>out</name>
- <type>byte</type>
+ <type>$type</type>
</source>
</block>
diff --git a/gr-digital/include/gnuradio/digital/CMakeLists.txt
b/gr-digital/include/gnuradio/digital/CMakeLists.txt
index 1b22265..911187c 100644
--- a/gr-digital/include/gnuradio/digital/CMakeLists.txt
+++ b/gr-digital/include/gnuradio/digital/CMakeLists.txt
@@ -46,6 +46,7 @@ install(FILES
corr_est_cc.h
correlate_access_code_bb.h
correlate_access_code_tag_bb.h
+ correlate_access_code_tag_ff.h
correlate_access_code_bb_ts.h
correlate_access_code_ff_ts.h
correlate_and_sync_cc.h
diff --git a/gr-digital/include/gnuradio/digital/correlate_access_code_tag_ff.h
b/gr-digital/include/gnuradio/digital/correlate_access_code_tag_ff.h
new file mode 100644
index 0000000..93e89d6
--- /dev/null
+++ b/gr-digital/include/gnuradio/digital/correlate_access_code_tag_ff.h
@@ -0,0 +1,72 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2006,2011,2012,2017 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_FF_H
+#define INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_FF_H
+
+#include <gnuradio/digital/api.h>
+#include <gnuradio/sync_block.h>
+#include <string>
+
+namespace gr {
+ namespace digital {
+
+ /*!
+ * \brief Examine input for specified access code, one bit at a time.
+ * \ingroup packet_operators_blk
+ *
+ * \details
+ * input: stream of floats (generally, soft decisions)
+ * output: unaltered stream of bits (plus tags)
+ *
+ * This block annotates the input stream with tags. The tags have
+ * key name [tag_name], specified in the constructor. Used for
+ * searching an input data stream for preambles, etc., by slicing
+ * the soft decision symbol inputs.
+ */
+ class DIGITAL_API correlate_access_code_tag_ff : virtual public sync_block
+ {
+ public:
+ // gr::digital::correlate_access_code_tag_ff::sptr
+ typedef boost::shared_ptr<correlate_access_code_tag_ff> sptr;
+
+ /*!
+ * \param access_code is represented with 1 byte per bit,
+ * e.g., "010101010111000100"
+ * \param threshold maximum number of bits that may be wrong
+ * \param tag_name key of the tag inserted into the tag stream
+ */
+ static sptr make(const std::string &access_code,
+ int threshold,
+ const std::string &tag_name);
+
+ /*!
+ * \param access_code is represented with 1 byte per bit,
+ * e.g., "010101010111000100"
+ */
+ virtual bool set_access_code(const std::string &access_code) = 0;
+ };
+
+ } /* namespace digital */
+} /* namespace gr */
+
+#endif /* INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_FF_H */
diff --git a/gr-digital/lib/CMakeLists.txt b/gr-digital/lib/CMakeLists.txt
index 84f53ec..383b940 100644
--- a/gr-digital/lib/CMakeLists.txt
+++ b/gr-digital/lib/CMakeLists.txt
@@ -64,6 +64,7 @@ list(APPEND digital_sources
corr_est_cc_impl.cc
correlate_access_code_bb_impl.cc
correlate_access_code_tag_bb_impl.cc
+ correlate_access_code_tag_ff_impl.cc
correlate_access_code_bb_ts_impl.cc
correlate_access_code_ff_ts_impl.cc
correlate_and_sync_cc_impl.cc
diff --git a/gr-digital/lib/correlate_access_code_tag_ff_impl.cc
b/gr-digital/lib/correlate_access_code_tag_ff_impl.cc
new file mode 100644
index 0000000..c5c8ee7
--- /dev/null
+++ b/gr-digital/lib/correlate_access_code_tag_ff_impl.cc
@@ -0,0 +1,135 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006,2010-2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio; 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 "correlate_access_code_tag_ff_impl.h"
+#include <gnuradio/io_signature.h>
+#include <gnuradio/math.h>
+#include <stdexcept>
+#include <volk/volk.h>
+#include <cstdio>
+#include <iostream>
+
+namespace gr {
+ namespace digital {
+
+#define VERBOSE 0
+
+ correlate_access_code_tag_ff::sptr
+ correlate_access_code_tag_ff::make(const std::string &access_code,
+ int threshold,
+ const std::string &tag_name)
+ {
+ return gnuradio::get_initial_sptr
+ (new correlate_access_code_tag_ff_impl(access_code,
+ threshold, tag_name));
+ }
+
+
+ correlate_access_code_tag_ff_impl::correlate_access_code_tag_ff_impl(
+ const std::string &access_code, int threshold, const std::string
&tag_name)
+ : sync_block("correlate_access_code_tag_ff",
+ io_signature::make(1, 1, sizeof(float)),
+ io_signature::make(1, 1, sizeof(float))),
+ d_data_reg(0), d_mask(0),
+ d_threshold(threshold), d_len(0)
+ {
+ if(!set_access_code(access_code)) {
+ throw std::out_of_range ("access_code is > 64 bits");
+ }
+
+ std::stringstream str;
+ str << name() << unique_id();
+ d_me = pmt::string_to_symbol(str.str());
+ d_key = pmt::string_to_symbol(tag_name);
+ }
+
+ correlate_access_code_tag_ff_impl::~correlate_access_code_tag_ff_impl()
+ {
+ }
+
+ bool
+ correlate_access_code_tag_ff_impl::set_access_code(
+ const std::string &access_code)
+ {
+ d_len = access_code.length(); // # of bytes in string
+ if(d_len > 64)
+ return false;
+
+ // set len bottom bits to 1.
+ d_mask = ((~0ULL) >> (64 - d_len));
+
+ d_access_code = 0;
+ for(unsigned i=0; i < d_len; i++){
+ d_access_code = (d_access_code << 1) | (access_code[i] & 1);
+ }
+
+ if(VERBOSE) {
+ std::cerr << "Access code: " << std::hex << d_access_code <<
std::dec << std::endl;
+ std::cerr << "Mask: " << std::hex << d_mask << std::dec << std::endl;
+ }
+
+ return true;
+ }
+
+ int
+ correlate_access_code_tag_ff_impl::work(int noutput_items,
+ gr_vector_const_void_star
&input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float*)input_items[0];
+ float *out = (float*)output_items[0];
+
+ uint64_t abs_out_sample_cnt = nitems_written(0);
+
+ for(int i = 0; i < noutput_items; i++) {
+ out[i] = in[i];
+
+ // compute hamming distance between desired access code and current data
+ uint64_t wrong_bits = 0;
+ uint64_t nwrong = d_threshold+1;
+
+ wrong_bits = (d_data_reg ^ d_access_code) & d_mask;
+ volk_64u_popcnt(&nwrong, wrong_bits);
+
+ // shift in new data
+ d_data_reg = (d_data_reg << 1) | (gr::branchless_binary_slicer(in[i]) &
0x1);
+ if(nwrong <= d_threshold) {
+ if(VERBOSE)
+ std::cerr << "writing tag at sample " << abs_out_sample_cnt + i <<
std::endl;
+ add_item_tag(0, //stream ID
+ abs_out_sample_cnt + i, //sample
+ d_key, //frame info
+ pmt::from_long(nwrong), //data (number wrong)
+ d_me //block src id
+ );
+ }
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace digital */
+} /* namespace gr */
diff --git a/gr-digital/lib/correlate_access_code_tag_ff_impl.h
b/gr-digital/lib/correlate_access_code_tag_ff_impl.h
new file mode 100644
index 0000000..234df02
--- /dev/null
+++ b/gr-digital/lib/correlate_access_code_tag_ff_impl.h
@@ -0,0 +1,61 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2006,2011,2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_FF_IMPL_H
+#define INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_FF_IMPL_H
+
+#include <gnuradio/digital/correlate_access_code_tag_ff.h>
+
+namespace gr {
+ namespace digital {
+
+ class correlate_access_code_tag_ff_impl :
+ public correlate_access_code_tag_ff
+ {
+ private:
+ unsigned long long d_access_code; // access code to locate start
of packet
+ // access code is left justified in
the word
+ unsigned long long d_data_reg; // used to look for access_code
+ unsigned long long d_mask; // masks access_code bits (top N bits
are set where
+ // N is the number of bits in the
access code)
+ unsigned int d_threshold; // how many bits may be wrong in sync
vector
+ unsigned int d_len; // the length of the access code
+
+ pmt::pmt_t d_key, d_me; //d_key is the tag name, d_me is the block name
+ unique ID
+
+ public:
+ correlate_access_code_tag_ff_impl(const std::string &access_code,
+ int threshold,
+ const std::string &tag_name);
+ ~correlate_access_code_tag_ff_impl();
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ bool set_access_code(const std::string &access_code);
+ };
+
+ } /* namespace digital */
+} /* namespace gr */
+
+#endif /* INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_FF_IMPL_H */
diff --git a/gr-digital/python/digital/qa_correlate_access_code.py
b/gr-digital/python/digital/qa_correlate_access_code.py
index d89b457..355843a 100755
--- a/gr-digital/python/digital/qa_correlate_access_code.py
+++ b/gr-digital/python/digital/qa_correlate_access_code.py
@@ -91,6 +91,24 @@ class test_correlate_access_code(gr_unittest.TestCase):
result_data = dst.data()
self.assertEqual(expected_result, result_data)
+ def test_004(self):
+ code = tuple(string_to_1_0_list(default_access_code))
+ access_code = to_1_0_string(code)
+ pad = (0,) * 64
+ #print code
+ #print access_code
+ src_bits = code + (1, 0, 1, 1) + pad
+ src_data = [2.0*x - 1.0 for x in src_bits]
+ expected_result_bits = code + (1, 0, 1, 1) + pad
+ expected_result = [2.0*x - 1.0 for x in expected_result_bits]
+ src = blocks.vector_source_f(src_data)
+ op = digital.correlate_access_code_tag_ff(access_code, 0, "test")
+ dst = blocks.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertFloatTuplesAlmostEqual(expected_result, result_data, 5)
+
if __name__ == '__main__':
gr_unittest.run(test_correlate_access_code,
"test_correlate_access_code.xml")
diff --git a/gr-digital/python/digital/qa_correlate_access_code_tag.py
b/gr-digital/python/digital/qa_correlate_access_code_tag.py
index f2663e4..7266169 100755
--- a/gr-digital/python/digital/qa_correlate_access_code_tag.py
+++ b/gr-digital/python/digital/qa_correlate_access_code_tag.py
@@ -50,7 +50,7 @@ class test_correlate_access_code(gr_unittest.TestCase):
src_data = (1, 0, 1, 1, 1, 1, 0, 1, 1) + pad + (0,) * 7
src = blocks.vector_source_b(src_data)
op = digital.correlate_access_code_tag_bb("1011", 0, "sync")
- dst = blocks.tag_debug(1, "sync")
+ dst = blocks.tag_debug(gr.sizeof_char, "sync")
self.tb.connect(src, op, dst)
self.tb.run()
result_data = dst.current_tags()
@@ -65,10 +65,40 @@ class test_correlate_access_code(gr_unittest.TestCase):
#print code
#print access_code
src_data = code + (1, 0, 1, 1) + pad
- expected_result = pad + code + (3, 0, 1, 1)
src = blocks.vector_source_b(src_data)
op = digital.correlate_access_code_tag_bb(access_code, 0, "sync")
- dst = blocks.tag_debug(1, "sync")
+ dst = blocks.tag_debug(gr.sizeof_char, "sync")
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ result_data = dst.current_tags()
+ self.assertEqual(len(result_data), 1)
+ self.assertEqual(result_data[0].offset, len(code))
+
+ def test_003(self):
+ pad = (0,) * 64
+ src_bits = (1, 0, 1, 1, 1, 1, 0, 1, 1) + pad + (0,) * 7
+ src_data = [2.0*x - 1.0 for x in src_bits]
+ src = blocks.vector_source_f(src_data)
+ op = digital.correlate_access_code_tag_ff("1011", 0, "sync")
+ dst = blocks.tag_debug(gr.sizeof_float, "sync")
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ result_data = dst.current_tags()
+ self.assertEqual(len(result_data), 2)
+ self.assertEqual(result_data[0].offset, 4)
+ self.assertEqual(result_data[1].offset, 9)
+
+ def test_004(self):
+ code = tuple(string_to_1_0_list(default_access_code))
+ access_code = to_1_0_string(code)
+ pad = (0,) * 64
+ #print code
+ #print access_code
+ src_bits = code + (1, 0, 1, 1) + pad
+ src_data = [2.0*x - 1.0 for x in src_bits]
+ src = blocks.vector_source_f(src_data)
+ op = digital.correlate_access_code_tag_ff(access_code, 0, "sync")
+ dst = blocks.tag_debug(gr.sizeof_float, "sync")
self.tb.connect(src, op, dst)
self.tb.run()
result_data = dst.current_tags()
diff --git a/gr-digital/swig/digital_swig0.i b/gr-digital/swig/digital_swig0.i
index 753d026..0f0652f 100644
--- a/gr-digital/swig/digital_swig0.i
+++ b/gr-digital/swig/digital_swig0.i
@@ -46,6 +46,7 @@
#include "gnuradio/digital/corr_est_cc.h"
#include "gnuradio/digital/correlate_access_code_bb.h"
#include "gnuradio/digital/correlate_access_code_tag_bb.h"
+#include "gnuradio/digital/correlate_access_code_tag_ff.h"
#include "gnuradio/digital/correlate_access_code_bb_ts.h"
#include "gnuradio/digital/correlate_access_code_ff_ts.h"
#include "gnuradio/digital/correlate_and_sync_cc.h"
@@ -81,6 +82,7 @@
%include "gnuradio/digital/corr_est_cc.h"
%include "gnuradio/digital/correlate_access_code_bb.h"
%include "gnuradio/digital/correlate_access_code_tag_bb.h"
+%include "gnuradio/digital/correlate_access_code_tag_ff.h"
%include "gnuradio/digital/correlate_access_code_bb_ts.h"
%include "gnuradio/digital/correlate_access_code_ff_ts.h"
%include "gnuradio/digital/correlate_and_sync_cc.h"
@@ -114,6 +116,7 @@ GR_SWIG_BLOCK_MAGIC2(digital,
constellation_soft_decoder_cf);
GR_SWIG_BLOCK_MAGIC2(digital, corr_est_cc);
GR_SWIG_BLOCK_MAGIC2(digital, correlate_access_code_bb);
GR_SWIG_BLOCK_MAGIC2(digital, correlate_access_code_tag_bb);
+GR_SWIG_BLOCK_MAGIC2(digital, correlate_access_code_tag_ff);
GR_SWIG_BLOCK_MAGIC2(digital, correlate_access_code_bb_ts);
GR_SWIG_BLOCK_MAGIC2(digital, correlate_access_code_ff_ts);
GR_SWIG_BLOCK_MAGIC2(digital, correlate_and_sync_cc);