automatic scaling of scatter diagram, quite nice to watch
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 23 Nov 2012 23:04:43 +0000 (23:04 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 23 Nov 2012 23:04:43 +0000 (23:04 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1055 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/src/fdmdv2_defines.h
fdmdv2/src/fdmdv2_plot_scatter.cpp
fdmdv2/src/fdmdv2_plot_scatter.h

index 616d3855b297fc395d2446e25d9434e8d66ed9a5..6883f7d7771fb47299ea3c63ee00143bc09c2ec9 100644 (file)
@@ -44,8 +44,6 @@
 // (symbols/frame)/(graphics update period) = symbols/s sent to scatter memory
 // memory (symbols) = secs of memory * symbols/sec
 #define SCATTER_MEM_SYMS    ((int)(SCATTER_MEM_SECS*(FDMDV_NSYM/DT)))
-#define SCATTER_X_MAX       4.0
-#define SCATTER_Y_MAX       4.0
 
 // Waveform plotting constants
 
index c194365f8c3fc52ca59127202025b135411d0de8..d41b279031143827a0d12499f2e78c36587a8825 100644 (file)
@@ -45,6 +45,8 @@ PlotScatter::PlotScatter(wxFrame* parent) : PlotPanel(parent)
         m_mem[i].real = 0.0;
         m_mem[i].imag = 0.0;
     }
+
+    m_filter_max_xy = 0.1;
 }
 
 //----------------------------------------------------------------
@@ -70,9 +72,7 @@ void PlotScatter::draw(wxAutoBufferedPaintDC& dc)
     dc.SetBrush(ltGraphBkgBrush);
     dc.SetPen(wxPen(BLACK_COLOR, 0));
     dc.DrawRectangle(m_rPlot);
-    x_scale = (float)m_rGrid.GetWidth()/SCATTER_X_MAX;
-    y_scale = (float)m_rGrid.GetHeight()/SCATTER_Y_MAX;
-
     wxPen pen;
     pen.SetColour(LIGHT_GREEN_COLOR);
     pen.SetWidth(1);
@@ -92,6 +92,26 @@ void PlotScatter::draw(wxAutoBufferedPaintDC& dc)
         m_mem[i] = m_new_samples[j];
     }
 
+    // automatically scale
+
+    float max_xy = 1E-12;
+    float real,imag;
+    for(i=0; i< SCATTER_MEM_SYMS; i++) {
+        real = fabs(m_mem[i].real);
+        imag = fabs(m_mem[i].imag);
+        if (real > max_xy)
+            max_xy = real;
+        if (imag > max_xy)
+            max_xy = imag;
+    }
+    m_filter_max_xy = BETA*m_filter_max_xy + (1 - BETA)*2.5*max_xy;
+    if (m_filter_max_xy < 0.1)
+        m_filter_max_xy = 0.1;
+    //printf("max_xy: %f m_filter_max_xy: %f\n", max_xy, m_filter_max_xy);
+
+    x_scale = (float)m_rGrid.GetWidth()/m_filter_max_xy;
+    y_scale = (float)m_rGrid.GetHeight()/m_filter_max_xy;
+
     // draw all samples
 
     for(i = 0; i < SCATTER_MEM_SYMS; i++)
index 86bc54b644af758e864fb9949736a599bcedaa42..f33d3afef7c82adc99057d1e5232e4dfea82208d 100644 (file)
@@ -45,6 +45,9 @@ class PlotScatter : public PlotPanel
         void OnShow(wxShowEvent& event);
 
         DECLARE_EVENT_TABLE()
+
+    private:
+        float m_filter_max_xy;
 };
 
 #endif //__FDMDV2_PLOT_SCATTER__