summaryrefslogtreecommitdiff
path: root/gr-digital/python
diff options
context:
space:
mode:
Diffstat (limited to 'gr-digital/python')
-rw-r--r--gr-digital/python/bpsk.py61
-rw-r--r--gr-digital/python/cpm.py2
-rw-r--r--gr-digital/python/generic_mod_demod.py37
-rw-r--r--gr-digital/python/pkt.py2
-rw-r--r--gr-digital/python/psk.py29
-rwxr-xr-xgr-digital/python/qa_constellation.py30
-rwxr-xr-xgr-digital/python/qa_constellation_receiver.py36
-rwxr-xr-xgr-digital/python/qa_glfsr_source.py8
-rw-r--r--gr-digital/python/qam.py14
-rw-r--r--gr-digital/python/qpsk.py91
10 files changed, 172 insertions, 138 deletions
diff --git a/gr-digital/python/bpsk.py b/gr-digital/python/bpsk.py
index 0d8f05c4c1..9f2354003c 100644
--- a/gr-digital/python/bpsk.py
+++ b/gr-digital/python/bpsk.py
@@ -31,18 +31,11 @@ from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod
import digital_swig
import modulation_utils
-# Default number of points in constellation.
-_def_constellation_points = 2
-# Whether differential coding is used.
-_def_differential = False
-
# /////////////////////////////////////////////////////////////////////////////
# BPSK constellation
# /////////////////////////////////////////////////////////////////////////////
-def bpsk_constellation(m=_def_constellation_points):
- if m != _def_constellation_points:
- raise ValueError("BPSK can only have 2 constellation points.")
+def bpsk_constellation():
return digital_swig.constellation_bpsk()
# /////////////////////////////////////////////////////////////////////////////
@@ -51,8 +44,7 @@ def bpsk_constellation(m=_def_constellation_points):
class bpsk_mod(generic_mod):
- def __init__(self, constellation_points=_def_constellation_points,
- differential=False, *args, **kwargs):
+ def __init__(self, mod_code=None, differential=False, *args, **kwargs):
"""
Hierarchical block for RRC-filtered BPSK modulation.
@@ -61,12 +53,12 @@ class bpsk_mod(generic_mod):
output is the complex modulated signal at baseband.
See generic_mod block for list of parameters.
+
+ 'mod_code' argument is not used.
+ It exists purely to simplify generation of the block in grc.
"""
- constellation_points = _def_constellation_points
constellation = digital_swig.constellation_bpsk()
- if constellation_points != 2:
- raise ValueError('Number of constellation points must be 2 for BPSK.')
super(bpsk_mod, self).__init__(constellation=constellation,
differential=differential, *args, **kwargs)
@@ -77,8 +69,7 @@ class bpsk_mod(generic_mod):
class bpsk_demod(generic_demod):
- def __init__(self, constellation_points=_def_constellation_points,
- differential=False, *args, **kwargs):
+ def __init__(self, mod_code=None, differential=False, *args, **kwargs):
"""
Hierarchical block for RRC-filtered BPSK modulation.
@@ -87,12 +78,12 @@ class bpsk_demod(generic_demod):
output is the complex modulated signal at baseband.
See generic_demod block for list of parameters.
+
+ 'mod_code' argument is not used.
+ It exists purely to simplify generation of the block in grc.
"""
- constellation_points = _def_constellation_points
constellation = digital_swig.constellation_bpsk()
- if constellation_points != 2:
- raise ValueError('Number of constellation points must be 2 for BPSK.')
super(bpsk_demod, self).__init__(constellation=constellation,
differential=differential, *args, **kwargs)
@@ -102,19 +93,16 @@ class bpsk_demod(generic_demod):
# DBPSK constellation
# /////////////////////////////////////////////////////////////////////////////
-def dbpsk_constellation(m=_def_constellation_points):
- if m != _def_constellation_points:
- raise ValueError("DBPSK can only have 2 constellation points.")
+def dbpsk_constellation():
return digital_swig.constellation_dbpsk()
# /////////////////////////////////////////////////////////////////////////////
# DBPSK modulator
# /////////////////////////////////////////////////////////////////////////////
-class dbpsk_mod(generic_mod):
+class dbpsk_mod(bpsk_mod):
- def __init__(self, constellation_points=_def_constellation_points,
- differential=True, *args, **kwargs):
+ def __init__(self, mod_code=None, *args, **kwargs):
"""
Hierarchical block for RRC-filtered DBPSK modulation.
@@ -123,14 +111,12 @@ class dbpsk_mod(generic_mod):
output is the complex modulated signal at baseband.
See generic_mod block for list of parameters.
+
+ 'mod_code' argument is not used.
+ It exists purely to simplify generation of the block in grc.
"""
- constellation_points = _def_constellation_points
- constellation = digital_swig.constellation_bpsk()
- if constellation_points != 2:
- raise ValueError('Number of constellation points must be 2 for DBPSK.')
- super(dbpsk_mod, self).__init__(constellation=constellation,
- differential=True,
+ super(dbpsk_mod, self).__init__(differential=True,
*args, **kwargs)
# /////////////////////////////////////////////////////////////////////////////
@@ -138,10 +124,9 @@ class dbpsk_mod(generic_mod):
#
# /////////////////////////////////////////////////////////////////////////////
-class dbpsk_demod(generic_demod):
+class dbpsk_demod(bpsk_demod):
- def __init__(self, constellation_points=_def_constellation_points,
- differential=True, *args, **kwargs):
+ def __init__(self, mod_code=None, *args, **kwargs):
"""
Hierarchical block for RRC-filtered DBPSK modulation.
@@ -150,14 +135,12 @@ class dbpsk_demod(generic_demod):
output is the complex modulated signal at baseband.
See generic_demod block for list of parameters.
+
+ 'mod_code' argument is not used.
+ It exists purely to simplify generation of the block in grc.
"""
- constellation_points = _def_constellation_points
- constellation = digital_swig.constellation_bpsk()
- if constellation_points != 2:
- raise ValueError('Number of constellation points must be 2 for DBPSK.')
- super(dbpsk_demod, self).__init__(constellation=constellation,
- differential=True,
+ super(dbpsk_demod, self).__init__(differential=True,
*args, **kwargs)
#
diff --git a/gr-digital/python/cpm.py b/gr-digital/python/cpm.py
index 05032336d4..f11832b626 100644
--- a/gr-digital/python/cpm.py
+++ b/gr-digital/python/cpm.py
@@ -131,7 +131,7 @@ class cpm_mod(gr.hier_block2):
# Turn it into symmetric PAM data.
- self.pam = gr.chunks_to_symbols_bf(self.sym_alphabet,1)
+ self.pam = digital_swig.chunks_to_symbols_bf(self.sym_alphabet,1)
# Generate pulse (sum of taps = samples_per_symbol/2)
if cpm_type == 0: # CPFSK
diff --git a/gr-digital/python/generic_mod_demod.py b/gr-digital/python/generic_mod_demod.py
index a6c4f3445a..105c6fe8ff 100644
--- a/gr-digital/python/generic_mod_demod.py
+++ b/gr-digital/python/generic_mod_demod.py
@@ -76,10 +76,10 @@ def add_common_options(parser):
class generic_mod(gr.hier_block2):
def __init__(self, constellation,
- samples_per_symbol=_def_samples_per_symbol,
differential=_def_differential,
+ samples_per_symbol=_def_samples_per_symbol,
+ pre_diff_code=True,
excess_bw=_def_excess_bw,
- gray_coded=True,
verbose=_def_verbose,
log=_def_log):
"""
@@ -92,10 +92,12 @@ class generic_mod(gr.hier_block2):
@type constellation: gnuradio.digital.gr_constellation
@param samples_per_symbol: samples per baud >= 2
@type samples_per_symbol: float
+ @param differential: whether to use differential encoding
+ @type differential: boolean
+ @param pre_diff_code: whether to use apply a pre-differential mapping
+ @type pre_diff_code: boolean
@param excess_bw: Root-raised cosine filter excess bandwidth
@type excess_bw: float
- @param gray_coded: turn gray coding on/off
- @type gray_coded: bool
@param verbose: Print information about modulator?
@type verbose: bool
@param log: Log modulation data to files?
@@ -110,6 +112,8 @@ class generic_mod(gr.hier_block2):
self._samples_per_symbol = samples_per_symbol
self._excess_bw = excess_bw
self._differential = differential
+ # Only apply a predifferential coding if the constellation also supports it.
+ self.pre_diff_code = pre_diff_code and self._constellation.apply_pre_diff_code()
if self._samples_per_symbol < 2:
raise TypeError, ("sbp must be >= 2, is %f" % self._samples_per_symbol)
@@ -120,7 +124,7 @@ class generic_mod(gr.hier_block2):
self.bytes2chunks = \
gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)
- if gray_coded == True:
+ if self.pre_diff_code:
self.symbol_mapper = digital.map_bb(self._constellation.pre_diff_code())
if differential:
@@ -142,7 +146,7 @@ class generic_mod(gr.hier_block2):
# Connect
blocks = [self, self.bytes2chunks]
- if gray_coded == True:
+ if self.pre_diff_code:
blocks.append(self.symbol_mapper)
if differential:
blocks.append(self.diffenc)
@@ -186,7 +190,7 @@ class generic_mod(gr.hier_block2):
print "Modulation logging turned on."
self.connect(self.bytes2chunks,
gr.file_sink(gr.sizeof_char, "tx_bytes2chunks.8b"))
- if self._constellation.apply_pre_diff_code():
+ if self.pre_diff_code:
self.connect(self.symbol_mapper,
gr.file_sink(gr.sizeof_char, "tx_symbol_mapper.8b"))
if self._differential:
@@ -208,10 +212,10 @@ class generic_mod(gr.hier_block2):
class generic_demod(gr.hier_block2):
def __init__(self, constellation,
- samples_per_symbol=_def_samples_per_symbol,
differential=_def_differential,
+ samples_per_symbol=_def_samples_per_symbol,
+ pre_diff_code=True,
excess_bw=_def_excess_bw,
- gray_coded=True,
freq_bw=_def_freq_bw,
timing_bw=_def_timing_bw,
phase_bw=_def_phase_bw,
@@ -227,10 +231,12 @@ class generic_demod(gr.hier_block2):
@type constellation: gnuradio.digital.gr_constellation
@param samples_per_symbol: samples per symbol >= 2
@type samples_per_symbol: float
+ @param differential: whether to use differential encoding
+ @type differential: boolean
+ @param pre_diff_code: whether to use apply a pre-differential mapping
+ @type pre_diff_code: boolean
@param excess_bw: Root-raised cosine filter excess bandwidth
@type excess_bw: float
- @param gray_coded: turn gray coding on/off
- @type gray_coded: bool
@param freq_bw: loop filter lock-in bandwidth
@type freq_bw: float
@param timing_bw: timing recovery loop lock-in bandwidth
@@ -259,6 +265,9 @@ class generic_demod(gr.hier_block2):
if self._samples_per_symbol < 2:
raise TypeError, ("sbp must be >= 2, is %d" % self._samples_per_symbol)
+ # Only apply a predifferential coding if the constellation also supports it.
+ self.pre_diff_code = pre_diff_code and self._constellation.apply_pre_diff_code()
+
arity = pow(2,self.bits_per_symbol())
nfilts = 32
@@ -289,7 +298,7 @@ class generic_demod(gr.hier_block2):
if differential:
self.diffdec = digital.diff_decoder_bb(arity)
- if gray_coded:
+ if self.pre_diff_code:
self.symbol_mapper = digital.map_bb(
mod_codes.invert_code(self._constellation.pre_diff_code()))
@@ -307,7 +316,7 @@ class generic_demod(gr.hier_block2):
self.time_recov, self.receiver]
if differential:
blocks.append(self.diffdec)
- if self._constellation.apply_pre_diff_code():
+ if self.pre_diff_code:
blocks.append(self.symbol_mapper)
blocks += [self.unpack, self]
self.connect(*blocks)
@@ -357,7 +366,7 @@ class generic_demod(gr.hier_block2):
if self._differential:
self.connect(self.diffdec,
gr.file_sink(gr.sizeof_char, "rx_diffdec.8b"))
- if self._constellation.apply_pre_diff_code():
+ if self.pre_diff_code:
self.connect(self.symbol_mapper,
gr.file_sink(gr.sizeof_char, "rx_symbol_mapper.8b"))
self.connect(self.unpack,
diff --git a/gr-digital/python/pkt.py b/gr-digital/python/pkt.py
index 8650bdbb02..09254a7caa 100644
--- a/gr-digital/python/pkt.py
+++ b/gr-digital/python/pkt.py
@@ -143,7 +143,7 @@ class demod_pkts(gr.hier_block2):
self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY
self.correlator = digital_swig.correlate_access_code_bb(access_code, threshold)
- self.framer_sink = gr.framer_sink_1(self._rcvd_pktq)
+ self.framer_sink = digital.framer_sink_1(self._rcvd_pktq)
self.connect(self, self._demodulator, self.correlator, self.framer_sink)
self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
diff --git a/gr-digital/python/psk.py b/gr-digital/python/psk.py
index 58f6787f0c..4b35447278 100644
--- a/gr-digital/python/psk.py
+++ b/gr-digital/python/psk.py
@@ -35,17 +35,23 @@ from generic_mod_demod import generic_mod, generic_demod
_def_constellation_points = 4
# The default encoding (e.g. gray-code, set-partition)
_def_mod_code = mod_codes.GRAY_CODE
+# Default use of differential encoding
+_def_differential = True
-def create_encodings(mod_code, arity):
+def create_encodings(mod_code, arity, differential):
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)
+ if differential:
+ pre_diff_code = gray_code.gray_code(arity)
+ post_diff_code = None
+ else:
+ pre_diff_code = []
+ post_diff_code = gray_code.gray_code(arity)
elif mod_code == mod_codes.NO_CODE:
pre_diff_code = []
+ post_diff_code = None
else:
raise ValueError('That modulation code is not implemented for this constellation.')
return (pre_diff_code, post_diff_code)
@@ -54,7 +60,8 @@ def create_encodings(mod_code, arity):
# PSK constellation
# /////////////////////////////////////////////////////////////////////////////
-def psk_constellation(m=_def_constellation_points, mod_code=_def_mod_code):
+def psk_constellation(m=_def_constellation_points, mod_code=_def_mod_code,
+ differential=_def_differential):
"""
Creates a PSK constellation object.
"""
@@ -62,7 +69,7 @@ def psk_constellation(m=_def_constellation_points, mod_code=_def_mod_code):
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)]
- pre_diff_code, post_diff_code = create_encodings(mod_code, m)
+ pre_diff_code, post_diff_code = create_encodings(mod_code, m, differential)
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]
@@ -77,6 +84,7 @@ class psk_mod(generic_mod):
def __init__(self, constellation_points=_def_constellation_points,
mod_code=_def_mod_code,
+ differential=_def_differential,
*args, **kwargs):
"""
@@ -88,8 +96,8 @@ class psk_mod(generic_mod):
See generic_mod block for list of parameters.
"""
- constellation = psk_constellation(constellation_points, mod_code)
- super(psk_mod, self).__init__(constellation, *args, **kwargs)
+ constellation = psk_constellation(constellation_points, mod_code, differential)
+ super(psk_mod, self).__init__(constellation, differential, *args, **kwargs)
# /////////////////////////////////////////////////////////////////////////////
# PSK demodulator
@@ -100,6 +108,7 @@ class psk_demod(generic_demod):
def __init__(self, constellation_points=_def_constellation_points,
mod_code=_def_mod_code,
+ differential=_def_differential,
*args, **kwargs):
"""
@@ -111,8 +120,8 @@ class psk_demod(generic_demod):
See generic_demod block for list of parameters.
"""
- constellation = psk_constellation(constellation_points, mod_code)
- super(psk_demod, self).__init__(constellation, *args, **kwargs)
+ constellation = psk_constellation(constellation_points, mod_code, differential)
+ super(psk_demod, self).__init__(constellation, differential, *args, **kwargs)
#
# Add these to the mod/demod registry
diff --git a/gr-digital/python/qa_constellation.py b/gr-digital/python/qa_constellation.py
index b17d2a0fcb..e0b5b3888e 100755
--- a/gr-digital/python/qa_constellation.py
+++ b/gr-digital/python/qa_constellation.py
@@ -67,8 +67,24 @@ def threed_constell():
tested_constellation_info = (
(psk.psk_constellation,
{'m': (2, 4, 8, 16, 32, 64),
- 'mod_code': tested_mod_codes, },
+ 'mod_code': tested_mod_codes,
+ 'differential': (True,)},
True, None),
+ (psk.psk_constellation,
+ {'m': (2, 4, 8, 16, 32, 64),
+ 'mod_code': tested_mod_codes,
+ 'differential': (False,)},
+ False, None),
+ (qam.qam_constellation,
+ {'constellation_points': (4, 16, 64),
+ 'mod_code': tested_mod_codes,
+ 'differential': (True,)},
+ True, None),
+ (qam.qam_constellation,
+ {'constellation_points': (4, 16, 64),
+ 'mod_code': tested_mod_codes,
+ 'differential': (False,)},
+ False, None),
(digital_swig.constellation_bpsk, {}, True, None),
(digital_swig.constellation_qpsk, {}, False, None),
(digital_swig.constellation_dqpsk, {}, True, None),
@@ -167,13 +183,13 @@ class mod_demod(gr.hier_block2):
# Apply any pre-differential coding
# Gray-coding is done here if we're also using differential coding.
if self.constellation.apply_pre_diff_code():
- self.blocks.append(gr.map_bb(self.constellation.pre_diff_code()))
+ self.blocks.append(digital_swig.map_bb(self.constellation.pre_diff_code()))
# Differential encoding.
if self.differential:
- self.blocks.append(gr.diff_encoder_bb(arity))
+ self.blocks.append(digital_swig.diff_encoder_bb(arity))
# Convert to constellation symbols.
- self.blocks.append(gr.chunks_to_symbols_bc(self.constellation.points(),
- self.constellation.dimensionality()))
+ self.blocks.append(digital_swig.chunks_to_symbols_bc(self.constellation.points(),
+ self.constellation.dimensionality()))
# CHANNEL
# Channel just consists of a rotation to check differential coding.
if rotation is not None:
@@ -184,10 +200,10 @@ class mod_demod(gr.hier_block2):
self.blocks.append(digital_swig.constellation_decoder_cb(self.constellation.base()))
# Differential decoding.
if self.differential:
- self.blocks.append(gr.diff_decoder_bb(arity))
+ self.blocks.append(digital_swig.diff_decoder_bb(arity))
# Decode any pre-differential coding.
if self.constellation.apply_pre_diff_code():
- self.blocks.append(gr.map_bb(
+ self.blocks.append(digital_swig.map_bb(
mod_codes.invert_code(self.constellation.pre_diff_code())))
# unpack the k bit vector into a stream of bits
self.blocks.append(gr.unpack_k_bits_bb(
diff --git a/gr-digital/python/qa_constellation_receiver.py b/gr-digital/python/qa_constellation_receiver.py
index 2d25433b92..8c2d2da0c5 100755
--- a/gr-digital/python/qa_constellation_receiver.py
+++ b/gr-digital/python/qa_constellation_receiver.py
@@ -85,11 +85,16 @@ class test_constellation_receiver (gr_unittest.TestCase):
# That is not implemented since the receiver has no way of
# knowing where the beginning of a symbol is.
# It also doesn't work for non-differential modulation.
- if constellation.dimensionality() != 1 or not differential:
+ if constellation.dimensionality() != 1:
continue
data_length = DATA_LENGTH * constellation.bits_per_symbol()
+ if differential:
+ freq_offset=True
+ else:
+ freq_offset=False
tb = rec_test_tb(constellation, differential,
- src_data=self.src_data[:data_length])
+ src_data=self.src_data[:data_length],
+ freq_offset=freq_offset)
tb.run()
data = tb.dst.data()
d1 = tb.src_data[:int(len(tb.src_data)*self.ignore_fraction)]
@@ -105,12 +110,14 @@ class rec_test_tb (gr.top_block):
and generic demodulation.
"""
def __init__(self, constellation, differential,
- data_length=None, src_data=None):
+ data_length=None, src_data=None, freq_offset=True):
"""
- constellation -- a constellation object
- differential -- whether differential encoding is used
- data_length -- the number of bits of data to use
- src_data -- a list of the bits to use
+ Args:
+ constellation: a constellation object
+ differential: whether differential encoding is used
+ data_length: the number of bits of data to use
+ src_data: a list of the bits to use
+ freq_offset: whether to use a frequency offset in the channel
"""
super(rec_test_tb, self).__init__()
# Transmission Blocks
@@ -122,11 +129,18 @@ class rec_test_tb (gr.top_block):
src = gr.vector_source_b(self.src_data)
mod = generic_mod(constellation, differential=differential)
# Channel
- channel = gr.channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET)
+ if freq_offset:
+ channel = gr.channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET)
+ else:
+ channel = gr.channel_model(NOISE_VOLTAGE, 0, TIMING_OFFSET)
# Receiver Blocks
- demod = generic_demod(constellation, differential=differential,
- freq_bw=FREQ_BW,
- phase_bw=PHASE_BW)
+ if freq_offset:
+ demod = generic_demod(constellation, differential=differential,
+ freq_bw=FREQ_BW,
+ phase_bw=PHASE_BW)
+ else:
+ demod = generic_demod(constellation, differential=differential,
+ freq_bw=0, phase_bw=0)
self.dst = gr.vector_sink_b()
self.connect(src, packer, mod, channel, demod, self.dst)
diff --git a/gr-digital/python/qa_glfsr_source.py b/gr-digital/python/qa_glfsr_source.py
index 157520d7f8..7d02037335 100755
--- a/gr-digital/python/qa_glfsr_source.py
+++ b/gr-digital/python/qa_glfsr_source.py
@@ -38,9 +38,9 @@ class test_glfsr_source(gr_unittest.TestCase):
def test_001_degree_b(self):
self.assertRaises(RuntimeError,
- lambda: gr.glfsr_source_b(0))
+ lambda: digital.glfsr_source_b(0))
self.assertRaises(RuntimeError,
- lambda: gr.glfsr_source_b(33))
+ lambda: digital.glfsr_source_b(33))
def test_002_correlation_b(self):
for degree in range(1,11): # Higher degrees take too long to correlate
@@ -65,9 +65,9 @@ class test_glfsr_source(gr_unittest.TestCase):
def test_004_degree_f(self):
self.assertRaises(RuntimeError,
- lambda: gr.glfsr_source_f(0))
+ lambda: digital.glfsr_source_f(0))
self.assertRaises(RuntimeError,
- lambda: gr.glfsr_source_f(33))
+ lambda: digital.glfsr_source_f(33))
def test_005_correlation_f(self):
for degree in range(1,11): # Higher degrees take too long to correlate
src = digital.glfsr_source_f(degree, False)
diff --git a/gr-digital/python/qam.py b/gr-digital/python/qam.py
index 5b1f7683b8..0635fda75e 100644
--- a/gr-digital/python/qam.py
+++ b/gr-digital/python/qam.py
@@ -157,14 +157,20 @@ def qam_constellation(constellation_points=_def_constellation_points,
else:
raise ValueError("Mod code is not implemented for QAM")
if differential:
- points = make_differential_constellation(constellation_points, gray_coded)
+ points = make_differential_constellation(constellation_points, gray_coded=False)
else:
points = make_non_differential_constellation(constellation_points, gray_coded)
side = int(sqrt(constellation_points))
width = 2.0/(side-1)
- # No pre-diff code
- # Should add one so that we can gray-code the quadrant bits too.
- pre_diff_code = []
+ # For differential and gray-coded then gray-code the first two
+ # bits with a pre_diff_code.
+ # FIXME: It would be good to have a test to make sure that gray-coded constellations
+ # are really gray-coded. Perhaps by checking on the correlation between bit-errors.
+ if differential and gray_coded:
+ m = constellation_points
+ pre_diff_code = range(0, m/2) + range(3*m/4, m) + range(m/2, 3*m/4)
+ else:
+ pre_diff_code = []
constellation = digital_swig.constellation_rect(points, pre_diff_code, 4,
side, side, width, width)
return constellation
diff --git a/gr-digital/python/qpsk.py b/gr-digital/python/qpsk.py
index be21fd76f1..2fdeabd40f 100644
--- a/gr-digital/python/qpsk.py
+++ b/gr-digital/python/qpsk.py
@@ -27,21 +27,20 @@ Demodulation is not included since the generic_mod_demod
from gnuradio import gr
from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod
+from utils import mod_codes
import digital_swig
import modulation_utils
-# Default number of points in constellation.
-_def_constellation_points = 4
-# Whether gray coding is used.
-_def_gray_coded = True
+# The default encoding (e.g. gray-code, set-partition)
+_def_mod_code = mod_codes.GRAY_CODE
# /////////////////////////////////////////////////////////////////////////////
# QPSK constellation
# /////////////////////////////////////////////////////////////////////////////
-def qpsk_constellation(m=_def_constellation_points):
- if m != _def_constellation_points:
- raise ValueError("QPSK can only have 4 constellation points.")
+def qpsk_constellation(mod_code=_def_mod_code):
+ if mod_code != mod_codes.GRAY_CODE:
+ raise ValueError("This QPSK mod/demod works only for gray-coded constellations.")
return digital_swig.constellation_qpsk()
# /////////////////////////////////////////////////////////////////////////////
@@ -50,9 +49,7 @@ def qpsk_constellation(m=_def_constellation_points):
class qpsk_mod(generic_mod):
- def __init__(self, constellation_points=_def_constellation_points,
- gray_coded=_def_gray_coded,
- *args, **kwargs):
+ def __init__(self, mod_code=_def_mod_code, differential=False, *args, **kwargs):
"""
Hierarchical block for RRC-filtered QPSK modulation.
@@ -62,15 +59,21 @@ class qpsk_mod(generic_mod):
See generic_mod block for list of parameters.
"""
-
- constellation_points = _def_constellation_points
- constellation = digital_swig.constellation_qpsk()
- if constellation_points != 4:
- raise ValueError("QPSK can only have 4 constellation points.")
- if not gray_coded:
- raise ValueError("This QPSK mod/demod works only for gray-coded constellations.")
+
+ pre_diff_code = True
+ if not differential:
+ constellation = digital_swig.constellation_qpsk()
+ if mod_code != mod_codes.GRAY_CODE:
+ raise ValueError("This QPSK mod/demod works only for gray-coded constellations.")
+ else:
+ constellation = digital_swig.constellation_dqpsk()
+ if mod_code not in (mod_codes.GRAY_CODE or mod_codes.NO_CODE):
+ raise ValueError("That mod_code is not supported for DQPSK mod/demod.")
+ if mod_code == mod_codes.NO_CODE:
+ pre_diff_code = False
+
super(qpsk_mod, self).__init__(constellation=constellation,
- gray_coded=gray_coded,
+ pre_diff_code=pre_diff_code,
*args, **kwargs)
@@ -81,7 +84,7 @@ class qpsk_mod(generic_mod):
class qpsk_demod(generic_demod):
- def __init__(self, constellation_points=_def_constellation_points,
+ def __init__(self, mod_code=_def_mod_code, differential=False,
*args, **kwargs):
"""
@@ -93,11 +96,20 @@ class qpsk_demod(generic_demod):
See generic_demod block for list of parameters.
"""
- constellation_points = _def_constellation_points
- constellation = digital_swig.constellation_qpsk()
- if constellation_points != 4:
- raise ValueError('Number of constellation points must be 4 for QPSK.')
+ pre_diff_code = True
+ if not differential:
+ constellation = digital_swig.constellation_qpsk()
+ if mod_code != mod_codes.GRAY_CODE:
+ raise ValueError("This QPSK mod/demod works only for gray-coded constellations.")
+ else:
+ constellation = digital_swig.constellation_dqpsk()
+ if mod_code not in (mod_codes.GRAY_CODE or mod_codes.NO_CODE):
+ raise ValueError("That mod_code is not supported for DQPSK mod/demod.")
+ if mod_code == mod_codes.NO_CODE:
+ pre_diff_code = False
+
super(qpsk_demod, self).__init__(constellation=constellation,
+ pre_diff_code=pre_diff_code,
*args, **kwargs)
@@ -106,20 +118,18 @@ class qpsk_demod(generic_demod):
# DQPSK constellation
# /////////////////////////////////////////////////////////////////////////////
-def dqpsk_constellation(m=_def_constellation_points):
- if m != _def_constellation_points:
- raise ValueError("DQPSK can only have 4 constellation points.")
+def dqpsk_constellation(mod_code=_def_mod_code):
+ if mod_code != mod_codes.GRAY_CODE:
+ raise ValueError("The DQPSK constellation is only generated for gray_coding. But it can be used for non-grayed coded modulation if one doesn't use the pre-differential code.")
return digital_swig.constellation_dqpsk()
# /////////////////////////////////////////////////////////////////////////////
# DQPSK modulator
# /////////////////////////////////////////////////////////////////////////////
-class dqpsk_mod(generic_mod):
+class dqpsk_mod(qpsk_mod):
- def __init__(self, constellation_points=_def_constellation_points,
- gray_coded=_def_gray_coded,
- differential=True, *args, **kwargs):
+ def __init__(self, mod_code=_def_mod_code, *args, **kwargs):
"""
Hierarchical block for RRC-filtered DQPSK modulation.
@@ -128,14 +138,7 @@ class dqpsk_mod(generic_mod):
See generic_mod block for list of parameters.
"""
-
- constellation_points = _def_constellation_points
- constellation = digital_swig.constellation_dqpsk()
- if constellation_points != 4:
- raise ValueError('Number of constellation points must be 4 for DQPSK.')
- super(dqpsk_mod, self).__init__(constellation=constellation,
- gray_coded=gray_coded,
- differential=True,
+ super(dqpsk_mod, self).__init__(mod_code, differential=True,
*args, **kwargs)
# /////////////////////////////////////////////////////////////////////////////
@@ -143,10 +146,9 @@ class dqpsk_mod(generic_mod):
#
# /////////////////////////////////////////////////////////////////////////////
-class dqpsk_demod(generic_demod):
+class dqpsk_demod(qpsk_demod):
- def __init__(self, constellation_points=_def_constellation_points,
- differential=True, *args, **kwargs):
+ def __init__(self, mod_code=_def_mod_code, *args, **kwargs):
"""
Hierarchical block for RRC-filtered DQPSK modulation.
@@ -156,12 +158,7 @@ class dqpsk_demod(generic_demod):
See generic_demod block for list of parameters.
"""
- constellation_points = _def_constellation_points
- constellation = digital_swig.constellation_dqpsk()
- if constellation_points != 4:
- raise ValueError('Number of constellation points must be 4 for DQPSK.')
- super(dqpsk_demod, self).__init__(constellation=constellation,
- differential=True,
+ super(dqpsk_demod, self).__init__(mod_code, differential=True,
*args, **kwargs)
#