Skip to content

Commit dc25537

Browse files
authored
Merge pull request #15 from rtucker/master
Python 3 and modulation.py fixes
2 parents 9e91c12 + b1db413 commit dc25537

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

commpy/channelcoding/turbo.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ def _backward_recursion(trellis, msg_length, noise_variance,
8787
output_table = trellis.output_table
8888

8989
# Backward recursion
90-
for reverse_time_index in reversed(xrange(1, msg_length+1)):
90+
for reverse_time_index in reversed(range(1, msg_length+1)):
9191

92-
for current_state in xrange(number_states):
93-
for current_input in xrange(number_inputs):
92+
for current_state in range(number_states):
93+
for current_input in range(number_inputs):
9494
next_state = next_state_table[current_state, current_input]
9595
code_symbol = output_table[current_state, current_input]
9696
codeword_array = dec2bitarray(code_symbol, n)
@@ -124,11 +124,11 @@ def _forward_recursion_decoding(trellis, mode, msg_length, noise_variance,
124124
output_table = trellis.output_table
125125

126126
# Forward Recursion
127-
for time_index in xrange(1, msg_length+1):
127+
for time_index in range(1, msg_length+1):
128128

129129
app[:] = 0
130-
for current_state in xrange(number_states):
131-
for current_input in xrange(number_inputs):
130+
for current_state in range(number_states):
131+
for current_input in range(number_inputs):
132132
next_state = next_state_table[current_state, current_input]
133133
branch_prob = branch_probs[current_input, current_state, time_index-1]
134134
# Compute the forward state metrics
@@ -308,7 +308,7 @@ def turbo_decode(sys_symbols, non_sys_symbols_1, non_sys_symbols_2, trellis,
308308
# Interleave systematic symbols for input to second decoder
309309
sys_symbols_i = interleaver.interlv(sys_symbols)
310310

311-
for iteration_count in xrange(number_iterations):
311+
for iteration_count in range(number_iterations):
312312

313313
# MAP Decoder - 1
314314
[L_ext_1, decoded_bits] = map_decode(sys_symbols, non_sys_symbols_1,

commpy/channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def awgn(input_signal, snr_dB, rate=1.0):
162162
# g_var = 0.5
163163
# gain_process = zeros([len(path_gains), block_length], dtype=complex)
164164
# delay_process = zeros([n2+1-n1, len(path_delays)])
165-
# for k in xrange(len(path_gains)):
165+
# for k in range(len(path_gains)):
166166
# g = (g_var**0.5) * (randn(channel_length) + 1j*randn(channel_length))
167167
# g_filt = convolve(g, h_jakes, mode='same')
168168
# g_filt_interp = resample(g_filt, block_length)

commpy/modulation.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
1717
"""
1818
from numpy import arange, array, zeros, pi, cos, sin, sqrt, log2, argmin, \
19-
hstack, repeat, tile, dot, sum, shape, concatenate, exp, log
19+
hstack, repeat, tile, dot, sum, shape, concatenate, exp, \
20+
log, vectorize
2021
from itertools import product
2122
from commpy.utilities import bitarray2dec, dec2bitarray
2223
from numpy.fft import fft, ifft
@@ -39,10 +40,10 @@ def modulate(self, input_bits):
3940
Modulated complex symbols.
4041
4142
"""
43+
mapfunc = vectorize(lambda i:
44+
self.constellation[bitarray2dec(input_bits[i:i+self.num_bits_symbol])])
4245

43-
index_list = map(lambda i: bitarray2dec(input_bits[i:i+self.num_bits_symbol]), \
44-
xrange(0, len(input_bits), self.num_bits_symbol))
45-
baseband_symbols = self.constellation[index_list]
46+
baseband_symbols = mapfunc(arange(0, len(input_bits), self.num_bits_symbol))
4647

4748
return baseband_symbols
4849

@@ -71,7 +72,7 @@ def demodulate(self, input_symbols, demod_type, noise_var = 0):
7172
"""
7273
if demod_type == 'hard':
7374
index_list = map(lambda i: argmin(abs(input_symbols[i] - self.constellation)), \
74-
xrange(0, len(input_symbols)))
75+
range(0, len(input_symbols)))
7576
demod_bits = hstack(map(lambda i: dec2bitarray(i, self.num_bits_symbol),
7677
index_list))
7778
elif demod_type == 'soft':
@@ -112,7 +113,7 @@ def __init__(self, m):
112113
self.m = m
113114
self.num_bits_symbol = int(log2(self.m))
114115
self.symbol_mapping = arange(self.m)
115-
self.constellation = array(map(self._constellation_symbol,
116+
self.constellation = list(map(self._constellation_symbol,
116117
self.symbol_mapping))
117118

118119
class QAMModem(Modem):
@@ -135,7 +136,7 @@ def __init__(self, m):
135136
self.num_bits_symbol = int(log2(self.m))
136137
self.symbol_mapping = arange(self.m)
137138
mapping_array = arange(1, sqrt(self.m)+1) - (sqrt(self.m)/2)
138-
self.constellation = array(map(self._constellation_symbol,
139+
self.constellation = list(map(self._constellation_symbol,
139140
list(product(mapping_array, repeat=2))))
140141

141142
def ofdm_tx(x, nfft, nsc, cp_length):
@@ -146,7 +147,7 @@ def ofdm_tx(x, nfft, nsc, cp_length):
146147
cp_length = float(cp_length)
147148
ofdm_tx_signal = array([])
148149

149-
for i in xrange(0, shape(x)[1]):
150+
for i in range(0, shape(x)[1]):
150151
symbols = x[:,i]
151152
ofdm_sym_freq = zeros(nfft, dtype=complex)
152153
ofdm_sym_freq[1:(nsc/2)+1] = symbols[nsc/2:]
@@ -163,7 +164,7 @@ def ofdm_rx(y, nfft, nsc, cp_length):
163164
num_ofdm_symbols = int(len(y)/(nfft + cp_length))
164165
x_hat = zeros([nsc, num_ofdm_symbols], dtype=complex)
165166

166-
for i in xrange(0, num_ofdm_symbols):
167+
for i in range(0, num_ofdm_symbols):
167168
ofdm_symbol = y[i*nfft + (i+1)*cp_length:(i+1)*(nfft + cp_length)]
168169
symbols_freq = fft(ofdm_symbol)
169170
x_hat[:,i] = concatenate((symbols_freq[-nsc/2:], symbols_freq[1:(nsc/2)+1]))

commpy/sequences.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def pnsequence(pn_order, pn_seed, pn_mask, seq_length):
4949
pnseq = zeros(seq_length)
5050

5151
# Initialize shift register with the pn_seed
52-
sr = array(map(lambda i: int(pn_seed[i]), xrange(0, len(pn_seed))))
52+
sr = array(map(lambda i: int(pn_seed[i]), range(0, len(pn_seed))))
5353

54-
for i in xrange(seq_length):
54+
for i in range(seq_length):
5555
new_bit = 0
56-
for j in xrange(pn_order):
56+
for j in range(pn_order):
5757
if int(pn_mask[j]) == 1:
5858
new_bit = new_bit ^ sr[j]
5959
pnseq[i] = sr[pn_order-1]

doc/sphinxext/plot_directive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def makefig(code, code_path, output_dir, output_base, config):
520520
all_exists = True
521521
for i, code_piece in enumerate(code_pieces):
522522
images = []
523-
for j in xrange(1000):
523+
for j in range(1000):
524524
img = ImageFile('%s_%02d_%02d' % (output_base, i, j), output_dir)
525525
for format, dpi in formats:
526526
if out_of_date(code_path, img.filename(format)):

0 commit comments

Comments
 (0)