summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/python/gnuradio/blks2impl/psk2.py
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src/python/gnuradio/blks2impl/psk2.py')
-rw-r--r--gnuradio-core/src/python/gnuradio/blks2impl/psk2.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/psk2.py b/gnuradio-core/src/python/gnuradio/blks2impl/psk2.py
index 4fd2c77fec..95f25e75a9 100644
--- a/gnuradio-core/src/python/gnuradio/blks2impl/psk2.py
+++ b/gnuradio-core/src/python/gnuradio/blks2impl/psk2.py
@@ -28,17 +28,32 @@ from cmath import exp
from gnuradio import gr, modulation_utils2
from gnuradio.blks2impl.generic_mod_demod import generic_mod, generic_demod
+from gnuradio.utils import mod_codes, gray_code
# Default number of points in constellation.
_def_constellation_points = 4
-# Whether differential coding is used.
-_def_differential = True
-
+# The default encoding (e.g. gray-code, set-partition)
+_def_mod_code = mod_codes.GRAY_CODE
+
+def create_encodings(mod_code, arity):
+ post_diff_code = None
+ if mod_code not in mod_codes.codes:
+ raise ValueError('That modulation code does not exist.')
+ if mod_code == mod_codes.GRAY_CODE:
+ pre_diff_code = gray_code.gray_code(arity)
+ elif mod_code == mod_codes.SET_PARTITION_CODE:
+ pre_diff_code = set_partition_code.set_partition_code(arity)
+ elif mod_code == mod_codes.NO_CODE:
+ pre_diff_code = []
+ else:
+ raise ValueError('That modulation code is not implemented for this constellation.')
+ return (pre_diff_code, post_diff_code)
+
# /////////////////////////////////////////////////////////////////////////////
# PSK constellation
# /////////////////////////////////////////////////////////////////////////////
-def psk_constellation(m=_def_constellation_points):
+def psk_constellation(m=_def_constellation_points, mod_code=_def_mod_code):
"""
Creates a PSK constellation object.
"""
@@ -46,7 +61,11 @@ def psk_constellation(m=_def_constellation_points):
if (k != int(k)):
raise StandardError('Number of constellation points must be a power of two.')
points = [exp(2*pi*(0+1j)*i/m) for i in range(0,m)]
- constellation = gr.constellation_psk(points, m)
+ pre_diff_code, post_diff_code = create_encodings(mod_code, m)
+ if post_diff_code is not None:
+ inverse_post_diff_code = mod_codes.invert_code(post_diff_code)
+ points = [points[x] for x in inverse_post_diff_code]
+ constellation = gr.constellation_psk(points, pre_diff_code, m)
return constellation
# /////////////////////////////////////////////////////////////////////////////
@@ -56,6 +75,7 @@ def psk_constellation(m=_def_constellation_points):
class psk_mod(generic_mod):
def __init__(self, constellation_points=_def_constellation_points,
+ mod_code=_def_mod_code,
*args, **kwargs):
"""
@@ -67,7 +87,7 @@ class psk_mod(generic_mod):
See generic_mod block for list of parameters.
"""
- constellation = psk_constellation(constellation_points)
+ constellation = psk_constellation(constellation_points, mod_code)
super(psk_mod, self).__init__(constellation, *args, **kwargs)
# /////////////////////////////////////////////////////////////////////////////
@@ -78,6 +98,7 @@ class psk_mod(generic_mod):
class psk_demod(generic_demod):
def __init__(self, constellation_points=_def_constellation_points,
+ mod_code=_def_mod_code,
*args, **kwargs):
"""
@@ -89,7 +110,7 @@ class psk_demod(generic_demod):
See generic_demod block for list of parameters.
"""
- constellation = psk_constellation(constellation_points)
+ constellation = psk_constellation(constellation_points, mod_code)
super(psk_demod, self).__init__(constellation, *args, **kwargs)
#