diff options
author | Johannes Demel <ufcsy@student.kit.edu> | 2015-09-23 17:04:51 +0200 |
---|---|---|
committer | Johannes Demel <ufcsy@student.kit.edu> | 2015-12-01 10:09:42 +0100 |
commit | 97a87e0d6e863ff1e76ae37b2e1541f7c0ab1e7e (patch) | |
tree | 4f5311f9219e77bf54332972186405ac3a4c4908 /gr-fec | |
parent | 7a0e28f2f0ba509119690e7f4f0a4e9adb21edf5 (diff) |
polar: channel construction bugfixes in Python code
Diffstat (limited to 'gr-fec')
-rw-r--r-- | gr-fec/python/fec/polar/channel_construction.py | 4 | ||||
-rwxr-xr-x | gr-fec/python/fec/polar/channel_construction_bsc.py | 8 | ||||
-rw-r--r-- | 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 477e1df605..7babb67854 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 77057a7c1c..7be337960b 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 ca66bf4a50..4ec02399cc 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() |