commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/18: polar: channel construction bugfixes


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/18: polar: channel construction bugfixes in Python code
Date: Tue, 8 Dec 2015 00:31:21 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 97a87e0d6e863ff1e76ae37b2e1541f7c0ab1e7e
Author: Johannes Demel <address@hidden>
Date:   Wed Sep 23 17:04:51 2015 +0200

    polar: channel construction bugfixes in Python code
---
 gr-fec/python/fec/polar/channel_construction.py    |  4 +--
 .../python/fec/polar/channel_construction_bsc.py   |  8 ++++--
 gr-fec/python/fec/polar/helper_functions.py        | 31 +++++++++++++++++-----
 3 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/gr-fec/python/fec/polar/channel_construction.py 
b/gr-fec/python/fec/polar/channel_construction.py
index 477e1df..7babb67 100644
--- a/gr-fec/python/fec/polar/channel_construction.py
+++ b/gr-fec/python/fec/polar/channel_construction.py
@@ -91,11 +91,11 @@ def default_dir():
     return path
 
 
-def save_z_parameters(z_params, block_size, design_snr, mu):
+def save_z_parameters(z_params, block_size, design_snr, mu, 
alt_construction_method='Tal-Vardy algorithm'):
     path = default_dir()
     filename = generate_filename(block_size, design_snr, mu)
     header = Z_PARAM_FIRST_HEADER_LINE + "\n"
-    header += "Channel construction method: Tal-Vardy algorithm\n"
+    header += "Channel construction method: " + alt_construction_method + "\n"
     header += "Parameters:\n"
     header += "block_size=" + str(block_size) + "\n"
     header += "design_snr=" + str(design_snr) + "\n"
diff --git a/gr-fec/python/fec/polar/channel_construction_bsc.py 
b/gr-fec/python/fec/polar/channel_construction_bsc.py
index 77057a7..7be3379 100755
--- a/gr-fec/python/fec/polar/channel_construction_bsc.py
+++ b/gr-fec/python/fec/polar/channel_construction_bsc.py
@@ -108,6 +108,10 @@ def discretize_awgn(mu, design_snr):
     for j in range(mu):
         tpm[0][j] = q_function(factor + a[j]) - q_function(factor + a[j + 1])
         tpm[1][j] = q_function(-1. * factor + a[j]) - q_function(-1. * factor 
+ a[j + 1])
+
+    tpm = tpm[::-1]
+    tpm[0] = tpm[0][::-1]
+    tpm[1] = tpm[1][::-1]
     return tpm
 
 
@@ -152,12 +156,13 @@ def upper_bound_z_params(z, block_size, design_snr):
 
 
 def tal_vardy_tpm_algorithm(block_size, design_snr, mu):
+    mu = mu // 2  # make sure algorithm uses only as many bins as specified.
     block_power = power_of_2_int(block_size)
     channels = np.zeros((block_size, 2, mu))
     channels[0] = discretize_awgn(mu, design_snr) * 2
 
     print('Constructing polar code with Tal-Vardy algorithm')
-    print('(block_size = {0}, design SNR = {1}, mu = {2}'.format(block_size, 
design_snr, mu))
+    print('(block_size = {0}, design SNR = {1}, mu = {2}'.format(block_size, 
design_snr, 2 * mu))
     show_progress_bar(0, block_size)
     for j in range(0, block_power):
         u = 2 ** j
@@ -171,7 +176,6 @@ def tal_vardy_tpm_algorithm(block_size, design_snr, mu):
 
     z = np.zeros(block_size)
     for i in range(block_size):
-        # z[i] = np.sum(channels[i][1])
         z[i] = bhattacharyya_parameter(channels[i])
 
     z = z[bit_reverse_vector(np.arange(block_size), block_power)]
diff --git a/gr-fec/python/fec/polar/helper_functions.py 
b/gr-fec/python/fec/polar/helper_functions.py
index ca66bf4..4ec0239 100644
--- a/gr-fec/python/fec/polar/helper_functions.py
+++ b/gr-fec/python/fec/polar/helper_functions.py
@@ -139,13 +139,21 @@ def mutual_information(w):
 
 
 def bhattacharyya_parameter(w):
-    '''bhattacharyya parameter is a measure of similarity between two prob. 
distributions'''
-    # sum over all y e Y for sqrt( W(y|0) * W(y|1) )
+    '''
+    bhattacharyya parameter is a measure of similarity between two prob. 
distributions
+    THEORY: sum over all y e Y for sqrt( W(y|0) * W(y|1) )
+    Implementation:
+    Numpy vector of dimension (2, mu//2)
+    holds probabilities P(x|0), first vector for even, second for odd.
+    '''
     dim = np.shape(w)
-    ydim = dim[0]
-    z = 0.0
-    for y in range(ydim):
-        z += np.sqrt(w[0, y] * w[1, y])
+    if len(dim) != 2:
+        raise ValueError
+
+    if dim[0] > dim[1]:
+        raise ValueError
+
+    z = np.sum(np.sqrt(w[0] * w[1]))
     # need all
     return z
 
@@ -164,6 +172,17 @@ def main():
     print(pos)
     print(rev_pos)
 
+    f = np.linspace(.01, .29, 10)
+    e = np.linspace(.03, .31, 10)
+
+    b = np.array([e, f])
+    zp = bhattacharyya_parameter(b)
+    print(zp)
+
+    a = np.sum(np.sqrt(e * f))
+    print(a)
+
+
 
 if __name__ == '__main__':
     main()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]