@@ -105,7 +105,7 @@ def __init__(self, memory, g_matrix, feedback = 0, code_type = 'default'):
105
105
[self .k , self .n ] = g_matrix .shape
106
106
107
107
if code_type == 'rsc' :
108
- for i in xrange (self .k ):
108
+ for i in range (self .k ):
109
109
g_matrix [i ][i ] = feedback
110
110
111
111
self .total_memory = memory .sum ()
@@ -117,19 +117,19 @@ def __init__(self, memory, g_matrix, feedback = 0, code_type = 'default'):
117
117
self .number_inputs ], 'int' )
118
118
119
119
# Compute the entries in the next state table and the output table
120
- for current_state in xrange (self .number_states ):
120
+ for current_state in range (self .number_states ):
121
121
122
- for current_input in xrange (self .number_inputs ):
122
+ for current_input in range (self .number_inputs ):
123
123
outbits = np .zeros (self .n , 'int' )
124
124
125
125
# Compute the values in the output_table
126
- for r in xrange (self .n ):
126
+ for r in range (self .n ):
127
127
128
128
output_generator_array = np .zeros (self .k , 'int' )
129
129
shift_register = dec2bitarray (current_state ,
130
130
self .total_memory )
131
131
132
- for l in xrange (self .k ):
132
+ for l in range (self .k ):
133
133
134
134
# Convert the number representing a polynomial into a
135
135
# bit array
@@ -138,7 +138,7 @@ def __init__(self, memory, g_matrix, feedback = 0, code_type = 'default'):
138
138
139
139
# Loop over M delay elements of the shift register
140
140
# to compute their contribution to the r-th output
141
- for i in xrange (memory [l ]):
141
+ for i in range (memory [l ]):
142
142
outbits [r ] = (outbits [r ] + \
143
143
(shift_register [i + l ]* generator_array [i + 1 ])) % 2
144
144
@@ -184,7 +184,7 @@ def _generate_states(self, trellis_length, grid, state_order, state_radius, font
184
184
""" Private method """
185
185
state_patches = []
186
186
187
- for state_count in xrange (self .number_states * trellis_length ):
187
+ for state_count in range (self .number_states * trellis_length ):
188
188
state_patch = mpatches .Circle (grid [:,state_count ], state_radius ,
189
189
color = "#003399" , ec = "#cccccc" )
190
190
state_patches .append (state_patch )
@@ -198,11 +198,11 @@ def _generate_edges(self, trellis_length, grid, state_order, state_radius, edge_
198
198
""" Private method """
199
199
edge_patches = []
200
200
201
- for current_time_index in xrange (trellis_length - 1 ):
201
+ for current_time_index in range (trellis_length - 1 ):
202
202
grid_subset = grid [:,self .number_states * current_time_index :]
203
- for state_count_1 in xrange (self .number_states ):
203
+ for state_count_1 in range (self .number_states ):
204
204
input_count = 0
205
- for state_count_2 in xrange (self .number_states ):
205
+ for state_count_2 in range (self .number_states ):
206
206
dx = grid_subset [0 , state_count_2 + self .number_states ] - grid_subset [0 ,state_count_1 ] - 2 * state_radius
207
207
dy = grid_subset [1 , state_count_2 + self .number_states ] - grid_subset [1 ,state_count_1 ]
208
208
if np .count_nonzero (self .next_state_table [state_order [state_count_1 ],:] == state_order [state_count_2 ]):
@@ -219,8 +219,8 @@ def _generate_edges(self, trellis_length, grid, state_order, state_radius, edge_
219
219
def _generate_labels (self , grid , state_order , state_radius , font ):
220
220
""" Private method """
221
221
222
- for state_count in xrange (self .number_states ):
223
- for input_count in xrange (self .number_inputs ):
222
+ for state_count in range (self .number_states ):
223
+ for input_count in range (self .number_inputs ):
224
224
edge_label = str (input_count ) + "/" + str (
225
225
self .output_table [state_order [state_count ], input_count ])
226
226
plt .text (grid [0 , state_count ]- 1.5 * state_radius ,
@@ -333,16 +333,16 @@ def conv_encode(message_bits, trellis, code_type = 'default', puncture_matrix=No
333
333
number_outbits = int ((number_inbits + total_memory )/ rate )
334
334
335
335
outbits = np .zeros (number_outbits , 'int' )
336
- p_outbits = np .zeros (number_outbits *
337
- puncture_matrix [0 :].sum ()/ np .size (puncture_matrix , 1 ), 'int' )
336
+ p_outbits = np .zeros (int ( number_outbits *
337
+ puncture_matrix [0 :].sum ()/ np .size (puncture_matrix , 1 )) , 'int' )
338
338
next_state_table = trellis .next_state_table
339
339
output_table = trellis .output_table
340
340
341
341
# Encoding process - Each iteration of the loop represents one clock cycle
342
342
current_state = 0
343
343
j = 0
344
344
345
- for i in xrange ( number_inbits / k ): # Loop through all input bits
345
+ for i in range ( int ( number_inbits / k ) ): # Loop through all input bits
346
346
current_input = bitarray2dec (inbits [i * k :(i + 1 )* k ])
347
347
current_output = output_table [current_state ][current_input ]
348
348
outbits [j * n :(j + 1 )* n ] = dec2bitarray (current_output , n )
@@ -353,15 +353,15 @@ def conv_encode(message_bits, trellis, code_type = 'default', puncture_matrix=No
353
353
354
354
term_bits = dec2bitarray (current_state , trellis .total_memory )
355
355
term_bits = term_bits [::- 1 ]
356
- for i in xrange (trellis .total_memory ):
356
+ for i in range (trellis .total_memory ):
357
357
current_input = bitarray2dec (term_bits [i * k :(i + 1 )* k ])
358
358
current_output = output_table [current_state ][current_input ]
359
359
outbits [j * n :(j + 1 )* n ] = dec2bitarray (current_output , n )
360
360
current_state = next_state_table [current_state ][current_input ]
361
361
j += 1
362
362
363
363
j = 0
364
- for i in xrange (number_outbits ):
364
+ for i in range (number_outbits ):
365
365
if puncture_matrix [0 ][i % np .size (puncture_matrix , 1 )] == 1 :
366
366
p_outbits [j ] = outbits [i ]
367
367
j = j + 1
@@ -373,8 +373,8 @@ def _where_c(inarray, rows, cols, search_value, index_array):
373
373
374
374
#cdef int i, j,
375
375
number_found = 0
376
- for i in xrange (rows ):
377
- for j in xrange (cols ):
376
+ for i in range (rows ):
377
+ for j in range (cols ):
378
378
if inarray [i , j ] == search_value :
379
379
index_array [number_found , 0 ] = i
380
380
index_array [number_found , 1 ] = j
@@ -407,14 +407,14 @@ def _acs_traceback(r_codeword, trellis, decoding_type,
407
407
decoded_bitarray = np .empty (k , 'int' )
408
408
409
409
# Loop over all the current states (Time instant: t)
410
- for state_num in xrange (current_number_states ):
410
+ for state_num in range (current_number_states ):
411
411
412
412
# Using the next state table find the previous states and inputs
413
413
# leading into the current state (Trellis)
414
414
number_found = _where_c (next_state_table , number_states , number_inputs , state_num , index_array )
415
415
416
416
# Loop over all the previous states (Time instant: t-1)
417
- for i in xrange (number_found ):
417
+ for i in range (number_found ):
418
418
419
419
previous_state = index_array [i , 0 ]
420
420
previous_input = index_array [i , 1 ]
@@ -457,7 +457,7 @@ def _acs_traceback(r_codeword, trellis, decoding_type,
457
457
current_state = path_metrics [:,1 ].argmin ()
458
458
459
459
# Traceback Loop
460
- for j in reversed (xrange (1 , tb_depth )):
460
+ for j in reversed (range (1 , tb_depth )):
461
461
462
462
dec_symbol = decoded_symbols [current_state , j ]
463
463
previous_state = paths [current_state , j ]
@@ -538,7 +538,7 @@ def viterbi_decode(coded_bits, trellis, tb_depth=None, decoding_type='hard'):
538
538
count = 0
539
539
current_number_states = number_states
540
540
541
- for t in xrange (1 , ( L + total_memory + total_memory % k )/ k + 1 ):
541
+ for t in range (1 , int (( L + total_memory + total_memory % k )/ k ) + 1 ):
542
542
# Get the received codeword corresponding to t
543
543
if t <= L :
544
544
r_codeword = coded_bits [(t - 1 )* n :t * n ]
0 commit comments