summaryrefslogtreecommitdiff
path: root/gr-analog/lib
diff options
context:
space:
mode:
authorTom Rondeau2012-10-31 11:04:49 -0400
committerTom Rondeau2012-10-31 11:04:49 -0400
commit0353e0b56734c62884c7fd6d3634a28bafbae74f (patch)
tree3bcbf7718c0d898938b5e143a4f55dc410a6f626 /gr-analog/lib
parentc8b0062aeb430e9e8655014a430e5a8899278881 (diff)
downloadgnuradio-0353e0b56734c62884c7fd6d3634a28bafbae74f.tar.gz
gnuradio-0353e0b56734c62884c7fd6d3634a28bafbae74f.tar.bz2
gnuradio-0353e0b56734c62884c7fd6d3634a28bafbae74f.zip
analog: adding sig_source to gr-analog with QA and GRC.
Diffstat (limited to 'gr-analog/lib')
-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
3 files changed, 324 insertions, 0 deletions
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@ */