summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-analog/grc/analog_block_tree.xml1
-rw-r--r--gr-analog/grc/analog_sig_source_x.xml104
-rw-r--r--gr-analog/include/analog/CMakeLists.txt2
-rw-r--r--gr-analog/include/analog/sig_source_X.h.t75
-rw-r--r--gr-analog/include/analog/sig_source_waveform.h41
-rw-r--r--gr-analog/lib/CMakeLists.txt1
-rw-r--r--gr-analog/lib/sig_source_X_impl.cc.t253
-rw-r--r--gr-analog/lib/sig_source_X_impl.h.t70
-rwxr-xr-xgr-analog/python/qa_sig_source.py160
-rw-r--r--gr-analog/swig/analog_swig.i14
10 files changed, 721 insertions, 0 deletions
diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml
index 7283d9f5a..5043e9562 100644
--- a/gr-analog/grc/analog_block_tree.xml
+++ b/gr-analog/grc/analog_block_tree.xml
@@ -44,6 +44,7 @@
</cat>
<cat>
<name>Sources</name>
+ <block>analog_sig_source_x</block>
<block>analog_noise_source_x</block>
</cat>
<cat>
diff --git a/gr-analog/grc/analog_sig_source_x.xml b/gr-analog/grc/analog_sig_source_x.xml
new file mode 100644
index 000000000..b2cd8ad43
--- /dev/null
+++ b/gr-analog/grc/analog_sig_source_x.xml
@@ -0,0 +1,104 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Signal Source
+###################################################
+ -->
+<block>
+ <name>Signal Source</name>
+ <key>analog_sig_source_x</key>
+ <import>from gnuradio import analog</import>
+ <make>analog.sig_source_$(type.fcn)($samp_rate, $waveform, $freq, $amp, $offset)</make>
+ <callback>set_sampling_freq($samp_rate)</callback>
+ <callback>set_waveform($waveform)</callback>
+ <callback>set_frequency($freq)</callback>
+ <callback>set_amplitude($amp)</callback>
+ <callback>set_offset($offset)</callback>
+ <param>
+ <name>Output Type</name>
+ <key>type</key>
+ <type>enum</type>
+ <option>
+ <name>Complex</name>
+ <key>complex</key>
+ <opt>fcn:c</opt>
+ <opt>offset_type:complex</opt>
+ </option>
+ <option>
+ <name>Float</name>
+ <key>float</key>
+ <opt>fcn:f</opt>
+ <opt>offset_type:real</opt>
+ </option>
+ <option>
+ <name>Int</name>
+ <key>int</key>
+ <opt>fcn:i</opt>
+ <opt>offset_type:int</opt>
+ </option>
+ <option>
+ <name>Short</name>
+ <key>short</key>
+ <opt>fcn:s</opt>
+ <opt>offset_type:int</opt>
+ </option>
+ </param>
+ <param>
+ <name>Sample Rate</name>
+ <key>samp_rate</key>
+ <value>samp_rate</value>
+ <type>real</type>
+ </param>
+ <param>
+ <name>Waveform</name>
+ <key>waveform</key>
+ <value>analog.GR_COS_WAVE</value>
+ <type>int</type>
+ <option>
+ <name>Constant</name>
+ <key>analog.GR_CONST_WAVE</key>
+ </option>
+ <option>
+ <name>Sine</name>
+ <key>analog.GR_SIN_WAVE</key>
+ </option>
+ <option>
+ <name>Cosine</name>
+ <key>analog.GR_COS_WAVE</key>
+ </option>
+ <option>
+ <name>Square</name>
+ <key>analog.GR_SQR_WAVE</key>
+ </option>
+ <option>
+ <name>Triangle</name>
+ <key>analog.GR_TRI_WAVE</key>
+ </option>
+ <option>
+ <name>Saw Tooth</name>
+ <key>analog.GR_SAW_WAVE</key>
+ </option>
+ </param>
+ <param>
+ <name>Frequency</name>
+ <key>freq</key>
+ <value>1000</value>
+ <type>real</type>
+ </param>
+ <param>
+ <name>Amplitude</name>
+ <key>amp</key>
+ <value>1</value>
+ <type>real</type>
+ </param>
+ <param>
+ <name>Offset</name>
+ <key>offset</key>
+ <value>0</value>
+ <type>$type.offset_type</type>
+ </param>
+ <source>
+ <name>out</name>
+ <type>$type</type>
+ </source>
+</block>
diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt
index 83a6ccd98..99839449b 100644
--- a/gr-analog/include/analog/CMakeLists.txt
+++ b/gr-analog/include/analog/CMakeLists.txt
@@ -65,6 +65,7 @@ endmacro(expand_h)
# Invoke macro to generate various sources
#######################################################################
expand_h(noise_source_X s i f c)
+expand_h(sig_source_X s i f c)
add_custom_target(analog_generated_includes DEPENDS
${generated_includes}
@@ -98,6 +99,7 @@ install(FILES
probe_avg_mag_sqrd_cf.h
probe_avg_mag_sqrd_f.h
rotator.h
+ sig_source_waveform.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/analog
COMPONENT "analog_devel"
)
diff --git a/gr-analog/include/analog/sig_source_X.h.t b/gr-analog/include/analog/sig_source_X.h.t
new file mode 100644
index 000000000..2915c2abe
--- /dev/null
+++ b/gr-analog/include/analog/sig_source_X.h.t
@@ -0,0 +1,75 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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.
+ */
+
+/* @WARNING@ */
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include <analog/api.h>
+#include <analog/sig_source_waveform.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief signal generator with @TYPE@ output.
+ * \ingroup source_blk
+ */
+ class ANALOG_API @BASE_NAME@ : virtual public gr_sync_block
+ {
+ public:
+ // gr::analog::@BASE_NAME@::sptr
+ typedef boost::shared_ptr<@BASE_NAME@> sptr;
+
+ /*!
+ * \brief Make a signal source block.
+ *
+ * \param sampling_freq Sampling rate of signal.
+ * \param waveform wavetform type.
+ * \param wave_freq Frequency of waveform (relative to sampling_freq).
+ * \param ampl Signal amplitude.
+ * \param offset offset of signal.
+ */
+ static sptr make(double sampling_freq,
+ gr::analog::gr_waveform_t waveform,
+ double wave_freq,
+ double ampl, @TYPE@ offset = 0);
+
+ virtual double sampling_freq() const = 0;
+ virtual gr::analog::gr_waveform_t waveform() const = 0;
+ virtual double frequency() const = 0;
+ virtual double amplitude() const = 0;
+ virtual @TYPE@ offset() const = 0;
+
+ virtual void set_sampling_freq(double sampling_freq) = 0;
+ virtual void set_waveform(gr::analog::gr_waveform_t waveform) = 0;
+ virtual void set_frequency(double frequency) = 0;
+ virtual void set_amplitude(double ampl) = 0;
+ virtual void set_offset(@TYPE@ offset) = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-analog/include/analog/sig_source_waveform.h b/gr-analog/include/analog/sig_source_waveform.h
new file mode 100644
index 000000000..3a9edb8f3
--- /dev/null
+++ b/gr-analog/include/analog/sig_source_waveform.h
@@ -0,0 +1,41 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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_SIG_SOURCE_WAVEFORM_H
+#define INCLUDED_ANALOG_SIG_SOURCE_WAVEFORM_H
+
+namespace gr {
+ namespace analog {
+
+ typedef enum {
+ GR_CONST_WAVE = 100,
+ GR_SIN_WAVE,
+ GR_COS_WAVE,
+ GR_SQR_WAVE,
+ GR_TRI_WAVE,
+ GR_SAW_WAVE
+ } gr_waveform_t;
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_SIG_SOURCE_WAVEFORM_H */
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index c93c220cc..6b64c019d 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -99,6 +99,7 @@ endmacro(expand_cc)
# Invoke macro to generate various sources
########################################################################
expand_cc(noise_source_X_impl s i f c)
+expand_cc(sig_source_X_impl s i f c)
########################################################################
# Setup library
diff --git a/gr-analog/lib/sig_source_X_impl.cc.t b/gr-analog/lib/sig_source_X_impl.cc.t
new file mode 100644
index 000000000..60653dc1b
--- /dev/null
+++ b/gr-analog/lib/sig_source_X_impl.cc.t
@@ -0,0 +1,253 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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.
+ */
+
+/* @WARNING@ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "@IMPL_NAME@.h"
+#include <algorithm>
+#include <gr_io_signature.h>
+#include <stdexcept>
+#include <algorithm>
+#include <gr_complex.h>
+
+namespace gr {
+ namespace analog {
+
+ @BASE_NAME@::sptr
+ @BASE_NAME@::make(double sampling_freq, gr_waveform_t waveform,
+ double frequency, double ampl, @TYPE@ offset)
+ {
+ return gnuradio::get_initial_sptr
+ (new @IMPL_NAME@(sampling_freq, waveform, frequency, ampl, offset));
+ }
+
+ @IMPL_NAME@::@IMPL_NAME@(double sampling_freq, gr_waveform_t waveform,
+ double frequency, double ampl, @TYPE@ offset)
+ : gr_sync_block("@BASE_NAME@",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(1, 1, sizeof(@TYPE@))),
+ d_sampling_freq(sampling_freq), d_waveform(waveform),
+ d_frequency(frequency), d_ampl(ampl), d_offset(offset)
+ {
+ d_nco.set_freq(2 * M_PI * d_frequency / d_sampling_freq);
+ }
+
+ @IMPL_NAME@::~@IMPL_NAME@()
+ {
+ }
+
+ int
+ @IMPL_NAME@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @TYPE@ *optr = (@TYPE@*)output_items[0];
+ @TYPE@ t;
+
+ switch(d_waveform) {
+
+#if @IS_COMPLEX@ // complex?
+
+ case GR_CONST_WAVE:
+ t = (gr_complex) d_ampl + d_offset;
+ std::fill_n(optr, noutput_items, t);
+ break;
+
+ case GR_SIN_WAVE:
+ case GR_COS_WAVE:
+ d_nco.sincos(optr, noutput_items, d_ampl);
+ if(d_offset == gr_complex(0,0))
+ break;
+
+ for(int i = 0; i < noutput_items; i++) {
+ optr[i] += d_offset;
+ }
+ break;
+
+ /* Implements a real square wave high from -PI to 0.
+ * The imaginary square wave leads by 90 deg.
+ */
+ case GR_SQR_WAVE:
+ for(int i = 0; i < noutput_items; i++) {
+ if(d_nco.get_phase() < -1*M_PI/2)
+ optr[i] = gr_complex(d_ampl, 0) + d_offset;
+ else if(d_nco.get_phase() < 0)
+ optr[i] = gr_complex(d_ampl, d_ampl) + d_offset;
+ else if(d_nco.get_phase() < M_PI/2)
+ optr[i] = gr_complex(0, d_ampl) + d_offset;
+ else
+ optr[i] = d_offset;
+ d_nco.step();
+ }
+ break;
+
+ /* Implements a real triangle wave rising from -PI to 0 and
+ * falling from 0 to PI. The imaginary triangle wave leads by
+ * 90 deg.
+ */
+ case GR_TRI_WAVE:
+ for(int i = 0; i < noutput_items; i++) {
+ if(d_nco.get_phase() < -1*M_PI/2){
+ optr[i] = gr_complex(d_ampl*d_nco.get_phase()/M_PI + d_ampl,
+ -1*d_ampl*d_nco.get_phase()/M_PI - d_ampl/2) + d_offset;
+ }
+ else if(d_nco.get_phase() < 0) {
+ optr[i] = gr_complex(d_ampl*d_nco.get_phase()/M_PI + d_ampl,
+ d_ampl*d_nco.get_phase()/M_PI + d_ampl/2) + d_offset;
+ }
+ else if(d_nco.get_phase() < M_PI/2) {
+ optr[i] = gr_complex(-1*d_ampl*d_nco.get_phase()/M_PI + d_ampl,
+ d_ampl*d_nco.get_phase()/M_PI + d_ampl/2) + d_offset;
+ }
+ else {
+ optr[i] = gr_complex(-1*d_ampl*d_nco.get_phase()/M_PI + d_ampl,
+ -1*d_ampl*d_nco.get_phase()/M_PI + 3*d_ampl/2) + d_offset;
+ }
+ d_nco.step();
+ }
+ break;
+
+ /* Implements a real saw tooth wave rising from -PI to PI.
+ * The imaginary saw tooth wave leads by 90 deg.
+ */
+ case GR_SAW_WAVE:
+ for(int i = 0; i < noutput_items; i++) {
+ if(d_nco.get_phase() < -1*M_PI/2) {
+ optr[i] = gr_complex(d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/2,
+ d_ampl*d_nco.get_phase()/(2*M_PI) + 5*d_ampl/4) + d_offset;
+ }
+ else {
+ optr[i] = gr_complex(d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/2,
+ d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/4) + d_offset;
+ }
+ d_nco.step();
+ }
+ break;
+
+#else // nope...
+
+ case GR_CONST_WAVE:
+ t = (@TYPE@)d_ampl + d_offset;
+ std::fill_n(optr, noutput_items, t);
+ break;
+
+ case GR_SIN_WAVE:
+ d_nco.sin(optr, noutput_items, d_ampl);
+ if(d_offset == 0)
+ break;
+
+ for(int i = 0; i < noutput_items; i++) {
+ optr[i] += d_offset;
+ }
+ break;
+
+ case GR_COS_WAVE:
+ d_nco.cos(optr, noutput_items, d_ampl);
+ if(d_offset == 0)
+ break;
+
+ for(int i = 0; i < noutput_items; i++) {
+ optr[i] += d_offset;
+ }
+ break;
+
+ /* The square wave is high from -PI to 0. */
+ case GR_SQR_WAVE:
+ t = (@TYPE@)d_ampl + d_offset;
+ for(int i = 0; i < noutput_items; i++) {
+ if(d_nco.get_phase() < 0)
+ optr[i] = t;
+ else
+ optr[i] = d_offset;
+ d_nco.step();
+ }
+ break;
+
+ /* The triangle wave rises from -PI to 0 and falls from 0 to PI. */
+ case GR_TRI_WAVE:
+ for(int i = 0; i < noutput_items; i++) {
+ double t = d_ampl*d_nco.get_phase()/M_PI;
+ if (d_nco.get_phase() < 0)
+ optr[i] = static_cast<@TYPE@>(t + d_ampl + d_offset);
+ else
+ optr[i] = static_cast<@TYPE@>(-1*t + d_ampl + d_offset);
+ d_nco.step();
+ }
+ break;
+
+ /* The saw tooth wave rises from -PI to PI. */
+ case GR_SAW_WAVE:
+ for(int i = 0; i < noutput_items; i++) {
+ t = static_cast<@TYPE@>(d_ampl*d_nco.get_phase()/(2*M_PI)
+ + d_ampl/2 + d_offset);
+ optr[i] = t;
+ d_nco.step();
+ }
+ break;
+
+#endif
+
+ default:
+ throw std::runtime_error("gr_sig_source: invalid waveform");
+ }
+
+ return noutput_items;
+ }
+
+ void
+ @NAME@::set_sampling_freq(double sampling_freq)
+ {
+ d_sampling_freq = sampling_freq;
+ d_nco.set_freq (2 * M_PI * d_frequency / d_sampling_freq);
+ }
+
+ void
+ @NAME@::set_waveform(gr_waveform_t waveform)
+ {
+ d_waveform = waveform;
+ }
+
+ void
+ @NAME@::set_frequency(double frequency)
+ {
+ d_frequency = frequency;
+ d_nco.set_freq(2 * M_PI * d_frequency / d_sampling_freq);
+ }
+
+ void
+ @NAME@::set_amplitude(double ampl)
+ {
+ d_ampl = ampl;
+ }
+
+ void
+ @NAME@::set_offset(@TYPE@ offset)
+ {
+ d_offset = offset;
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/sig_source_X_impl.h.t b/gr-analog/lib/sig_source_X_impl.h.t
new file mode 100644
index 000000000..50f179127
--- /dev/null
+++ b/gr-analog/lib/sig_source_X_impl.h.t
@@ -0,0 +1,70 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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.
+ */
+
+/* @WARNING@ */
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include <analog/@BASE_NAME@.h>
+#include <gr_sync_block.h>
+#include <gr_fxpt_nco.h>
+
+namespace gr {
+ namespace analog {
+
+ class @IMPL_NAME@ : public @BASE_NAME@
+ {
+ private:
+ double d_sampling_freq;
+ gr_waveform_t d_waveform;
+ double d_frequency;
+ double d_ampl;
+ @TYPE@ d_offset;
+ gr_fxpt_nco d_nco;
+
+ public:
+ @IMPL_NAME@(double sampling_freq, gr_waveform_t waveform,
+ double wave_freq, double ampl, @TYPE@ offset = 0);
+ ~@IMPL_NAME@();
+
+ virtual int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ double sampling_freq() const { return d_sampling_freq; }
+ gr_waveform_t waveform() const { return d_waveform; }
+ double frequency() const { return d_frequency; }
+ double amplitude() const { return d_ampl; }
+ @TYPE@ offset() const { return d_offset; }
+
+ void set_sampling_freq(double sampling_freq);
+ void set_waveform(gr_waveform_t waveform);
+ void set_frequency(double frequency);
+ void set_amplitude(double ampl);
+ void set_offset(@TYPE@ offset);
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-analog/python/qa_sig_source.py b/gr-analog/python/qa_sig_source.py
new file mode 100755
index 000000000..bc48333ed
--- /dev/null
+++ b/gr-analog/python/qa_sig_source.py
@@ -0,0 +1,160 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2007,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.
+#
+
+from gnuradio import gr, gr_unittest
+import analog_swig as analog
+import math
+
+class test_sig_source(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_const_f(self):
+ tb = self.tb
+ expected_result = (1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5)
+ src1 = analog.sig_source_f(1e6, analog.GR_CONST_WAVE, 0, 1.5)
+ op = gr.head(gr.sizeof_float, 10)
+ dst1 = gr.vector_sink_f()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertEqual(expected_result, dst_data)
+
+ def test_const_i(self):
+ tb = self.tb
+ expected_result = (1, 1, 1, 1)
+ src1 = analog.sig_source_i(1e6, analog.GR_CONST_WAVE, 0, 1)
+ op = gr.head(gr.sizeof_int, 4)
+ dst1 = gr.vector_sink_i()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertEqual(expected_result, dst_data)
+
+ def test_sine_f(self):
+ tb = self.tb
+ sqrt2 = math.sqrt(2) / 2
+ expected_result = (0, sqrt2, 1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0)
+ src1 = analog.sig_source_f(8, analog.GR_SIN_WAVE, 1.0, 1.0)
+ op = gr.head(gr.sizeof_float, 9)
+ dst1 = gr.vector_sink_f()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
+
+ def test_cosine_f(self):
+ tb = self.tb
+ sqrt2 = math.sqrt(2) / 2
+ expected_result = (1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0, sqrt2, 1)
+ src1 = analog.sig_source_f(8, analog.GR_COS_WAVE, 1.0, 1.0)
+ op = gr.head(gr.sizeof_float, 9)
+ dst1 = gr.vector_sink_f()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
+
+ def test_sqr_c(self):
+ tb = self.tb #arg6 is a bit before -PI/2
+ expected_result = (1j, 1j, 0, 0, 1, 1, 1+0j, 1+1j, 1j)
+ src1 = analog.sig_source_c(8, analog.GR_SQR_WAVE, 1.0, 1.0)
+ op = gr.head(gr.sizeof_gr_complex, 9)
+ dst1 = gr.vector_sink_c()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertEqual(expected_result, dst_data)
+
+ def test_tri_c(self):
+ tb = self.tb
+ expected_result = (1+.5j, .75+.75j, .5+1j, .25+.75j, 0+.5j,
+ .25+.25j, .5+0j, .75+.25j, 1+.5j)
+ src1 = analog.sig_source_c(8, analog.GR_TRI_WAVE, 1.0, 1.0)
+ op = gr.head(gr.sizeof_gr_complex, 9)
+ dst1 = gr.vector_sink_c()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5)
+
+ def test_saw_c(self):
+ tb = self.tb
+ expected_result = (.5+.25j, .625+.375j, .75+.5j, .875+.625j,
+ 0+.75j, .125+.875j, .25+1j, .375+.125j, .5+.25j)
+ src1 = analog.sig_source_c(8, analog.GR_SAW_WAVE, 1.0, 1.0)
+ op = gr.head(gr.sizeof_gr_complex, 9)
+ dst1 = gr.vector_sink_c()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5)
+
+ def test_sqr_f(self):
+ tb = self.tb
+ expected_result = (0, 0, 0, 0, 1, 1, 1, 1, 0)
+ src1 = analog.sig_source_f(8, analog.GR_SQR_WAVE, 1.0, 1.0)
+ op = gr.head(gr.sizeof_float, 9)
+ dst1 = gr.vector_sink_f()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertEqual(expected_result, dst_data)
+
+ def test_tri_f(self):
+ tb = self.tb
+ expected_result = (1, .75, .5, .25, 0, .25, .5, .75, 1)
+ src1 = analog.sig_source_f(8, analog.GR_TRI_WAVE, 1.0, 1.0)
+ op = gr.head(gr.sizeof_float, 9)
+ dst1 = gr.vector_sink_f()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
+
+ def test_saw_f(self):
+ tb = self.tb
+ expected_result = (.5, .625, .75, .875, 0, .125, .25, .375, .5)
+ src1 = analog.sig_source_f(8, analog.GR_SAW_WAVE, 1.0, 1.0)
+ op = gr.head(gr.sizeof_float, 9)
+ dst1 = gr.vector_sink_f()
+ tb.connect(src1, op)
+ tb.connect(op, dst1)
+ tb.run()
+ dst_data = dst1.data()
+ self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_sig_source, "test_sig_source.xml")
diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i
index 83b61c32d..f23fa6d00 100644
--- a/gr-analog/swig/analog_swig.i
+++ b/gr-analog/swig/analog_swig.i
@@ -53,6 +53,11 @@
#include "analog/probe_avg_mag_sqrd_cf.h"
#include "analog/probe_avg_mag_sqrd_f.h"
#include "analog/sincos.h"
+#include "analog/sig_source_s.h"
+#include "analog/sig_source_i.h"
+#include "analog/sig_source_f.h"
+#include "analog/sig_source_c.h"
+#include "analog/sig_source_waveform.h"
#include "analog/squelch_base_cc.h"
#include "analog/squelch_base_ff.h"
%}
@@ -82,6 +87,11 @@
%include "analog/probe_avg_mag_sqrd_cf.h"
%include "analog/probe_avg_mag_sqrd_f.h"
%include "analog/sincos.h"
+%include "analog/sig_source_s.h"
+%include "analog/sig_source_i.h"
+%include "analog/sig_source_f.h"
+%include "analog/sig_source_c.h"
+%include "analog/sig_source_waveform.h"
%include "analog/squelch_base_cc.h"
%include "analog/squelch_base_ff.h"
@@ -106,3 +116,7 @@ GR_SWIG_BLOCK_MAGIC2(analog, pll_refout_cc);
GR_SWIG_BLOCK_MAGIC2(analog, probe_avg_mag_sqrd_c);
GR_SWIG_BLOCK_MAGIC2(analog, probe_avg_mag_sqrd_cf);
GR_SWIG_BLOCK_MAGIC2(analog, probe_avg_mag_sqrd_f);
+GR_SWIG_BLOCK_MAGIC2(analog, sig_source_s);
+GR_SWIG_BLOCK_MAGIC2(analog, sig_source_i);
+GR_SWIG_BLOCK_MAGIC2(analog, sig_source_f);
+GR_SWIG_BLOCK_MAGIC2(analog, sig_source_c);