summaryrefslogtreecommitdiff
path: root/gr-analog
diff options
context:
space:
mode:
Diffstat (limited to 'gr-analog')
-rw-r--r--gr-analog/grc/analog_block_tree.xml3
-rw-r--r--gr-analog/grc/analog_phase_modulator_fc.xml26
-rw-r--r--gr-analog/include/analog/CMakeLists.txt1
-rw-r--r--gr-analog/include/analog/phase_modulator_fc.h63
-rw-r--r--gr-analog/lib/CMakeLists.txt1
-rw-r--r--gr-analog/lib/phase_modulator_fc_impl.cc73
-rw-r--r--gr-analog/lib/phase_modulator_fc_impl.h55
-rw-r--r--gr-analog/python/qa_phase_modulator.py58
-rw-r--r--gr-analog/swig/analog_swig.i3
9 files changed, 282 insertions, 1 deletions
diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml
index bb7a9b067..7927c1086 100644
--- a/gr-analog/grc/analog_block_tree.xml
+++ b/gr-analog/grc/analog_block_tree.xml
@@ -35,10 +35,11 @@
<block>analog_feedforward_agc_cc</block>
<block>analog_ctcss_squelch_ff</block>
<block>analog_dpll_bb</block>
- <block>analog_frequency_modulator_fc</block>
</cat>
<cat>
<name>Modulators</name>
<block>analog_cpfsk_bc</block>
+ <block>analog_frequency_modulator_fc</block>
+ <block>analog_phase_modulator_fc</block>
</cat>
</cat>
diff --git a/gr-analog/grc/analog_phase_modulator_fc.xml b/gr-analog/grc/analog_phase_modulator_fc.xml
new file mode 100644
index 000000000..c13af769c
--- /dev/null
+++ b/gr-analog/grc/analog_phase_modulator_fc.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Phase Modulator
+###################################################
+ -->
+<block>
+ <name>Phase Mod</name>
+ <key>analog_phase_modulator_fc</key>
+ <import>from gnuradio import analog</import>
+ <make>analog.phase_modulator_fc($sensitivity)</make>
+ <callback>set_sensitivity($sensitivity)</callback>
+ <param>
+ <name>Sensitivity</name>
+ <key>sensitivity</key>
+ <type>real</type>
+ </param>
+ <sink>
+ <name>in</name>
+ <type>float</type>
+ </sink>
+ <source>
+ <name>out</name>
+ <type>complex</type>
+ </source>
+</block>
diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt
index 76a11a3ac..fded7501a 100644
--- a/gr-analog/include/analog/CMakeLists.txt
+++ b/gr-analog/include/analog/CMakeLists.txt
@@ -90,6 +90,7 @@ install(FILES
feedforward_agc_cc.h
fmdet_cf.h
frequency_modulator_fc.h
+ phase_modulator_fc.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/analog
COMPONENT "analog_devel"
)
diff --git a/gr-analog/include/analog/phase_modulator_fc.h b/gr-analog/include/analog/phase_modulator_fc.h
new file mode 100644
index 000000000..409de7804
--- /dev/null
+++ b/gr-analog/include/analog/phase_modulator_fc.h
@@ -0,0 +1,63 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2006,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_PHASE_MODULATOR_FC_H
+#define INCLUDED_ANALOG_PHASE_MODULATOR_FC_H
+
+#include <analog/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief Phase modulator block
+ * \ingroup modulation_blk
+ *
+ * output = complex(cos(in*sensitivity), sin(in*sensitivity))
+ *
+ * Input stream 0: floats
+ * Ouput stream 0: complex
+ */
+ class ANALOG_API phase_modulator_fc : virtual public gr_sync_block
+ {
+ public:
+ // gr::analog::phase_modulator_fc::sptr
+ typedef boost::shared_ptr<phase_modulator_fc> sptr;
+
+ /* \brief Make a phase modulator block.
+ *
+ * \param sensitivity Phase change sensitivity of input amplitude.
+ */
+ static sptr make(double sensitivity);
+
+ virtual double sensitivity() const = 0;
+ virtual double phase() const = 0;
+
+ virtual void set_sensitivity(double s) = 0;
+ virtual void set_phase(double p) = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PHASE_MODULATOR_FC_H */
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index cad0d7b91..a151fbf76 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -116,6 +116,7 @@ list(APPEND analog_sources
feedforward_agc_cc_impl.cc
fmdet_cf_impl.cc
frequency_modulator_fc_impl.cc
+ phase_modulator_fc_impl.cc
)
list(APPEND analog_libs
diff --git a/gr-analog/lib/phase_modulator_fc_impl.cc b/gr-analog/lib/phase_modulator_fc_impl.cc
new file mode 100644
index 000000000..9e9e73f8c
--- /dev/null
+++ b/gr-analog/lib/phase_modulator_fc_impl.cc
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,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 "phase_modulator_fc_impl.h"
+#include <gr_io_signature.h>
+#include <gr_sincos.h>
+#include <math.h>
+
+namespace gr {
+ namespace analog {
+
+ phase_modulator_fc::sptr
+ phase_modulator_fc::make(double sensitivity)
+ {
+ return gnuradio::get_initial_sptr
+ (new phase_modulator_fc_impl(sensitivity));
+ }
+
+ phase_modulator_fc_impl::phase_modulator_fc_impl(double sensitivity)
+ : gr_sync_block("phase_modulator_fc",
+ gr_make_io_signature(1, 1, sizeof(float)),
+ gr_make_io_signature(1, 1, sizeof(gr_complex))),
+ d_sensitivity(sensitivity), d_phase(0)
+ {
+ }
+
+ phase_modulator_fc_impl::~phase_modulator_fc_impl()
+ {
+ }
+
+ int
+ phase_modulator_fc_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];
+ gr_complex *out = (gr_complex*)output_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ d_phase = d_sensitivity * in[i];
+ float oi, oq;
+ gr_sincosf(d_phase, &oq, &oi);
+ out[i] = gr_complex(oi, oq);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/phase_modulator_fc_impl.h b/gr-analog/lib/phase_modulator_fc_impl.h
new file mode 100644
index 000000000..ac10bc891
--- /dev/null
+++ b/gr-analog/lib/phase_modulator_fc_impl.h
@@ -0,0 +1,55 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2006,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_PHASE_MODULATOR_FC_IMPL_H
+#define INCLUDED_ANALOG_PHASE_MODULATOR_FC_IMPL_H
+
+#include <analog/phase_modulator_fc.h>
+
+namespace gr {
+ namespace analog {
+
+ class phase_modulator_fc_impl : public phase_modulator_fc
+ {
+ private:
+ double d_sensitivity;
+ double d_phase;
+
+ public:
+ phase_modulator_fc_impl(double sensitivity);
+ ~phase_modulator_fc_impl();
+
+ double sensitivity() const { return d_sensitivity; }
+ double phase() const { return d_phase; }
+
+ void set_sensitivity(double s) { d_sensitivity = s; }
+ void set_phase(double p) { d_phase = p; }
+
+ 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_PHASE_MODULATOR_FC_IMPL_H */
diff --git a/gr-analog/python/qa_phase_modulator.py b/gr-analog/python/qa_phase_modulator.py
new file mode 100644
index 000000000..a9c8c8459
--- /dev/null
+++ b/gr-analog/python/qa_phase_modulator.py
@@ -0,0 +1,58 @@
+#!/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
+
+def sincos(x):
+ return math.cos(x) + math.sin(x) * 1j
+
+
+class test_phase_modulator(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_fm_001(self):
+ pi = math.pi
+ sensitivity = pi/4
+ src_data = (1.0/4, 1.0/2, 1.0/4, -1.0/4, -1.0/2, -1/4.0)
+ expected_result = tuple([sincos(sensitivity*x) for x in src_data])
+
+ src = gr.vector_source_f(src_data)
+ op = analog.phase_modulator_fc(sensitivity)
+ dst = gr.vector_sink_c()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ result_data = dst.data()
+ self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_phase_modulator, "test_phase_modulator.xml")
+
diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i
index 4c35f9b07..665da9686 100644
--- a/gr-analog/swig/analog_swig.i
+++ b/gr-analog/swig/analog_swig.i
@@ -43,6 +43,7 @@
#include "analog/noise_source_i.h"
#include "analog/noise_source_f.h"
#include "analog/noise_source_c.h"
+#include "analog/phase_modulator_fc.h"
#include "analog/squelch_base_cc.h"
#include "analog/squelch_base_ff.h"
%}
@@ -63,6 +64,7 @@
%include "analog/noise_source_i.h"
%include "analog/noise_source_f.h"
%include "analog/noise_source_c.h"
+%include "analog/phase_modulator_fc.h"
%include "analog/squelch_base_cc.h"
%include "analog/squelch_base_ff.h"
@@ -80,3 +82,4 @@ GR_SWIG_BLOCK_MAGIC2(analog, noise_source_s);
GR_SWIG_BLOCK_MAGIC2(analog, noise_source_i);
GR_SWIG_BLOCK_MAGIC2(analog, noise_source_f);
GR_SWIG_BLOCK_MAGIC2(analog, noise_source_c);
+GR_SWIG_BLOCK_MAGIC2(analog, phase_modulator_fc);