renamed a few variables for consistency, spectrum now working
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 24 Oct 2012 00:50:22 +0000 (00:50 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 24 Oct 2012 00:50:22 +0000 (00:50 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@802 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/src/fdmdv2_defines.h
fdmdv2/src/fdmdv2_plot_spectrum.cpp
fdmdv2/src/fdmdv2_plot_waterfall_linux.cpp

index 96bc9c4120eeb6a41f7ff0d5f31edda95ccfdbb1..9b5cac7d2364df333d489074569477023baf4be7 100644 (file)
@@ -32,9 +32,9 @@
 
 #define FDMDV_NSPEC         512
 
-#define MIN_AMP_DB         -40.0    // min of spectrogram/waterfall amplitude axis
-#define MAX_AMP_DB          0.0     // max of spectrogram/waterfall amplitude axis
-#define STEP_AMP_DB         5.0     // amplitude axis step
+#define MIN_MAG_DB        -40.0     // min of spectrogram/waterfall magnitude axis
+#define MAX_MAG_DB          0.0     // max of spectrogram/waterfall magnitude axis
+#define STEP_MAG_DB         5.0     // magnitude axis step
 #define BETA                0.1     // constant for time averageing spectrum data
 #define MIN_F_HZ            0       // min freq on Waterfall and Spectrum
 #define MAX_F_HZ            4000    // max freq on Waterfall and Spectrum
index 263f869716a198137397f3f89ef894575462419c..2fcc0a13d3fc42a987d2634965caf240596f3a46 100644 (file)
@@ -95,7 +95,8 @@ void PlotSpectrum::draw(wxAutoBufferedPaintDC& dc)
     m_rCtrl  = GetClientRect();
 
     // m_rGrid is coords of inner window we actually plot to.  We deflate it a bit
-    // to leave room for axis labels.
+    // to leave room for axis labels.  We need to work this out every time we draw
+    // as window may have been resized
 
     m_rGrid  = m_rCtrl;
     m_rGrid = m_rGrid.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2)));
@@ -108,65 +109,45 @@ void PlotSpectrum::draw(wxAutoBufferedPaintDC& dc)
     dc.SetPen(wxPen(BLACK_COLOR, 0));
     dc.DrawRectangle(m_rPlot);
 
-    // graticule
+    // draw spectrum
 
-    drawGraticule(dc);
-
-#ifdef OLD
-
-    wxMemoryDC m_mDC;
-    m_mDC.SelectObject(*m_pBmp);
-    m_rCtrl  = GetClientRect();
-    m_rGrid  = m_rCtrl;
-
-    m_rGrid = m_rGrid.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2)));
-    m_rGrid.Offset(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER);
-
-    pDC.Clear();
-    m_rPlot = wxRect(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_rGrid.GetWidth(), m_rGrid.GetHeight());
-    if(m_firstPass)
-    {
-        m_firstPass = false;
-        m_mDC.Clear();
-        m_mDC.FloodFill(0, 0, VERY_LTGREY_COLOR);
-
-        // Draw a filled rectangle with aborder
-//        wxBrush ltGraphBkgBrush = wxBrush(LIGHT_YELLOW_COLOR);
-        wxBrush ltGraphBkgBrush = wxBrush(DARK_GREY_COLOR);
-        m_mDC.SetBrush(ltGraphBkgBrush);
-        m_mDC.SetPen(wxPen(BLACK_COLOR, 0));
-        m_mDC.DrawRectangle(m_rPlot);
-    }
     if(m_newdata)
     {
+       int   x, y, prev_x, prev_y, index;
+       float index_to_px, mag_dB_to_py, mag;
+
         m_newdata = false;
-//        plotPixelData(dc);
-#ifdef _USE_TIMER
-        int t = m_rPlot.GetTop();
-        int l = m_rPlot.GetLeft();
-        int h = m_rPlot.GetHeight();
-        int w = m_rPlot.GetWidth();
-        //double stride = w / FDMDV_NSPEC;
 
         wxPen pen;
         pen.SetColour(DARK_GREEN_COLOR);
         pen.SetWidth(1);
-        m_mDC.SetPen(pen);
+        dc.SetPen(pen);
+
+       index_to_px = (float)m_rGrid.GetWidth()/FDMDV_NSPEC;
+       mag_dB_to_py = (float)m_rGrid.GetHeight()/(MAX_MAG_DB-MIN_MAG_DB);
 
-//        float *pData = m_pTopFrame->m_rxPa->m_av_mag;
-        float *pData = g_avmag;
-        for(int x = 1; x < w; x++)
+       prev_x = PLOT_BORDER + XLEFT_OFFSET;
+       prev_y = PLOT_BORDER;
+        for(index = 0; index < FDMDV_NSPEC; index++)
         {
-//            m_mDC.DrawPoint(x, (int)pData[x]);
-            m_mDC.DrawLine((x - 1), (int)pData[(x - 1)] + (h / 2), x, (int)pData[x] + (h / 2));
+            x = index*index_to_px;
+           mag = g_avmag[index];
+           if (mag > MAX_MAG_DB) mag = MAX_MAG_DB;
+           if (mag < MIN_MAG_DB) mag = MIN_MAG_DB;
+           y = -mag * mag_dB_to_py;
+
+           x += PLOT_BORDER + XLEFT_OFFSET;
+           y += PLOT_BORDER;
+
+           dc.DrawLine(x, y, prev_x, prev_y);
+           prev_x = x; prev_y = y;
         }
-        pDC.Blit(l, t, w, h, &m_mDC, l, t);
-#endif
-        drawGraticule(pDC);
     }
-    m_mDC.SetBrush(wxNullBrush);
-    m_mDC.SelectObject(wxNullBitmap);
-#endif
+
+    // and finally draw Graticule
+
+    drawGraticule(dc);
+
 }
 
 //-------------------------------------------------------------------------
@@ -177,7 +158,7 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC&  dc)
     int      x, y, text_w, text_h;
     char     buf[15];
     wxString s;
-    float    f, amplitude, freq_hz_to_px, ampl_dB_to_py;
+    float    f, mag, freq_hz_to_px, mag_dB_to_py;
 
     wxBrush ltGraphBkgBrush;
     ltGraphBkgBrush.SetStyle(wxBRUSHSTYLE_TRANSPARENT);
@@ -186,7 +167,7 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC&  dc)
     dc.SetPen(wxPen(BLACK_COLOR, 1));
 
     freq_hz_to_px = (float)m_rGrid.GetWidth()/(MAX_F_HZ-MIN_F_HZ);
-    ampl_dB_to_py = (float)m_rGrid.GetHeight()/(MAX_AMP_DB-MIN_AMP_DB);
+    mag_dB_to_py = (float)m_rGrid.GetHeight()/(MAX_MAG_DB-MIN_MAG_DB);
 
     // upper LH coords of plot area are (PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER)
     // lower RH coords of plot area are (PLOT_BORDER + XLEFT_OFFSET + m_rGrid.GetWidth(), 
@@ -195,7 +176,6 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC&  dc)
     // Vertical gridlines
 
     dc.SetPen(m_penShortDash);
-
     for(f=STEP_F_HZ; f<MAX_F_HZ; f+=STEP_F_HZ) {
        x = f*freq_hz_to_px;
        x += PLOT_BORDER + XLEFT_OFFSET;
@@ -207,12 +187,13 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC&  dc)
 
     // Horizontal gridlines
 
-    for(amplitude=MIN_AMP_DB; amplitude<=MAX_AMP_DB; amplitude+=STEP_AMP_DB) {
-       y = -amplitude*ampl_dB_to_py;
+    dc.SetPen(m_penDotDash);
+    for(mag=MIN_MAG_DB; mag<=MAX_MAG_DB; mag+=STEP_MAG_DB) {
+       y = -mag*mag_dB_to_py;
        y += PLOT_BORDER;
        dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, y, 
                    (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), y);
-        sprintf(buf, "%3.0fdB", amplitude);
+        sprintf(buf, "%3.0fdB", mag);
        GetTextExtent(buf, &text_w, &text_h);
         dc.DrawText(buf, PLOT_BORDER + XLEFT_OFFSET - text_w - XLEFT_TEXT_OFFSET, y-text_h/2);
    }
index 0705d292e808cced4c95713dca0177247429bfb7..d068bd54efd445e2144f8e18695ba311a3f2f0c1 100644 (file)
@@ -229,7 +229,6 @@ void PlotWaterfall::drawGraticule(wxAutoBufferedPaintDC& dc)
     // Vertical gridlines
 
     dc.SetPen(m_penShortDash);
-
     for(f=STEP_F_HZ; f<MAX_F_HZ; f+=STEP_F_HZ) {
        x = f*freq_hz_to_px;
        x += PLOT_BORDER + XLEFT_OFFSET;
@@ -241,6 +240,7 @@ void PlotWaterfall::drawGraticule(wxAutoBufferedPaintDC& dc)
 
     // Horizontal gridlines
 
+    dc.SetPen(m_penDotDash);
     for(time=0; time<=WATERFALL_SECS_Y; time++) {
        y = m_rGrid.GetHeight() - time*time_s_to_py;
        y += PLOT_BORDER;
@@ -251,33 +251,6 @@ void PlotWaterfall::drawGraticule(wxAutoBufferedPaintDC& dc)
         dc.DrawText(buf, PLOT_BORDER + XLEFT_OFFSET - text_w - XLEFT_TEXT_OFFSET, y-text_h/2);
    }
 
-#ifdef OLD
-    // Vertical gridlines
-    dc.SetPen(m_penShortDash);
-    for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < ((m_rGrid.GetWidth() - XLEFT_OFFSET) + GRID_INCREMENT); p += GRID_INCREMENT)
-    {
-        dc.DrawLine(p, (m_rGrid.GetHeight() + PLOT_BORDER), p, PLOT_BORDER);
-    }
-    // Horizontal gridlines
-    dc.SetPen(m_penDotDash);
-    for(p = (m_rGrid.GetHeight() - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT)
-    {
-        dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (p + PLOT_BORDER), (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (p + PLOT_BORDER));
-    }
-    // Label the X-Axis
-    dc.SetPen(wxPen(GREY_COLOR, 1));
-    for(p = GRID_INCREMENT; p < (m_rGrid.GetWidth() - YBOTTOM_OFFSET); p += GRID_INCREMENT)
-    {
-        sprintf(buf, "%1.1f Hz",(double)(p / 10));
-        dc.DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, m_rGrid.GetHeight() + YBOTTOM_OFFSET/3);
-    }
-    // Label the Y-Axis
-    for(p = (m_rGrid.GetHeight() - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT)
-    {
-        sprintf(buf, "%1.0f", (double)((m_rGrid.GetHeight() - p) * 10));
-        dc.DrawText(buf, XLEFT_TEXT_OFFSET, p);
-    }
-#endif
 }
 
 //-------------------------------------------------------------------------
@@ -314,7 +287,7 @@ void PlotWaterfall::plotPixelData()
     // number of dy high blocks in spectrogram
     dy_blocks = m_rGrid.GetHeight()/ dy;
 
-    intensity_per_dB  = (float)256 /(MAX_AMP_DB - MIN_AMP_DB);
+    intensity_per_dB  = (float)256 /(MAX_MAG_DB - MIN_MAG_DB);
     spec_index_per_px = (float)FDMDV_NSPEC / (float) m_rGrid.GetWidth();
     
     /*
@@ -372,7 +345,7 @@ void PlotWaterfall::plotPixelData()
            index = px * spec_index_per_px;
            assert(index < FDMDV_NSPEC);
 
-           intensity = intensity_per_dB * (g_avmag[index] - MIN_AMP_DB);
+           intensity = intensity_per_dB * (g_avmag[index] - MIN_MAG_DB);
            if(intensity > 255) intensity = 255;
            if (intensity < 0) intensity = 0;
            //printf("%d %f %d \n", index, g_avmag[index], intensity);