[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gnuradio-patch
Subject:    [Patch-gnuradio] gr_sig_source_X phase
From:       Patrick Strasser <patrick.strasser () tugraz ! at>
Date:       2007-03-06 17:57:44
Message-ID: 45EDAB98.9050101 () tugraz ! at
[Download RAW message or body]

Hello!

Added phase parameter to gr_sig_source_X. This should be compatible with 
  Josh Blum's new wave forms.
Phase is in radians, like in the NCO.

Patrick
-- 
Engineers motto: cheap, good, fast: choose any two
Patrick Strasser <patrick dot strasser at  tugraz dot at>
Student of Telematik, Techn. University Graz, Austria

["gr_sig_source_phase.diff" (text/plain)]

Index: gr_sig_source_X.cc.t
===================================================================
--- gr_sig_source_X.cc.t	(revision 4483)
+++ gr_sig_source_X.cc.t	(working copy)
@@ -33,21 +33,21 @@
 
 
 @NAME@::@NAME@ (double sampling_freq, gr_waveform_t waveform,
-		double frequency, double ampl, @TYPE@ offset)
+		double frequency, double ampl, @TYPE@ offset, double phase)
   : 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_ampl (ampl), d_offset (offset), d_phase (phase)
 {
   d_nco.set_freq (2 * M_PI * d_frequency / d_sampling_freq);
 }
 
 @NAME@_sptr
 gr_make_@BASE_NAME@ (double sampling_freq, gr_waveform_t waveform,
-		     double frequency, double ampl, @TYPE@ offset)
+		     double frequency, double ampl, @TYPE@ offset, double phase)
 {
-  return @NAME@_sptr (new @NAME@ (sampling_freq, waveform, frequency, ampl, offset));
+  return @NAME@_sptr (new @NAME@ (sampling_freq, waveform, frequency, ampl, offset, phase));
 }
 
 int
@@ -147,3 +147,12 @@
   d_offset = offset;
 }
 
+void 
+@NAME@::set_phase (double phase)
+{
+  double diff_phase = phase - d_phase;
+  d_phase = fmod ((d_phase + diff_phase),  M_PI);
+  // We want an absolute phase, gr_fxt_nco has only relative phase
+  // thus we adjust the phase of the running NCO
+  d_nco.adjust_phase (diff_phase);
+}
Index: gr_sig_source_X.h.t
===================================================================
--- gr_sig_source_X.h.t	(revision 4483)
+++ gr_sig_source_X.h.t	(working copy)
@@ -40,18 +40,19 @@
 class @NAME@ : public gr_sync_block {
   friend @NAME@_sptr 
   gr_make_@BASE_NAME@ (double sampling_freq, gr_waveform_t waveform,
-		       double frequency, double ampl, @TYPE@ offset);
+		       double frequency, double ampl, @TYPE@ offset, double phase);
 
   double		d_sampling_freq;
   gr_waveform_t		d_waveform;
   double		d_frequency;
   double		d_ampl;
   @TYPE@		d_offset;
+  double 		d_phase; /// Phase offset in radians
   gr_fxpt_nco		d_nco;
 
 
   @NAME@ (double sampling_freq, gr_waveform_t waveform,
-	  double wave_freq, double ampl, @TYPE@ offset);
+	  double wave_freq, double ampl, @TYPE@ offset, double phase);
 
  public:
   virtual int work (int noutput_items,
@@ -64,6 +65,7 @@
   double frequency () const { return d_frequency; }
   double amplitude () const { return d_ampl; }
   @TYPE@ offset () const { return d_offset; }
+  double phase () const {return d_phase; }
 
   // MANIPULATORS
   void set_sampling_freq (double sampling_freq);
@@ -71,11 +73,12 @@
   void set_frequency (double frequency);
   void set_amplitude (double ampl);
   void set_offset (@TYPE@ offset);
+  void set_phase (double phase);
 };
 
 @NAME@_sptr
 gr_make_@BASE_NAME@ (double sampling_freq, gr_waveform_t waveform,
-		     double wave_freq, double ampl, @TYPE@ offset = 0);
+		     double wave_freq, double ampl, @TYPE@ offset = 0, double phase = 0);
 
 
 #endif
Index: gr_sig_source_X.i.t
===================================================================
--- gr_sig_source_X.i.t	(revision 4483)
+++ gr_sig_source_X.i.t	(working copy)
@@ -26,13 +26,13 @@
 
 @NAME@_sptr
 gr_make_@BASE_NAME@ (double sampling_freq, gr_waveform_t waveform,
-		     double wave_freq, double ampl, @TYPE@ offset = 0);
+		     double wave_freq, double ampl, @TYPE@ offset = 0, double phase = 0);
 
 
 class @NAME@ : public gr_sync_block {
  private:
   @NAME@ (double sampling_freq, gr_waveform_t waveform,
-	  double wave_freq, double ampl, @TYPE@ offset);
+	  double wave_freq, double ampl, @TYPE@ offset, double phase);
 
  public:
 
@@ -42,6 +42,7 @@
   double frequency () const { return d_frequency; }
   double amplitude () const { return d_ampl; }
   @TYPE@ offset () const { return d_offset; }
+  double phase () const { return d_phase; }
 
   // MANIPULATORS
   void set_sampling_freq (double sampling_freq);
@@ -49,4 +50,5 @@
   void set_frequency (double frequency);
   void set_amplitude (double ampl);
   void set_offset (@TYPE@ offset);
+  void set_phase (double phase);
 };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic