#define FDMDV_NSPEC 512
-#define MIN_DB -40.0 // minimum of spectram/waterfall DB axis
-#define MAX_DB 0.0
-#define STEP_DB 10.0
+#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 BETA 0.1 // constant for time averageing spectrum data
-#define MIN_HZ 0 // min freq on Waterfall and Spectrum
-#define MAX_HZ 4000 // max freq on Waterfall and Spectrum
-#define STEP_HZ 500 // freq step on Waterfall and Spectrum graticule
+#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 WATERFALL_SECS_Y 5 // number of seconds respresented by y axis of waterfall
#define DT 0.1 // time between Waterfall updates
#define FS 8000 // FDMDV modem sample rate
// OnSize()
//----------------------------------------------------------------
void PlotSpectrum::OnSize(wxSizeEvent& event) {
- printf("PlotSpectrum::OnSize\n");
}
//----------------------------------------------------------------
//----------------------------------------------------------------
void PlotSpectrum::OnPaint(wxPaintEvent& event)
{
- printf("PlotSpectrum::OnPaint\n");
wxAutoBufferedPaintDC dc(this);
draw(dc);
}
int x, y, text_w, text_h;
char buf[15];
wxString s;
- float f, dB, freq_hz_to_px, ampl_dB_to_px;
+ float f, amplitude, freq_hz_to_px, ampl_dB_to_py;
wxBrush ltGraphBkgBrush;
ltGraphBkgBrush.SetStyle(wxBRUSHSTYLE_TRANSPARENT);
dc.SetBrush(ltGraphBkgBrush);
dc.SetPen(wxPen(BLACK_COLOR, 1));
- freq_hz_to_px = (float)m_rGrid.GetWidth()/(MAX_HZ-MIN_HZ);
- ampl_dB_to_px = (float)m_rGrid.GetHeight()/(MAX_DB-MIN_DB);
+ 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);
// 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(),
dc.SetPen(m_penShortDash);
- for(f=STEP_HZ; f<MAX_HZ; f+=STEP_HZ) {
+ for(f=STEP_F_HZ; f<MAX_F_HZ; f+=STEP_F_HZ) {
x = f*freq_hz_to_px;
x += PLOT_BORDER + XLEFT_OFFSET;
dc.DrawLine(x, m_rGrid.GetHeight() + PLOT_BORDER, x, PLOT_BORDER);
// Horizontal gridlines
- for(dB=MIN_DB; dB<MAX_DB; dB+=STEP_DB) {
- y = m_rGrid.GetHeight() + dB*ampl_dB_to_px;
+ for(amplitude=MIN_AMP_DB; amplitude<=MAX_AMP_DB; amplitude+=STEP_AMP_DB) {
+ y = -amplitude*ampl_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", dB);
+ sprintf(buf, "%3.0fdB", amplitude);
GetTextExtent(buf, &text_w, &text_h);
dc.DrawText(buf, PLOT_BORDER + XLEFT_OFFSET - text_w - XLEFT_TEXT_OFFSET, y-text_h/2);
}
//-------------------------------------------------------------------------
void PlotWaterfall::drawGraticule(wxAutoBufferedPaintDC& dc)
{
- int p;
- char buf[15];
-
+ int x, y, text_w, text_h;
+ char buf[15];
wxString s;
+ float f, time, freq_hz_to_px, time_s_to_py;
wxBrush ltGraphBkgBrush;
ltGraphBkgBrush.SetStyle(wxBRUSHSTYLE_TRANSPARENT);
dc.SetBrush(ltGraphBkgBrush);
dc.SetPen(wxPen(BLACK_COLOR, 1));
+ freq_hz_to_px = (float)m_rGrid.GetWidth()/(MAX_F_HZ-MIN_F_HZ);
+ time_s_to_py = (float)m_rGrid.GetHeight()/WATERFALL_SECS_Y;
+
+ // 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(),
+ // PLOT_BORDER + m_rGrid.GetHeight())
+
+ // 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;
+ dc.DrawLine(x, m_rGrid.GetHeight() + PLOT_BORDER, x, PLOT_BORDER);
+ sprintf(buf, "%4.0fHz", f);
+ GetTextExtent(buf, &text_w, &text_h);
+ dc.DrawText(buf, x - text_w/2, m_rGrid.GetHeight() + PLOT_BORDER + YBOTTOM_TEXT_OFFSET);
+ }
+
+ // Horizontal gridlines
+
+ for(time=0; time<=WATERFALL_SECS_Y; time++) {
+ y = m_rGrid.GetHeight() - time*time_s_to_py;
+ y += PLOT_BORDER;
+ dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, y,
+ (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), y);
+ sprintf(buf, "%3.0fs", time);
+ GetTextExtent(buf, &text_w, &text_h);
+ 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)
sprintf(buf, "%1.0f", (double)((m_rGrid.GetHeight() - p) * 10));
dc.DrawText(buf, XLEFT_TEXT_OFFSET, p);
}
+#endif
}
//-------------------------------------------------------------------------
// number of dy high blocks in spectrogram
dy_blocks = m_rGrid.GetHeight()/ dy;
- intensity_per_dB = (float)256 /(MAX_DB - MIN_DB);
+ intensity_per_dB = (float)256 /(MAX_AMP_DB - MIN_AMP_DB);
spec_index_per_px = (float)FDMDV_NSPEC / (float) m_rGrid.GetWidth();
/*
index = px * spec_index_per_px;
assert(index < FDMDV_NSPEC);
- intensity = intensity_per_dB * (g_avmag[index] - MIN_DB);
+ intensity = intensity_per_dB * (g_avmag[index] - MIN_AMP_DB);
if(intensity > 255) intensity = 255;
if (intensity < 0) intensity = 0;
//printf("%d %f %d \n", index, g_avmag[index], intensity);