summaryrefslogtreecommitdiff
path: root/gr-fec/python/fec/polar/helper_functions.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-fec/python/fec/polar/helper_functions.py')
-rw-r--r--gr-fec/python/fec/polar/helper_functions.py49
1 files changed, 43 insertions, 6 deletions
diff --git a/gr-fec/python/fec/polar/helper_functions.py b/gr-fec/python/fec/polar/helper_functions.py
index ca66bf4a50..85140c856f 100644
--- a/gr-fec/python/fec/polar/helper_functions.py
+++ b/gr-fec/python/fec/polar/helper_functions.py
@@ -23,6 +23,24 @@ import time, sys
import copy
+def bsc_channel(p):
+ '''
+ binary symmetric channel (BSC)
+ output alphabet Y = {0, 1} and
+ W(0|0) = W(1|1) and W(1|0) = W(0|1)
+
+ this function returns a prob's vector for a BSC
+ p denotes an erroneous transistion
+ '''
+ if not (p >= 0.0 and p <= 1.0):
+ print "given p is out of range!"
+ return np.array([], dtype=float)
+
+ # 0 -> 0, 0 -> 1, 1 -> 0, 1 -> 1
+ W = np.array([[1 - p, p], [p, 1 - p]], dtype=float)
+ return W
+
+
def power_of_2_int(num):
return int(np.log2(num))
@@ -139,13 +157,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 +190,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()