From: drowe67 Date: Tue, 27 Nov 2012 01:24:40 +0000 (+0000) Subject: automatic scaling of spectrogram, and toggling color mapping. Think it works better... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=a8eb76061a4f26d1547f265d77314eb2faac46c5;p=freetel-svn-tracking.git automatic scaling of spectrogram, and toggling color mapping. Think it works better but need to try on real signals git-svn-id: https://svn.code.sf.net/p/freetel/code@1079 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/src/fdmdv2_defines.h b/fdmdv2/src/fdmdv2_defines.h index 9116d7f2..f751c717 100644 --- a/fdmdv2/src/fdmdv2_defines.h +++ b/fdmdv2/src/fdmdv2_defines.h @@ -32,7 +32,8 @@ #define BETA 0.95 // constant for time averaging spectrum data #define MIN_F_HZ 0 // min freq on Waterfall and Spectrum #define MAX_F_HZ 4000 // max freq on Waterfall and Spectrum -#define STEP_F_HZ 500 // freq step on Waterfall and Spectrum graticule +#define STEP_F_HZ 500 // major (e.g. text legend) freq step on Waterfall and Spectrum graticule +#define STEP_MINOR_F_HZ 100 // minor (ticks) freq step on Waterfall and Spectrum graticule #define WATERFALL_SECS_Y 30 // number of seconds respresented by y axis of waterfall #define WATERFALL_SECS_STEP 5 // graticule y axis steps of waterfall #define DT 0.1 // time between real time graphing updates diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index fcbd8593..8b574003 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -218,13 +218,15 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) { // Add Waterfall Plot window - m_panelWaterfall = new PlotWaterfall((wxFrame*) m_auiNbookCtrl, false); + m_panelWaterfall = new PlotWaterfall((wxFrame*) m_auiNbookCtrl, false, 0); + m_panelWaterfall->SetToolTip(_("Left click to tune, Right click to toggle mono/colour")); m_auiNbookCtrl->AddPage(m_panelWaterfall, _("Waterfall"), true, wxNullBitmap); } if(wxGetApp().m_show_spect) { // Add Spectrum Plot window m_panelSpectrum = new PlotSpectrum((wxFrame*) m_auiNbookCtrl); + m_panelSpectrum->SetToolTip(_("Left click to tune")); m_auiNbookCtrl->AddPage(m_panelSpectrum, _("Spectrum"), true, wxNullBitmap); } if(wxGetApp().m_show_scatter) @@ -817,6 +819,9 @@ void MainFrame::OnTogBtnTXClick(wxCommandEvent& event) //------------------------------------------------------------------------- void MainFrame::OnTogBtnRxID(wxCommandEvent& event) { + // empty any junk in rx data FIFO + short junk; + while(fifo_read(g_rxDataOutFifo,&junk,1) == 0); event.Skip(); } diff --git a/fdmdv2/src/fdmdv2_plot.cpp b/fdmdv2/src/fdmdv2_plot.cpp index e5987148..1b85cd90 100644 --- a/fdmdv2/src/fdmdv2_plot.cpp +++ b/fdmdv2/src/fdmdv2_plot.cpp @@ -24,8 +24,9 @@ BEGIN_EVENT_TABLE(PlotPanel, wxPanel) EVT_PAINT (PlotPanel::OnPaint) EVT_MOTION (PlotPanel::OnMouseMove) - EVT_LEFT_DOWN (PlotPanel::OnMouseDown) - EVT_LEFT_UP (PlotPanel::OnMouseUp) + EVT_LEFT_DOWN (PlotPanel::OnMouseLeftDown) + EVT_LEFT_UP (PlotPanel::OnMouseLeftUp) + EVT_RIGHT_DOWN (PlotPanel::OnMouseRightDown) EVT_MOUSEWHEEL (PlotPanel::OnMouseWheelMoved) EVT_SIZE (PlotPanel::OnSize) EVT_SHOW (PlotPanel::OnShow) @@ -140,9 +141,16 @@ void PlotPanel::OnMouseMove(wxMouseEvent& event) } //------------------------------------------------------------------------- -// OnMouseDown() +// OnMouseLeftDown() //------------------------------------------------------------------------- -void PlotPanel::OnMouseDown(wxMouseEvent& event) +void PlotPanel::OnMouseLeftDown(wxMouseEvent& event) +{ +} + +//------------------------------------------------------------------------- +// OnMouseRightDown() +//------------------------------------------------------------------------- +void PlotPanel::OnMouseRightDown(wxMouseEvent& event) { } @@ -154,9 +162,9 @@ void PlotPanel::OnMouseWheelMoved(wxMouseEvent& event) } //------------------------------------------------------------------------- -// OnMouseUp() +// OnMouseLeftUp() //------------------------------------------------------------------------- -void PlotPanel::OnMouseUp(wxMouseEvent& event) +void PlotPanel::OnMouseLeftUp(wxMouseEvent& event) { m_mouseDown = false; } diff --git a/fdmdv2/src/fdmdv2_plot.h b/fdmdv2/src/fdmdv2_plot.h index 453f58b3..25309d3a 100644 --- a/fdmdv2/src/fdmdv2_plot.h +++ b/fdmdv2/src/fdmdv2_plot.h @@ -45,7 +45,7 @@ #define XLEFT_OFFSET 40 #define XLEFT_TEXT_OFFSET 6 #define YBOTTOM_OFFSET 20 -#define YBOTTOM_TEXT_OFFSET 6 +#define YBOTTOM_TEXT_OFFSET 15 #define GRID_INCREMENT 50 #define BLACK_COLOR wxColor(0x00, 0x00, 0x00) @@ -109,8 +109,9 @@ class PlotPanel : public wxPanel // some useful events void OnMouseMove(wxMouseEvent& event); - virtual void OnMouseDown(wxMouseEvent& event); - void OnMouseUp(wxMouseEvent& event); + virtual void OnMouseLeftDown(wxMouseEvent& event); + void OnMouseLeftUp(wxMouseEvent& event); + virtual void OnMouseRightDown(wxMouseEvent& event); void OnMouseWheelMoved(wxMouseEvent& event); void OnClose(wxCloseEvent& event ){ event.Skip(); } void OnSize( wxSizeEvent& event ); diff --git a/fdmdv2/src/fdmdv2_plot_scalar.cpp b/fdmdv2/src/fdmdv2_plot_scalar.cpp index e19ff3d3..8b5d8184 100644 --- a/fdmdv2/src/fdmdv2_plot_scalar.cpp +++ b/fdmdv2/src/fdmdv2_plot_scalar.cpp @@ -26,8 +26,6 @@ BEGIN_EVENT_TABLE(PlotScalar, PlotPanel) EVT_PAINT (PlotScalar::OnPaint) EVT_MOTION (PlotScalar::OnMouseMove) - EVT_LEFT_DOWN (PlotScalar::OnMouseDown) - EVT_LEFT_UP (PlotScalar::OnMouseUp) EVT_MOUSEWHEEL (PlotScalar::OnMouseWheelMoved) EVT_SIZE (PlotScalar::OnSize) EVT_SHOW (PlotScalar::OnShow) diff --git a/fdmdv2/src/fdmdv2_plot_scatter.cpp b/fdmdv2/src/fdmdv2_plot_scatter.cpp index 4b5b92b6..1c9707a6 100644 --- a/fdmdv2/src/fdmdv2_plot_scatter.cpp +++ b/fdmdv2/src/fdmdv2_plot_scatter.cpp @@ -25,8 +25,6 @@ BEGIN_EVENT_TABLE(PlotScatter, PlotPanel) EVT_PAINT (PlotScatter::OnPaint) EVT_MOTION (PlotScatter::OnMouseMove) - EVT_LEFT_DOWN (PlotScatter::OnMouseDown) - EVT_LEFT_UP (PlotScatter::OnMouseUp) EVT_MOUSEWHEEL (PlotScatter::OnMouseWheelMoved) EVT_SIZE (PlotScatter::OnSize) EVT_SHOW (PlotScatter::OnShow) diff --git a/fdmdv2/src/fdmdv2_plot_spectrum.cpp b/fdmdv2/src/fdmdv2_plot_spectrum.cpp index b4a171fe..12940be0 100644 --- a/fdmdv2/src/fdmdv2_plot_spectrum.cpp +++ b/fdmdv2/src/fdmdv2_plot_spectrum.cpp @@ -28,8 +28,8 @@ void fdmdv2_clickTune(float frequency); // callback to pass new click freq BEGIN_EVENT_TABLE(PlotSpectrum, PlotPanel) EVT_MOTION (PlotSpectrum::OnMouseMove) - EVT_LEFT_DOWN (PlotSpectrum::OnMouseDown) - EVT_LEFT_UP (PlotSpectrum::OnMouseUp) + EVT_LEFT_DOWN (PlotSpectrum::OnMouseLeftDown) + EVT_LEFT_UP (PlotSpectrum::OnMouseLeftUp) EVT_MOUSEWHEEL (PlotSpectrum::OnMouseWheelMoved) EVT_PAINT (PlotSpectrum::OnPaint) EVT_SHOW (PlotSpectrum::OnShow) @@ -175,16 +175,28 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC& dc) // Vertical gridlines - dc.SetPen(m_penShortDash); for(f=STEP_F_HZ; f max_mag) + max_mag = g_avmag[i]; + } + m_max_mag = BETA*m_max_mag + (1 - BETA)*max_mag; + m_min_mag = max_mag - 20.0; + //printf("max_mag: %f m_max_mag: %f\n", max_mag, m_max_mag); + //intensity_per_dB = (float)256 /(MAX_MAG_DB - MIN_MAG_DB); + intensity_per_dB = (float)256 /(m_max_mag - m_min_mag); spec_index_per_px = (float)FDMDV_NSPEC / (float) m_rGrid.GetWidth(); /* @@ -365,27 +395,35 @@ void PlotWaterfall::plotPixelData() index = px * spec_index_per_px; assert(index < FDMDV_NSPEC); - intensity = intensity_per_dB * (g_avmag[index] - MIN_MAG_DB); + intensity = intensity_per_dB * (g_avmag[index] - m_min_mag); if(intensity > 255) intensity = 255; if (intensity < 0) intensity = 0; //printf("%d %f %d \n", index, g_avmag[index], intensity); - if (m_greyscale) { - if (intensity > 200) { + switch (m_colour) { + case 0: + p.Red() = m_heatmap_lut[intensity] & 0xff; + p.Green() = (m_heatmap_lut[intensity] >> 8) & 0xff; + p.Blue() = (m_heatmap_lut[intensity] >> 16) & 0xff; + break; + case 1: + p.Red() = intensity; + p.Green() = intensity; + p.Blue() = intensity; + break; + case 2: + if (intensity > 250) { p.Red() = intensity; p.Green() = intensity; - p.Blue() = intensity; + p.Blue() = intensity; } else { p.Red() = 0; p.Green() = 0; - p.Blue() = intensity; + p.Blue() = intensity; } - } - else { - p.Red() = m_heatmap_lut[intensity] & 0xff; - p.Green() = (m_heatmap_lut[intensity] >> 8) & 0xff; - p.Blue() = (m_heatmap_lut[intensity] >> 16) & 0xff; + + break; } ++p; } @@ -396,9 +434,9 @@ void PlotWaterfall::plotPixelData() } //------------------------------------------------------------------------- -// OnMouseDown() +// OnMouseLeftDown() //------------------------------------------------------------------------- -void PlotWaterfall::OnMouseDown(wxMouseEvent& event) +void PlotWaterfall::OnMouseLeftDown(wxMouseEvent& event) { m_mouseDown = true; wxClientDC dc(this); @@ -419,3 +457,14 @@ void PlotWaterfall::OnMouseDown(wxMouseEvent& event) fdmdv2_clickTune(clickFreq); } } + +//------------------------------------------------------------------------- +// OnMouseRightDown() +//------------------------------------------------------------------------- +void PlotWaterfall::OnMouseRightDown(wxMouseEvent& event) +{ + m_colour++; + if (m_colour == 3) + m_colour = 0; +} + diff --git a/fdmdv2/src/fdmdv2_plot_waterfall_linux.h b/fdmdv2/src/fdmdv2_plot_waterfall_linux.h index 92ecfa88..e5c0e836 100644 --- a/fdmdv2/src/fdmdv2_plot_waterfall_linux.h +++ b/fdmdv2/src/fdmdv2_plot_waterfall_linux.h @@ -37,7 +37,7 @@ class PlotWaterfall : public PlotPanel { public: - PlotWaterfall(wxFrame* parent, bool greyscale); + PlotWaterfall(wxFrame* parent, bool graticule, int colour); ~PlotWaterfall(); bool checkDT(void); void setGreyscale(bool greyscale) { m_greyscale = greyscale; } @@ -54,11 +54,16 @@ class PlotWaterfall : public PlotPanel void drawGraticule(wxAutoBufferedPaintDC& dc); void draw(wxAutoBufferedPaintDC& dc); void plotPixelData(); - void OnMouseDown(wxMouseEvent& event); + void OnMouseLeftDown(wxMouseEvent& event); + void OnMouseRightDown(wxMouseEvent& event); private: float m_dT; float m_rxFreq; + bool m_graticule; + float m_min_mag; + float m_max_mag; + int m_colour; DECLARE_EVENT_TABLE() }; diff --git a/fdmdv2/src/topFrame.cpp b/fdmdv2/src/topFrame.cpp index ec5fa191..6b209354 100644 --- a/fdmdv2/src/topFrame.cpp +++ b/fdmdv2/src/topFrame.cpp @@ -128,7 +128,7 @@ TopFrame::TopFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxStaticBoxSizer* levelSizer; levelSizer = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Level")), wxVERTICAL); - m_textLevel = new wxStaticText(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(50,-1), wxALIGN_CENTRE); + m_textLevel = new wxStaticText(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(60,-1), wxALIGN_CENTRE); m_textLevel->SetForegroundColour(wxColour(255,0,0)); levelSizer->Add(m_textLevel, 0, wxALIGN_LEFT, 1);