From 758255e748192836362710ee6de907d3c0b48b13 Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Tue, 5 Apr 2022 15:35:37 +0200
Subject: [PATCH] Also verify expected SST level.

---
 libraries/dsp/verify_pfb/tb_verify_pfb_wg.vhd | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/libraries/dsp/verify_pfb/tb_verify_pfb_wg.vhd b/libraries/dsp/verify_pfb/tb_verify_pfb_wg.vhd
index d688ef1fd7..85e9724b6b 100644
--- a/libraries/dsp/verify_pfb/tb_verify_pfb_wg.vhd
+++ b/libraries/dsp/verify_pfb/tb_verify_pfb_wg.vhd
@@ -172,7 +172,8 @@ ARCHITECTURE tb OF tb_verify_pfb_wg IS
   --CONSTANT c_view_pfir_impulse_reponse : BOOLEAN := TRUE;
   
   -- Determine bypass PFIR for PFB2, using g_fil_coefs_file_prefix setting for WPFB
-  CONSTANT c_pfs_bypass        : BOOLEAN := g_fil_coefs_file_prefix="data/run_pfir_coeff_m_bypass_16taps_1024points_16b_1wb";
+  CONSTANT c_pfs_bypass        : BOOLEAN := g_fil_coefs_file_prefix = "data/run_pfir_coeff_m_bypass_16taps_1024points_16b_1wb";
+  CONSTANT c_pfs_lofar1        : BOOLEAN := g_fil_coefs_file_prefix = "data/Coeffs16384Kaiser-quant_1wb";
 
   -- Determine PFIR coefficient width for WPFB and PFB2
   CONSTANT c_pfir_coef_w       : NATURAL := sel_a_b(g_sel_pfb="WPFB", g_fil_coef_dat_w, 16);
@@ -275,11 +276,16 @@ ARCHITECTURE tb OF tb_verify_pfb_wg IS
     
   -- SST
   -- Expected subband amplitude gain relative to input WG amplitude -1 for divide by 2 in two real input separate (Ampl --> Ampl/2)
-  -- . assume fir_filter_dc_gain ~= 1.0, like with c_wpfb_lofar1_fir_filter_dc_gain 0.994817
-  CONSTANT c_pfb_sub_scaling         : REAL := func_wpfb_subband_gain(c_wpfb);
+  -- . default assume c_fir_filter_dc_gain ~= 1.0, like with c_fil_lofar1_fir_filter_dc_gain = 0.994817
+  CONSTANT c_fir_filter_dc_gain      : REAL := sel_a_b(c_pfs_lofar1, c_fil_lofar1_fir_filter_dc_gain, 1.0);
+  CONSTANT c_pfb_sub_scaling         : REAL := func_wpfb_subband_gain(c_wpfb, c_fir_filter_dc_gain);
 
   CONSTANT c_exp_sub_a_ampl          : REAL := c_wg_ampl_a * c_pfb_sub_scaling;
-  CONSTANT c_exp_sub_b_ampl          : REAL := c_wg_ampl_a * c_pfb_sub_scaling;
+  CONSTANT c_exp_sub_b_ampl          : REAL := c_wg_ampl_b * c_pfb_sub_scaling;
+
+  -- Use 1 as integration interval, because measured sst_wg_power_a,b is normalized for c_N_blk
+  CONSTANT c_exp_sst_a               : REAL := func_wpfb_sst_level(c_exp_sub_a_ampl, 1);
+  CONSTANT c_exp_sst_b               : REAL := func_wpfb_sst_level(c_exp_sub_b_ampl, 1);
 
   -- TB
   SIGNAL bs_end                 : STD_LOGIC := '0';
@@ -1031,6 +1037,7 @@ BEGIN
       print_str("");
       print_str("Powers:");
       print_str(". sst_wg_power_a               = " & real_to_str(sst_wg_power_a, 15, 3) & " = " & real_to_str(sst_wg_power_a_dB, 7, 2) & " [dB]");
+      print_str(". sst_wg_power_a/c_exp_sst_a   = " & real_to_str(sst_wg_power_a/c_exp_sst_a, 10, 6));
       print_str(". sst_noise_a                  = " & real_to_str(sst_noise_a, 15, 3) & " = " & real_to_str(sst_noise_a_dB, 7, 2) & " [dB]");
       print_str(". sst_noise_b                  = " & real_to_str(sst_noise_b, 15, 3) & " = " & real_to_str(sst_noise_b_dB, 7, 2) & " [dB]");  -- FFT cross talk power from a to b (if g_amplitude_b = 0)
       print_str("");
@@ -1074,6 +1081,7 @@ BEGIN
       print_str(". fil_phase_Ts_b               = " & real_to_str(fil_phase_Ts_b, 10, 3));
       print_str("Powers:");
       print_str(". sst_wg_power_b               = " & real_to_str(sst_wg_power_b, 15, 3) & " = " & real_to_str(sst_wg_power_b_dB, 7, 2) & " [dB]");
+      print_str(". sst_wg_power_b/c_exp_sst_b   = " & real_to_str(sst_wg_power_b/c_exp_sst_b, 10, 6));
       print_str(". sst_noise_b                  = " & real_to_str(sst_noise_b, 15, 3) & " = " & real_to_str(sst_noise_b_dB, 7, 2) & " [dB]");
       print_str(". sst_noise_a                  = " & real_to_str(sst_noise_a, 15, 3) & " = " & real_to_str(sst_noise_a_dB, 7, 2) & " [dB]");  -- FFT cross talk power from b to a (if g_amplitude_a = 0)
       print_str("");
@@ -1097,6 +1105,8 @@ BEGIN
       ASSERT almost_equal(fir_ampl_a, fil_ampl_a, 10.0)   REPORT "Wrong estimated amplitude for FIR filter output a, " & real_to_str(fir_ampl_a, 7, 0) & " /~= " & real_to_str(fil_ampl_a, 7, 0) SEVERITY ERROR;
       ASSERT almost_equal(sub_a_ampl/cw_ampl_a/c_pfb_sub_scaling, 1.0, 0.01)
                                                           REPORT "Wrong measured scaling for PFB subband output a, " & real_to_str(sub_a_ampl/cw_ampl_a, 7, 0) & " /~= " & real_to_str(c_pfb_sub_scaling, 7, 0) SEVERITY ERROR;
+      ASSERT almost_equal(sst_wg_power_a/c_exp_sst_a, 1.0, 0.01)
+                                                          REPORT "Wrong measured scaling for PFB SST output a, " & real_to_str(sst_wg_power_a/c_exp_sst_a, 7, 0) & " /~= 1.0" SEVERITY ERROR;
     END IF;
     tb_end <= '1';
     WAIT;
-- 
GitLab