summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t93
-rw-r--r--gnuradio-core/src/lib/gengen/gr_sig_source_waveform.h2
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_sig_source.py72
3 files changed, 166 insertions, 1 deletions
diff --git a/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t b/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t
index 8a09c7706..4357eedf4 100644
--- a/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t
+++ b/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t
@@ -78,6 +78,65 @@ int
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...
@@ -106,6 +165,40 @@ int
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++){
+ t = (@TYPE@) d_ampl*d_nco.get_phase()/M_PI;
+ if (d_nco.get_phase() < 0)
+ optr[i] = t + d_ampl + d_offset;
+ else
+ optr[i] = -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 = (@TYPE@) d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/2 + d_offset;
+ optr[i] = t;
+ d_nco.step();
+ }
+ break;
+
#endif
default:
diff --git a/gnuradio-core/src/lib/gengen/gr_sig_source_waveform.h b/gnuradio-core/src/lib/gengen/gr_sig_source_waveform.h
index 669437a3b..e34747247 100644
--- a/gnuradio-core/src/lib/gengen/gr_sig_source_waveform.h
+++ b/gnuradio-core/src/lib/gengen/gr_sig_source_waveform.h
@@ -23,7 +23,7 @@
#define INCLUDED_GR_SIG_SOURCE_WAVEFORM_H
typedef enum {
- GR_CONST_WAVE = 100, GR_SIN_WAVE, GR_COS_WAVE
+ GR_CONST_WAVE = 100, GR_SIN_WAVE, GR_COS_WAVE, GR_SQR_WAVE, GR_TRI_WAVE, GR_SAW_WAVE
} gr_waveform_t;
#endif /* INCLUDED_GR_SIG_SOURCE_WAVEFORM_H */
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_sig_source.py b/gnuradio-core/src/python/gnuradio/gr/qa_sig_source.py
index b985fe02c..7050b20de 100755
--- a/gnuradio-core/src/python/gnuradio/gr/qa_sig_source.py
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_sig_source.py
@@ -80,6 +80,78 @@ class test_sig_source (gr_unittest.TestCase):
fg.run ()
dst_data = dst1.data ()
self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5)
+
+ def test_sqr_c (self):
+ fg = self.fg #arg6 is a bit before -PI/2
+ expected_result = (1j, 1j, 0, 0, 1, 1, 1+0j, 1+1j, 1j)
+ src1 = gr.sig_source_c (8, gr.GR_SQR_WAVE, 1.0, 1.0)
+ op = gr.head (gr.sizeof_gr_complex, 9)
+ dst1 = gr.vector_sink_c ()
+ fg.connect (src1, op)
+ fg.connect (op, dst1)
+ fg.run ()
+ dst_data = dst1.data ()
+ self.assertEqual (expected_result, dst_data)
+
+ def test_tri_c (self):
+ fg = self.fg
+ expected_result = (1+.5j, .75+.75j, .5+1j, .25+.75j, 0+.5j, .25+.25j, .5+0j, .75+.25j, 1+.5j)
+ src1 = gr.sig_source_c (8, gr.GR_TRI_WAVE, 1.0, 1.0)
+ op = gr.head (gr.sizeof_gr_complex, 9)
+ dst1 = gr.vector_sink_c ()
+ fg.connect (src1, op)
+ fg.connect (op, dst1)
+ fg.run ()
+ dst_data = dst1.data ()
+ self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 5)
+
+ def test_saw_c (self):
+ fg = self.fg
+ expected_result = (.5+.25j, .625+.375j, .75+.5j, .875+.625j, 0+.75j, .125+.875j, .25+1j, .375+.125j, .5+.25j)
+ src1 = gr.sig_source_c (8, gr.GR_SAW_WAVE, 1.0, 1.0)
+ op = gr.head (gr.sizeof_gr_complex, 9)
+ dst1 = gr.vector_sink_c ()
+ fg.connect (src1, op)
+ fg.connect (op, dst1)
+ fg.run ()
+ dst_data = dst1.data ()
+ self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 5)
+
+ def test_sqr_f (self):
+ fg = self.fg
+ expected_result = (0, 0, 0, 0, 1, 1, 1, 1, 0)
+ src1 = gr.sig_source_f (8, gr.GR_SQR_WAVE, 1.0, 1.0)
+ op = gr.head (gr.sizeof_float, 9)
+ dst1 = gr.vector_sink_f ()
+ fg.connect (src1, op)
+ fg.connect (op, dst1)
+ fg.run ()
+ dst_data = dst1.data ()
+ self.assertEqual (expected_result, dst_data)
+
+ def test_tri_f (self):
+ fg = self.fg
+ expected_result = (1, .75, .5, .25, 0, .25, .5, .75, 1)
+ src1 = gr.sig_source_f (8, gr.GR_TRI_WAVE, 1.0, 1.0)
+ op = gr.head (gr.sizeof_float, 9)
+ dst1 = gr.vector_sink_f ()
+ fg.connect (src1, op)
+ fg.connect (op, dst1)
+ fg.run ()
+ dst_data = dst1.data ()
+ self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5)
+
+ def test_saw_f (self):
+ fg = self.fg
+ expected_result = (.5, .625, .75, .875, 0, .125, .25, .375, .5)
+ src1 = gr.sig_source_f (8, gr.GR_SAW_WAVE, 1.0, 1.0)
+ op = gr.head (gr.sizeof_float, 9)
+ dst1 = gr.vector_sink_f ()
+ fg.connect (src1, op)
+ fg.connect (op, dst1)
+ fg.run ()
+ dst_data = dst1.data ()
+ self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5)
if __name__ == '__main__':
gr_unittest.main ()