commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10465 - in gnuradio/branches/developers/jblum/gui_gut


From: jblum
Subject: [Commit-gnuradio] r10465 - in gnuradio/branches/developers/jblum/gui_guts: gnuradio-core/src/lib/io gr-wxgui/src/python
Date: Wed, 18 Feb 2009 18:31:07 -0700 (MST)

Author: jblum
Date: 2009-02-18 18:31:05 -0700 (Wed, 18 Feb 2009)
New Revision: 10465

Modified:
   
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.cc
   
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.h
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scopesink_gl.py
Log:
Added interpolation between sample points when triggering in scope guts.
Fixes ticket #307.



Modified: 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.cc
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.cc
      2009-02-18 22:55:53 UTC (rev 10464)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.cc
      2009-02-19 01:31:05 UTC (rev 10465)
@@ -67,8 +67,7 @@
     d_hold_off_count_init (OUTPUT_RECORD_SIZE/2-1),
     d_pre_trigger_count (0),
     d_post_trigger_count (0),
-    d_post_trigger_count_init (OUTPUT_RECORD_SIZE/2),
-    d_prev_sample (0)
+    d_post_trigger_count_init (OUTPUT_RECORD_SIZE/2)
 {
   if (d_nchannels > MAX_CHANNELS){
     fprintf (stderr, "gr_oscope_guts: too many channels.  MAX_CHANNELS = 
%d\n", MAX_CHANNELS);
@@ -112,8 +111,6 @@
   for (int i = 0; i < d_nchannels; i++)
     d_buffer[i][d_obi] = channel_data[i];                // copy data into 
buffer
 
-  int trigger = 0;
-  
   switch (d_state){
   case HOLD_OFF:
     d_hold_off_count--;
@@ -122,11 +119,8 @@
     break;
 
   case LOOK_FOR_TRIGGER:
-    trigger = found_trigger (d_buffer[d_trigger_channel][d_obi]);
-    if (trigger != 0){
+    if (found_trigger ()){
       enter_post_trigger ();
-      if (trigger < 0)                        // previous sample was closer
-        d_post_trigger_count--;
     }else if (d_pre_trigger_count > OUTPUT_RECORD_SIZE/2){
       enter_post_trigger (); //too long without a trigger, force post trigger
     }
@@ -162,8 +156,8 @@
 void
 gr_oscope_guts::enter_look_for_trigger ()
 {
+  d_pre_trigger_count = 0;
   d_state = LOOK_FOR_TRIGGER;
-  d_prev_sample = d_buffer[d_trigger_channel][d_obi];
 }
 
 void
@@ -171,54 +165,49 @@
 {
   d_state = POST_TRIGGER;
   d_post_trigger_count = d_post_trigger_count_init;
-  d_pre_trigger_count = 0;
 }
 
 // ----------------------------------------------------------------
-// returns 0 if no trigger found. 
-// returns +1 if this sample is the trigger point
-// returns -1 if the previous sample is the trigger point
+// returns true if trigger found
 
-int
-gr_oscope_guts::found_trigger (float new_sample)
+bool
+gr_oscope_guts::found_trigger ()
 {
-  float prev_sample = d_prev_sample;
-  d_prev_sample = new_sample;
+  if (d_obi == 0) return false;
+
+  float prev_sample = d_buffer[d_trigger_channel][d_obi-1];
+  float new_sample = d_buffer[d_trigger_channel][d_obi];
   bool trig;
 
   switch (d_trigger_mode){
 
   case gr_TRIG_AUTO:                // always trigger
-    return +1;
+    d_trigger_off = 0;
+    return true;
     
   case gr_TRIG_POS_SLOPE:
     trig = prev_sample < d_trigger_level && new_sample >= d_trigger_level;
-    if (trig){
-      if (fabs (prev_sample - d_trigger_level) < fabs (new_sample - 
d_trigger_level))
-        return -1;
-      else
-        return +1;
-    }
-    return 0;
+    break;
 
   case gr_TRIG_NEG_SLOPE:
     trig = prev_sample > d_trigger_level && new_sample <= d_trigger_level;
-    if (trig){
-      if (fabs (prev_sample - d_trigger_level) < fabs (new_sample - 
d_trigger_level))
-        return -1;
-      else
-        return +1;
-    }
-    return 0;
+    break;
 
   default:
     assert (0);
-    return 0;
+    return false;
   }
+  if (trig){
+    d_trigger_off = (d_trigger_level - prev_sample)/(new_sample - prev_sample);
+    return true;
+  }
+  return false;
 }
 
 // ----------------------------------------------------------------
 // write output records (duh!)
+// perform interpolation from the trigger point offset
+// writes OUTPUT_RECORD_SIZE-1 samples due to interpolation
 
 void
 gr_oscope_guts::write_output_records ()
@@ -231,17 +220,21 @@
   gr_message_sptr msg = 
     gr_make_message(0,                                         // msg type
             d_nchannels,                                       // arg1 for 
other side
-            OUTPUT_RECORD_SIZE,                                // arg2 for 
other side
-            d_nchannels * OUTPUT_RECORD_SIZE * sizeof(float)); // sizeof 
payload
+            (OUTPUT_RECORD_SIZE-1),                                // arg2 for 
other side
+            d_nchannels * (OUTPUT_RECORD_SIZE-1) * sizeof(float)); // sizeof 
payload
 
   float *out = (float *)msg->msg();        // get pointer to raw message buffer
 
+  float prev_sample, curr_sample;
   for (int ch = 0; ch < d_nchannels; ch++){
     // note that d_obi + 1 points at the oldest sample in the buffer
-    for (int i = 0; i < OUTPUT_RECORD_SIZE; i++)
-      out[i] = d_buffer[ch][wrap_bi(d_obi + 1 + i)];
-
-    out += OUTPUT_RECORD_SIZE;
+    prev_sample = d_buffer[ch][wrap_bi(d_obi + 1)];
+    for (int i = 0; i < OUTPUT_RECORD_SIZE; i++){
+      curr_sample = d_buffer[ch][wrap_bi(d_obi + 2 + i)];
+      out[i] = (curr_sample - prev_sample)*d_trigger_off + prev_sample; 
//perform interpolation
+      prev_sample = curr_sample;
+    }
+    out += (OUTPUT_RECORD_SIZE-1);
   }
 
   d_msgq->handle(msg);                // send the msg
@@ -333,7 +326,6 @@
 void
 gr_oscope_guts::trigger_changed ()
 {
-  // d_prev_sample = d_buffer[d_trigger_channel][decr_bi(d_obi)];
   enter_look_for_trigger ();
 }
 

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.h
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.h
       2009-02-18 22:55:53 UTC (rev 10464)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gnuradio-core/src/lib/io/gr_oscope_guts.h
       2009-02-19 01:31:05 UTC (rev 10465)
@@ -64,7 +64,7 @@
   int                  d_pre_trigger_count;
   int                  d_post_trigger_count;
   int                  d_post_trigger_count_init;
-  float                        d_prev_sample;                  // used for 
trigger checking
+  float                        d_trigger_off;                  //%sample 
trigger is off
 
   // NOT IMPLEMENTED
   gr_oscope_guts (const gr_oscope_guts &rhs);                  // no copy 
constructor
@@ -72,7 +72,7 @@
 
   void trigger_changed ();
   void update_rate_or_decimation_changed ();
-  int  found_trigger (float sample);   // returns -1, 0, +1
+  bool found_trigger ();       // returns true if found
   void write_output_records ();
 
   void enter_hold_off ();                      // called on state entry

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py 
    2009-02-18 22:55:53 UTC (rev 10464)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py 
    2009-02-19 01:31:05 UTC (rev 10465)
@@ -29,7 +29,7 @@
 import time
 import pubsub
 from constants import *
-from gnuradio import gr #for gr.prefs
+from gnuradio import gr #for gr.prefs, trigger modes
 
 ##################################################
 # Constants
@@ -38,9 +38,9 @@
 DEFAULT_WIN_SIZE = (600, 300)
 DEFAULT_V_SCALE = 1000
 TRIGGER_MODES = (
-       ('Off', 0),
-       ('Neg', -1),
-       ('Pos', +1),
+       ('Off', gr.gr_TRIG_AUTO),
+       ('Neg', gr.gr_TRIG_NEG_SLOPE),
+       ('Pos', gr.gr_TRIG_POS_SLOPE),
 )
 TRIGGER_LEVELS = (
        ('Auto', None),

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scopesink_gl.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scopesink_gl.py 
    2009-02-18 22:55:53 UTC (rev 10464)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scopesink_gl.py 
    2009-02-19 01:31:05 UTC (rev 10465)
@@ -80,13 +80,7 @@
                        if level == '': scope.set_trigger_level_auto()
                        else: scope.set_trigger_level(level)
                self.controller.subscribe(SCOPE_TRIGGER_LEVEL_KEY, 
set_trigger_level)
-               def set_trigger_mode(mode):
-                       if mode == 0: mode = gr.gr_TRIG_AUTO
-                       elif mode < 0: mode = gr.gr_TRIG_NEG_SLOPE
-                       elif mode > 0: mode = gr.gr_TRIG_POS_SLOPE
-                       else: return
-                       scope.set_trigger_mode(mode)
-               self.controller.subscribe(SCOPE_TRIGGER_MODE_KEY, 
set_trigger_mode)
+               self.controller.subscribe(SCOPE_TRIGGER_MODE_KEY, 
scope.set_trigger_mode)
                self.controller.subscribe(SCOPE_TRIGGER_CHANNEL_KEY, 
scope.set_trigger_channel)
                #start input watcher
                def setter(p, k, x): # lambdas can't have assignments :(





reply via email to

[Prev in Thread] Current Thread [Next in Thread]