real time error histograms, seem to be doing something sensible
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 15 Jul 2015 06:25:03 +0000 (06:25 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 15 Jul 2015 06:25:03 +0000 (06:25 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2239 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2-dev/src/fdmdv2_main.cpp
fdmdv2-dev/src/fdmdv2_main.h
fdmdv2-dev/src/fdmdv2_plot_scalar.cpp

index 4cc85509b4c6021edd5707ddb0942e0893e44759..a523f3e724401bbca5df59dc95d61d98496553bf 100644 (file)
@@ -49,8 +49,9 @@ int                 g_total_bits;
 int                 g_total_bit_errors;
 int                 g_channel_noise;
 float               g_sig_pwr_av = 0.0;
-struct FIFO         *g_error_pattern_fifo;
-
+struct FIFO        *g_error_pattern_fifo;
+short              *g_error_hist;
 // time averaged magnitude spectrum used for waterfall and spectrum display
 float               g_avmag[MODEM_STATS_NSPEC];
 
@@ -234,6 +235,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
     wxGetApp().m_show_speech_out    = pConfig->Read(wxT("/MainFrame/show_speech_out"),   1);
     wxGetApp().m_show_demod_in      = pConfig->Read(wxT("/MainFrame/show_demod_in"),     1);
     wxGetApp().m_show_test_frame_errors = pConfig->Read(wxT("/MainFrame/show_test_frame_errors"),     1);
+    wxGetApp().m_show_test_frame_errors_hist = pConfig->Read(wxT("/MainFrame/show_test_frame_errors_hist"),     1);
 
     wxGetApp().m_rxNbookCtrl        = pConfig->Read(wxT("/MainFrame/rxNbookCtrl"),    (long)0);
 
@@ -309,6 +311,13 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
         m_auiNbookCtrl->AddPage(m_panelTestFrameErrors, L"Test Frame Errors", true, wxNullBitmap);
     }
 
+    if(wxGetApp().m_show_test_frame_errors_hist)
+    {
+        // Add Test Frame Errors window
+        m_panelTestFrameErrorsHist = new PlotScalar((wxFrame*) m_auiNbookCtrl, 1, 1.0, 1.0/FDMDV_NC_MAX, 0.0, 1.0, 1.0/FDMDV_NC_MAX, 0.1, "%3.2f", 0);
+        m_auiNbookCtrl->AddPage(m_panelTestFrameErrorsHist, L"Test Frame Histogram", true, wxNullBitmap);
+    }
+
     wxGetApp().m_framesPerBuffer = pConfig->Read(wxT("/Audio/framesPerBuffer"), PA_FPB);
 
     g_soundCard1InDeviceNum  = pConfig->Read(wxT("/Audio/soundCard1InDeviceNum"),         -1);
@@ -553,6 +562,7 @@ MainFrame::~MainFrame()
         pConfig->Write(wxT("/MainFrame/show_speech_out"),   wxGetApp().m_show_speech_out);
         pConfig->Write(wxT("/MainFrame/show_demod_in"),     wxGetApp().m_show_demod_in);
         pConfig->Write(wxT("/MainFrame/show_test_frame_errors"), wxGetApp().m_show_test_frame_errors);
+        pConfig->Write(wxT("/MainFrame/show_test_frame_errors_hist"), wxGetApp().m_show_test_frame_errors_hist);
 
         pConfig->Write(wxT("/MainFrame/rxNbookCtrl"), wxGetApp().m_rxNbookCtrl);
 
@@ -1112,13 +1122,26 @@ void MainFrame::OnTimer(wxTimerEvent &evt)
         if (fifo_read(g_error_pattern_fifo, error_pattern, sz_error_pattern) == 0) {
             int i,b;
 
+            /* both modes map IQ to alternate bits, but one same carrier */
+
             if (g_pfreedv->mode == FREEDV_MODE_1600) {
                 /* FreeDV 1600 mapping from error pattern to bit on each carrier */
 
                 for(b=0; b<g_Nc*2; b++) {
-                    for(i=b; i<sz_error_pattern; i+= 2*g_Nc)
+                    for(i=b; i<sz_error_pattern; i+= 2*g_Nc) {
                         m_panelTestFrameErrors->add_new_sample(b, b + 0.8*error_pattern[i]);
+                        g_error_hist[b/2] += error_pattern[i];
+                    }
+                    //if (b%2)
+                    //    printf("g_error_hist[%d]: %d\n", b/2, g_error_hist[b/2]);
                 }
+
+                int max_hist = 0;
+                for(b=0; b<g_Nc; b++)
+                    if (g_error_hist[b] > max_hist)
+                        max_hist = g_error_hist[b];
+
+                m_panelTestFrameErrorsHist->add_new_short_samples(0, g_error_hist, FDMDV_NC_MAX, max_hist);
             }
        
             if (g_pfreedv->mode == FREEDV_MODE_700) {
@@ -1128,12 +1151,24 @@ void MainFrame::OnTimer(wxTimerEvent &evt)
                    picture, we have to assume Nc/2 carriers. */
 
                 for(b=0; b<g_Nc; b++) {
-                    for(i=b; i<sz_error_pattern; i+= g_Nc)
+                    for(i=b; i<sz_error_pattern; i+= g_Nc) {
                         m_panelTestFrameErrors->add_new_sample(b, b + 0.8*error_pattern[i]);
+                        g_error_hist[b/2] += error_pattern[i];
+                    }
+                    //if (b%2)
+                    //    printf("g_error_hist[%d]: %d\n", b/2, g_error_hist[b/2]);
                 }
-            }
 
+                int max_hist = 0;
+                for(b=0; b<g_Nc/2; b++)
+                    if (g_error_hist[b] > max_hist)
+                        max_hist = g_error_hist[b];
+                m_panelTestFrameErrorsHist->add_new_short_samples(0, g_error_hist, FDMDV_NC_MAX, max_hist);
+                
+            }
             m_panelTestFrameErrors->Refresh();       
+            m_panelTestFrameErrorsHist->Refresh();
         }
     }
 
@@ -1428,6 +1463,10 @@ void MainFrame::OnBerReset(wxCommandEvent& event)
 {
     g_pfreedv->total_bits = 0;
     g_pfreedv->total_bit_errors = 0;
+    int i;
+    for(i=0; i<g_Nc; i++)
+        g_error_hist[i] = 0;
+    
 }
 
 #ifdef ALC
@@ -2018,6 +2057,10 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
         g_pfreedv->error_pattern_callback_state = (void*)m_panelTestFrameErrors;
         g_pfreedv->freedv_put_error_pattern = &my_freedv_put_error_pattern;
         g_error_pattern_fifo = fifo_create(2*g_pfreedv->sz_error_pattern);
+        g_error_hist = new short[FDMDV_NC_MAX];
+        int i;
+        for(i=0; i<FDMDV_NC_MAX; i++)
+            g_error_hist[i] = 0;
 
         //if (g_mode == FREEDV_MODE_700)
         //    cohpsk_set_verbose(g_pfreedv->cohpsk, 1);
@@ -2126,6 +2169,7 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event)
         // free up states
 
         modem_stats_close(&g_stats);
+        delete g_error_hist;
         fifo_destroy(g_error_pattern_fifo);
         freedv_close(g_pfreedv);
         speex_preprocess_state_destroy(g_speex_st);
@@ -3234,7 +3278,15 @@ void per_frame_rx_processing(
         }
        
         if (g_channel_noise) {
-            fdmdv_simulate_channel(&g_sig_pwr_av, rx_fdm, nin, 2.0);
+            float snr;
+
+            /* enough noise to get a couple of % errors */
+
+            if (g_pfreedv->mode == FREEDV_MODE_1600)
+                snr = 2.0;
+             if (g_pfreedv->mode == FREEDV_MODE_700)
+                snr = -1.0;           
+            fdmdv_simulate_channel(&g_sig_pwr_av, rx_fdm, nin, snr);
         }
         fdmdv_freq_shift(rx_fdm_offset, rx_fdm, g_RxFreqOffsetHz, &g_RxFreqOffsetPhaseRect, nin);
         nout = freedv_comprx(g_pfreedv, output_buf, rx_fdm_offset);
index 4f8c24253987e46bf41c98f2500756790216ab5a..cde723be6ee3930b8ba73df91ec12302f9a39bec 100644 (file)
@@ -226,6 +226,7 @@ class MainApp : public wxApp
         int                 m_show_speech_out;
         int                 m_show_demod_in;
         int                 m_show_test_frame_errors;
+        int                 m_show_test_frame_errors_hist;
 
         // optional vox trigger tone
         bool                m_leftChannelVoxTone;
@@ -366,6 +367,7 @@ class MainFrame : public TopFrame
         PlotScalar*             m_panelSpeechOut;
         PlotScalar*             m_panelDemodIn;
         PlotScalar*             m_panelTestFrameErrors;
+        PlotScalar*             m_panelTestFrameErrorsHist;
 
         bool                    m_RxRunning;
 
index a29911f267d8d7ab228ae0005ef44130cf597fea..7a07f46f5b19551e51aae221059544025fd4391d 100644 (file)
@@ -36,14 +36,14 @@ END_EVENT_TABLE()
 // PlotScalar()
 //----------------------------------------------------------------
 PlotScalar::PlotScalar(wxFrame* parent, 
-                       int    channels,           // number on channel to plot
+                       int    channels,           // number on channels to plot
                       float  t_secs,             // time covered by entire x axis in seconds
                       float  sample_period_secs, // time between each sample in seconds
                       float  a_min,              // min ampltude of samples being plotted
                       float  a_max,              // max ampltude of samples being plotted
                       float  graticule_t_step,   // time step of x (time) axis graticule in seconds
                       float  graticule_a_step,   // step of amplitude axis graticule
-                      const char a_fmt[],        // printf format string for amlitude axis labels
+                      const char a_fmt[],        // printf format string for amplitude axis labels
                        int    mini                // true for mini-plot - don't draw graticule
                       ): PlotPanel(parent)
 {