From b9a0281701baeb56e4d16af90db6768af1c2c7b7 Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Tue, 25 Oct 2022 13:37:30 +0200
Subject: [PATCH] Add fig that is normalized by weights.

---
 .../base/common/python/try_round_weight.py    | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/libraries/base/common/python/try_round_weight.py b/libraries/base/common/python/try_round_weight.py
index ad02822219..7b8a3ec60a 100644
--- a/libraries/base/common/python/try_round_weight.py
+++ b/libraries/base/common/python/try_round_weight.py
@@ -67,6 +67,7 @@ _parser = argparse.ArgumentParser(
 
         # Get an overview
         > python try_round_weight.py --w_lo 0.2 --w_hi 3.0 --w_step 0.01 --s_lo 0.5 --s_hi 10 --s_step 0.2 -N 195312 -S 1
+        > python try_round_weight.py --w_lo 0.2 --w_hi 2.0 --w_step 0.01 --s_lo 1 --s_hi 10 --s_step 1 -N 195312 -S 1
 
         # Zoom in at w = 0.75
         > python try_round_weight.py --w_lo 0.7 --w_hi 0.8 --w_step 0.0001 --s_lo 1 --s_hi 10 --s_step 1 -N 195312 -S 0
@@ -154,6 +155,8 @@ figNr = 0
 figNr += 1
 plt.figure(figNr)
 for s, sigma in enumerate(sigmas):
+    # Plot sigma_qq of twice quantized noise as function of weight for
+    # different input sigmas
     plt.plot(weights, sigmas_qq_T[s], label='s = %4.2f' % sigma)
 plt.title("Sigma of weighted quantized noise")
 plt.xlabel("Weight")
@@ -164,6 +167,25 @@ plt.grid()
 figNr += 1
 plt.figure(figNr)
 for s, sigma in enumerate(sigmas):
+    # Plot sigma_qq of twice quantized noise as function of weight for
+    # different input sigmas.
+    # Normalize the sigma_qq by the weight, so that it can be compared with
+    # the input sigma that is shown by the horizontal sigma reference lines.
+    plt.plot(weights, sigmas_qq_T[s] / weights, label='s = %4.2f' % sigma)
+    plt.plot(weights, sigmas[s]*np.ones(N_weights))  # add sigma reference lines
+plt.title("Sigma of weighted quantized noise, normalized for weight")
+plt.xlabel("Weight")
+plt.ylabel("Sigma_qq")
+plt.legend(loc='upper right')
+plt.grid()
+
+figNr += 1
+plt.figure(figNr)
+for s, sigma in enumerate(sigmas):
+    # Plot ratio of sigma_qq / sigma_sq as function of weight for different
+    # input sigma. The ratio deviation from 1 tells how much the twice
+    # quantized noise deviates from the noise that is only quantized after
+    # the weighting.
     plt.plot(weights, sigmas_ratio_T[s], label='s = %4.2f' % sigma)
 plt.title("Relative sigma difference of weighting after / before quantisation")
 plt.xlabel("Weight")
@@ -174,6 +196,8 @@ plt.grid()
 figNr += 1
 plt.figure(figNr)
 for w, weight in enumerate(weights):
+    # Plot ratio of sigma_qq / sigma_sq as function of input sigma for
+    # different weights
     plt.plot(sigmas, sigmas_ratio[w], label='w = %4.2f' % weight)
 plt.title("Relative sigma difference of weighting after / before quantisation")
 plt.xlabel("Sigma")
-- 
GitLab