summaryrefslogtreecommitdiff
path: root/gr-digital/python/digital/generic_mod_demod.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-digital/python/digital/generic_mod_demod.py')
-rw-r--r--gr-digital/python/digital/generic_mod_demod.py66
1 files changed, 38 insertions, 28 deletions
diff --git a/gr-digital/python/digital/generic_mod_demod.py b/gr-digital/python/digital/generic_mod_demod.py
index a40a7fda5f..2db9e4482a 100644
--- a/gr-digital/python/digital/generic_mod_demod.py
+++ b/gr-digital/python/digital/generic_mod_demod.py
@@ -29,17 +29,18 @@ _def_log = False
_def_truncate = False
# Frequency correction
-_def_freq_bw = 2*math.pi/100.0
+_def_freq_bw = 2 * math.pi / 100.0
# Symbol timing recovery
-_def_timing_bw = 2*math.pi/100.0
+_def_timing_bw = 2 * math.pi / 100.0
_def_timing_max_dev = 1.5
# Fine frequency / Phase correction
-_def_phase_bw = 2*math.pi/100.0
+_def_phase_bw = 2 * math.pi / 100.0
# Number of points in constellation
_def_constellation_points = 16
# Whether differential coding is used.
_def_differential = False
+
def add_common_options(parser):
"""
Sets options common to both modulator and demodulator.
@@ -55,7 +56,7 @@ def add_common_options(parser):
parser.add_option("", "--mod-code", type="choice", choices=mod_codes.codes,
default=mod_codes.NO_CODE,
help="Select modulation code from: %s [default=%%default]"
- % (', '.join(mod_codes.codes),))
+ % (', '.join(mod_codes.codes),))
parser.add_option("", "--excess-bw", type="float", default=_def_excess_bw,
help="set RRC excess bandwidth factor [default=%default]")
@@ -92,8 +93,9 @@ class generic_mod(gr.hier_block2):
truncate=_def_truncate):
gr.hier_block2.__init__(self, "generic_mod",
- gr.io_signature(1, 1, gr.sizeof_char), # Input signature
- gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+ # Input signature
+ gr.io_signature(1, 1, gr.sizeof_char),
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
self._constellation = constellation
self._samples_per_symbol = samples_per_symbol
@@ -103,31 +105,36 @@ class generic_mod(gr.hier_block2):
self.pre_diff_code = pre_diff_code and self._constellation.apply_pre_diff_code()
if self._samples_per_symbol < 2:
- raise TypeError("sps must be >= 2, is %f" % self._samples_per_symbol)
+ raise TypeError("sps must be >= 2, is %f" %
+ self._samples_per_symbol)
- arity = pow(2,self.bits_per_symbol())
+ arity = pow(2, self.bits_per_symbol())
# turn bytes into k-bit vectors
self.bytes2chunks = \
- blocks.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)
+ blocks.packed_to_unpacked_bb(
+ self.bits_per_symbol(), gr.GR_MSB_FIRST)
if self.pre_diff_code:
- self.symbol_mapper = digital.map_bb(self._constellation.pre_diff_code())
+ self.symbol_mapper = digital.map_bb(
+ self._constellation.pre_diff_code())
if differential:
self.diffenc = digital.diff_encoder_bb(arity)
- self.chunks2symbols = digital.chunks_to_symbols_bc(self._constellation.points())
+ self.chunks2symbols = digital.chunks_to_symbols_bc(
+ self._constellation.points())
# pulse shaping filter
nfilts = 32
ntaps_per_filt = 11
- ntaps = nfilts * ntaps_per_filt * int(self._samples_per_symbol) # make nfilts filters of ntaps each
+ # make nfilts filters of ntaps each
+ ntaps = nfilts * ntaps_per_filt * int(self._samples_per_symbol)
self.rrc_taps = filter.firdes.root_raised_cosine(
nfilts, # gain
nfilts, # sampling rate based on 32 filters in resampler
1.0, # symbol rate
- self._excess_bw, # excess bandwidth (roll-off factor)
+ self._excess_bw, # excess bandwidth (roll-off factor)
ntaps)
self.rrc_filter = filter.pfb_arb_resampler_ccf(self._samples_per_symbol,
self.rrc_taps)
@@ -135,8 +142,10 @@ class generic_mod(gr.hier_block2):
# Remove the filter transient at the beginning of the transmission
if truncate:
fsps = float(self._samples_per_symbol)
- len_filt_delay = int((ntaps_per_filt*fsps*fsps-fsps)/2.0) # Length of delay through rrc filter
- self.skiphead = blocks.skiphead(gr.sizeof_gr_complex*1, len_filt_delay)
+ # Length of delay through rrc filter
+ len_filt_delay = int((ntaps_per_filt * fsps * fsps - fsps) / 2.0)
+ self.skiphead = blocks.skiphead(
+ gr.sizeof_gr_complex * 1, len_filt_delay)
# Connect
self._blocks = [self, self.bytes2chunks]
@@ -145,7 +154,7 @@ class generic_mod(gr.hier_block2):
if differential:
self._blocks.append(self.diffenc)
self._blocks += [self.chunks2symbols, self.rrc_filter]
-
+
if truncate:
self._blocks.append(self.skiphead)
self._blocks.append(self)
@@ -157,7 +166,6 @@ class generic_mod(gr.hier_block2):
if log:
self._setup_logging()
-
def samples_per_symbol(self):
return self._samples_per_symbol
@@ -176,8 +184,7 @@ class generic_mod(gr.hier_block2):
Given command line options, create dictionary suitable for passing to __init__
"""
return extract_kwargs_from_options_for_class(cls, options)
- extract_kwargs_from_options=classmethod(extract_kwargs_from_options)
-
+ extract_kwargs_from_options = classmethod(extract_kwargs_from_options)
def _print_verbage(self):
print("\nModulator:")
@@ -239,7 +246,8 @@ class generic_demod(gr.hier_block2):
log=_def_log):
gr.hier_block2.__init__(self, "generic_demod",
- gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+ # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex),
gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
self._constellation = constellation
@@ -248,19 +256,20 @@ class generic_demod(gr.hier_block2):
self._phase_bw = phase_bw
self._freq_bw = freq_bw
self._timing_bw = timing_bw
- self._timing_max_dev= _def_timing_max_dev
+ self._timing_max_dev = _def_timing_max_dev
self._differential = differential
if self._samples_per_symbol < 2:
- raise TypeError("sps must be >= 2, is %d" % self._samples_per_symbol)
+ raise TypeError("sps 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())
+ arity = pow(2, self.bits_per_symbol())
nfilts = 32
- ntaps = 11 * int(self._samples_per_symbol*nfilts)
+ ntaps = 11 * int(self._samples_per_symbol * nfilts)
# Automatic gain control
self.agc = analog.agc2_cc(0.6e-1, 1e-3, 1, 1)
@@ -271,11 +280,11 @@ class generic_demod(gr.hier_block2):
fll_ntaps, self._freq_bw)
# symbol timing recovery with RRC data filter
- taps = filter.firdes.root_raised_cosine(nfilts, nfilts*self._samples_per_symbol,
+ taps = filter.firdes.root_raised_cosine(nfilts, nfilts * self._samples_per_symbol,
1.0, self._excess_bw, ntaps)
self.time_recov = digital.pfb_clock_sync_ccf(self._samples_per_symbol,
self._timing_bw, taps,
- nfilts, nfilts//2, self._timing_max_dev)
+ nfilts, nfilts // 2, self._timing_max_dev)
fmin = -0.25
fmax = 0.25
@@ -318,7 +327,7 @@ class generic_demod(gr.hier_block2):
def _print_verbage(self):
print("\nDemodulator:")
- print("bits per symbol: %d" % self.bits_per_symbol())
+ print("bits per symbol: %d" % self.bits_per_symbol())
print("RRC roll-off factor: %.2f" % self._excess_bw)
print("FLL bandwidth: %.2e" % self._freq_bw)
print("Timing bandwidth: %.2e" % self._timing_bw)
@@ -381,7 +390,8 @@ class generic_demod(gr.hier_block2):
Given command line options, create dictionary suitable for passing to __init__
"""
return extract_kwargs_from_options_for_class(cls, options)
- extract_kwargs_from_options=classmethod(extract_kwargs_from_options)
+ extract_kwargs_from_options = classmethod(extract_kwargs_from_options)
+
shared_demod_args = """ samples_per_symbol: samples per baud >= 2 (float)
excess_bw: Root-raised cosine filter excess bandwidth (float)