summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib
diff options
context:
space:
mode:
authoreb2007-03-02 01:50:03 +0000
committereb2007-03-02 01:50:03 +0000
commit005d44e0e9281152bde0923e3239772d67e4e730 (patch)
treee45f5d00ba3a6165debf13eefb9207a8efa99515 /gnuradio-core/src/lib
parent95945638f5d97469ac0a396aeaeb619e6ca1f308 (diff)
downloadgnuradio-005d44e0e9281152bde0923e3239772d67e4e730.tar.gz
gnuradio-005d44e0e9281152bde0923e3239772d67e4e730.tar.bz2
gnuradio-005d44e0e9281152bde0923e3239772d67e4e730.zip
Applied patch from Josh Blum that adds SQUARE, TRIANGLE and SAWTOOTH
waveforms to gr_sig_source* git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4679 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-core/src/lib')
-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
2 files changed, 94 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 */