summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-analog/include/analog/CMakeLists.txt1
-rw-r--r--gr-analog/include/analog/dpll_bb.h59
-rw-r--r--gr-analog/lib/CMakeLists.txt1
-rw-r--r--gr-analog/lib/dpll_bb_impl.cc98
-rw-r--r--gr-analog/lib/dpll_bb_impl.h58
-rw-r--r--gr-analog/python/qa_dpll.py76
-rw-r--r--gr-analog/swig/analog_swig.i3
7 files changed, 296 insertions, 0 deletions
diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt
index 472f700d1..40af6e55d 100644
--- a/gr-analog/include/analog/CMakeLists.txt
+++ b/gr-analog/include/analog/CMakeLists.txt
@@ -86,6 +86,7 @@ install(FILES
agc2_ff.h
cpfsk_bc.h
ctcss_squelch_ff.h
+ dpll_bb.h
feedforward_agc_cc.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/analog
COMPONENT "analog_devel"
diff --git a/gr-analog/include/analog/dpll_bb.h b/gr-analog/include/analog/dpll_bb.h
new file mode 100644
index 000000000..78efb8fde
--- /dev/null
+++ b/gr-analog/include/analog/dpll_bb.h
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,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_ANALOG_DPLL_BB_H
+#define INCLUDED_ANALOG_DPLL_BB_H
+
+#include <analog/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief Detect the peak of a signal
+ * \ingroup level_blk
+ *
+ * If a peak is detected, this block outputs a 1,
+ * or it outputs 0's.
+ */
+ class ANALOG_API dpll_bb : virtual public gr_sync_block
+ {
+ public:
+ // gr::analog::dpll_bb::sptr
+ typedef boost::shared_ptr<dpll_bb> sptr;
+
+ static sptr make(float period, float gain);
+
+ virtual void set_gain(float gain) = 0;
+ virtual void set_decision_threshold(float thresh) = 0;
+
+ virtual float gain() const = 0;
+ virtual float freq() const = 0;
+ virtual float phase() const = 0;
+ virtual float decision_threshold() const = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_DPLL_BB_H */
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index f7281477e..258d5d67c 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -112,6 +112,7 @@ list(APPEND analog_sources
agc2_ff_impl.cc
cpfsk_bc_impl.cc
ctcss_squelch_ff_impl.cc
+ dpll_bb_impl.cc
feedforward_agc_cc_impl.cc
)
diff --git a/gr-analog/lib/dpll_bb_impl.cc b/gr-analog/lib/dpll_bb_impl.cc
new file mode 100644
index 000000000..a199b66b4
--- /dev/null
+++ b/gr-analog/lib/dpll_bb_impl.cc
@@ -0,0 +1,98 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2009,2010 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 "dpll_bb_impl.h"
+#include <gr_io_signature.h>
+#include <cstdio>
+
+namespace gr {
+ namespace analog {
+
+ dpll_bb::sptr
+ dpll_bb::make(float period, float gain)
+ {
+ return gnuradio::get_initial_sptr
+ (new dpll_bb_impl(period, gain));
+ }
+
+ dpll_bb_impl::dpll_bb_impl(float period, float gain)
+ : gr_sync_block("dpll_bb",
+ gr_make_io_signature(1, 1, sizeof(char)),
+ gr_make_io_signature(1, 1, sizeof(char))),
+ d_restart(0), d_pulse_phase(0)
+ {
+ d_pulse_frequency = 1.0/period;
+ d_gain = gain;
+ d_decision_threshold = 1.0 - 0.5*d_pulse_frequency;
+#if 0
+ fprintf(stderr,"frequency = %f period = %f gain = %f threshold = %f\n",
+ d_pulse_frequency,
+ period,
+ d_gain,
+ d_decision_threshold);
+#endif
+ }
+
+ dpll_bb_impl::~dpll_bb_impl()
+ {
+ }
+
+ int
+ dpll_bb_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const char *iptr = (const char*)input_items[0];
+ char *optr = (char*)output_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ optr[i]= 0;
+ if(iptr[i] == 1) {
+ if(d_restart == 0) {
+ d_pulse_phase = 1;
+ }
+ else {
+ if(d_pulse_phase > 0.5)
+ d_pulse_phase += d_gain*(1.0-d_pulse_phase);
+ else
+ d_pulse_phase -= d_gain*d_pulse_phase;
+ }
+ d_restart = 3;
+ }
+ if(d_pulse_phase > d_decision_threshold) {
+ d_pulse_phase -= 1.0;
+ if(d_restart > 0) {
+ d_restart -= 1;
+ optr[i] = 1;
+ }
+ }
+ d_pulse_phase += d_pulse_frequency;
+ }
+ return noutput_items;
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/dpll_bb_impl.h b/gr-analog/lib/dpll_bb_impl.h
new file mode 100644
index 000000000..a1d8b7709
--- /dev/null
+++ b/gr-analog/lib/dpll_bb_impl.h
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,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_ANALOG_DPLL_BB_IMPL_H
+#define INCLUDED_ANALOG_DPLL_BB_IMPL_H
+
+#include <analog/dpll_bb.h>
+
+namespace gr {
+ namespace analog {
+
+ class dpll_bb_impl : public dpll_bb
+ {
+ private:
+ unsigned char d_restart;
+ float d_pulse_phase, d_pulse_frequency;
+ float d_gain, d_decision_threshold;
+
+ public:
+ dpll_bb_impl(float period, float gain);
+ ~dpll_bb_impl();
+
+ void set_gain(float gain) { d_gain = gain; }
+ void set_decision_threshold(float thresh) { d_decision_threshold = thresh; }
+
+ float gain() const { return d_gain; }
+ float freq() const { return d_pulse_frequency; }
+ float phase() const { return d_pulse_phase; }
+ float decision_threshold() const { return d_decision_threshold; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_DPLL_BB_IMPL_H */
diff --git a/gr-analog/python/qa_dpll.py b/gr-analog/python/qa_dpll.py
new file mode 100644
index 000000000..3ef8a6e28
--- /dev/null
+++ b/gr-analog/python/qa_dpll.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+#
+# Copyright 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.
+#
+
+from gnuradio import gr, gr_unittest
+import analog_swig as analog
+import math
+
+class test_dpll_bb(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_dpll_bb_001(self):
+ # Test set/gets
+
+ period = 1.0
+ gain = 0.1
+ op = analog.dpll_bb(period, gain)
+
+ op.set_gain(0.2)
+ g = op.gain()
+ self.assertAlmostEqual(g, 0.2)
+
+ f = op.freq()
+ self.assertEqual(1/period, f)
+
+ d0 = 1.0 - 0.5*f;
+ d1 = op.decision_threshold()
+ self.assertAlmostEqual(d0, d1)
+
+ p = op.phase()
+ self.assertEqual(0, p)
+
+ def test_dpll_bb_002(self):
+ period = 4
+ gain = 0.1
+
+ src_data = 10*((period-1)*[0,] + [1,])
+ expected_result = src_data
+
+ src = gr.vector_source_b(src_data)
+ op = analog.dpll_bb(period, gain)
+ dst = gr.vector_sink_b()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ result_data = dst.data()
+ self.assertComplexTuplesAlmostEqual(expected_result, result_data, 4)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_dpll_bb, "test_dpll_bb.xml")
+
diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i
index 8cc166dd2..135bfb859 100644
--- a/gr-analog/swig/analog_swig.i
+++ b/gr-analog/swig/analog_swig.i
@@ -34,6 +34,7 @@
#include "analog/agc2_ff.h"
#include "analog/cpfsk_bc.h"
#include "analog/ctcss_squelch_ff.h"
+#include "analog/dpll_bb.h"
#include "analog/feedforward_agc_cc.h"
#include "analog/squelch_base_cc.h"
#include "analog/squelch_base_ff.h"
@@ -46,6 +47,7 @@
%include "analog/agc2_ff.h"
%include "analog/cpfsk_bc.h"
%include "analog/ctcss_squelch_ff.h"
+%include "analog/dpll_bb.h"
%include "analog/feedforward_agc_cc.h"
%include "analog/squelch_base_cc.h"
%include "analog/squelch_base_ff.h"
@@ -56,4 +58,5 @@ GR_SWIG_BLOCK_MAGIC2(analog, agc2_cc);
GR_SWIG_BLOCK_MAGIC2(analog, agc2_ff);
GR_SWIG_BLOCK_MAGIC2(analog, cpfsk_bc);
GR_SWIG_BLOCK_MAGIC2(analog, ctcss_squelch_ff);
+GR_SWIG_BLOCK_MAGIC2(analog, dpll_bb);
GR_SWIG_BLOCK_MAGIC2(analog, feedforward_agc_cc);