2323from matplotlib .collections import PatchCollection
2424import matplotlib .patches as mpatches
2525
26- from commpy .utilities import dec2bitarray , bitarray2dec , hamming_dist
26+ from commpy .utilities import dec2bitarray , bitarray2dec , hamming_dist , euclid_dist
2727#from commpy.channelcoding.acstb import acs_traceback
2828
2929__all__ = ['Trellis' , 'conv_encode' , 'viterbi_decode' ]
@@ -445,7 +445,7 @@ def _acs_traceback(r_codeword, trellis, decoding_type,
445445 pass
446446 elif decoding_type == 'unquantized' :
447447 i_codeword_array = 2 * i_codeword_array - 1
448- branch_metric = euclid_dist_c (r_codeword , i_codeword_array , n )
448+ branch_metric = euclid_dist (r_codeword , i_codeword_array )
449449 else :
450450 pass
451451
@@ -474,7 +474,6 @@ def _acs_traceback(r_codeword, trellis, decoding_type,
474474
475475 dec_symbol = decoded_symbols [current_state , j ]
476476 previous_state = paths [current_state , j ]
477- #dec2bitarray_c(dec_symbol, k, decoded_bitarray)
478477 decoded_bitarray = dec2bitarray (dec_symbol , k )
479478 decoded_bits [(t - tb_depth - 1 )+ (j + 1 )* k + count :(t - tb_depth - 1 )+ (j + 2 )* k + count ] = \
480479 decoded_bitarray
@@ -504,8 +503,10 @@ def viterbi_decode(coded_bits, trellis, tb_depth=None, decoding_type='hard'):
504503 tb_length : int
505504 Traceback depth (Typically set to 5*(M+1)).
506505
507- decoding_type : str {'hard', 'soft', ' unquantized'}
506+ decoding_type : str {'hard', 'unquantized'}
508507 The type of decoding to be used.
508+ 'hard' option is used for hard inputs (bits) to the decoder, e.g., BSC channel.
509+ 'unquantized' option is used for soft inputs (real numbers) to the decoder, e.g., BAWGN channel.
509510
510511 Returns
511512 -------
@@ -536,15 +537,15 @@ def viterbi_decode(coded_bits, trellis, tb_depth=None, decoding_type='hard'):
536537 L = int (len (coded_bits )* rate )
537538
538539 path_metrics = np .empty ([number_states , 2 ])
539- path_metrics [:, :] = 10000
540+ path_metrics [:, :] = 1000000
540541 path_metrics [0 ][0 ] = 0
541542 paths = np .empty ([number_states , tb_depth ], 'int' )
542- paths [:, :] = 10000
543+ paths [:, :] = 1000000
543544 paths [0 ][0 ] = 0
544545
545546 decoded_symbols = np .zeros ([number_states , tb_depth ], 'int' )
546- decoded_bits = np .empty (L + tb_depth + k , 'int' )
547- r_codeword = np .empty (n , 'int' )
547+ decoded_bits = np .zeros (L + tb_depth + k , 'int' )
548+ r_codeword = np .zeros (n , 'int' )
548549
549550 tb_count = 1
550551 count = 0
@@ -561,7 +562,7 @@ def viterbi_decode(coded_bits, trellis, tb_depth=None, decoding_type='hard'):
561562 pass
562563 elif decoding_type == 'unquantized' :
563564 r_codeword [:] = 0
564- r_codeword = r_codeword - 1
565+ r_codeword = 2 * r_codeword - 1
565566 else :
566567 pass
567568
@@ -583,4 +584,3 @@ def viterbi_decode(coded_bits, trellis, tb_depth=None, decoding_type='hard'):
583584 current_number_states = 1
584585
585586 return decoded_bits [0 :len (decoded_bits )- tb_depth - 1 ]
586- #return decoded_bits[0:len(decoded_bits)-tb_depth-total_memory-total_memory%k-k]
0 commit comments