Skip to content

Commit 6c97793

Browse files
committed
Update conv_code
1 parent c46a6de commit 6c97793

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

commpy/channelcoding/convcode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def viterbi_decode(coded_bits, trellis, tb_depth=None, decoding_type='hard'):
693693
if decoding_type == 'hard':
694694
r_codeword[:] = 0
695695
elif decoding_type == 'soft':
696-
r_codeword[:] = np.iinfo(int).min
696+
r_codeword[:] = 0
697697
elif decoding_type == 'unquantized':
698698
r_codeword[:] = -1
699699
else:

commpy/channelcoding/tests/test_convcode.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Authors: CommPy contributors
22
# License: BSD 3-Clause
33

4-
from commpy.channelcoding.convcode import Trellis, conv_encode, viterbi_decode
54
from numpy import array, inf
6-
from numpy.random import randint, randn
7-
from numpy.testing import assert_array_equal, dec, assert_array_less
5+
from numpy.random import randint, randn, seed
6+
from numpy.testing import assert_array_equal, dec, run_module_suite
7+
8+
from commpy.channelcoding.convcode import Trellis, conv_encode, viterbi_decode
89

910

1011
class TestConvCode(object):
@@ -104,18 +105,18 @@ def test_conv_encode(self):
104105
assert_array_equal(conv_encode(self.mes, self.trellis[i],'cont'), self.desired_encode_msg[i])
105106

106107
def test_viterbi_decode(self):
107-
pass
108+
pass # Tested below
108109

109110
@dec.slow
110111
def test_conv_encode_viterbi_decode(self):
111112
niters = 10
112113
blocklength = 1000
113114

114-
for i in range(niters):
115+
for n in range(niters):
115116
msg = randint(0, 2, blocklength)
116117

117118
# Previous tests
118-
for i in range(4):
119+
for i in range(len(self.trellis)):
119120
coded_bits = conv_encode(msg, self.trellis[i])
120121
decoded_bits = viterbi_decode(coded_bits.astype(float), self.trellis[i], 15)
121122
assert_array_equal(decoded_bits[:len(msg)], msg)
@@ -132,16 +133,27 @@ def test_conv_encode_viterbi_decode(self):
132133
coded_bits = conv_encode(msg, self.trellis[i])
133134
coded_syms = 10.0 * coded_bits - 5 + randn(len(coded_bits)) * 2
134135
decoded_bits = viterbi_decode(coded_syms, self.trellis[i], 15, 'soft')
135-
assert_array_less((decoded_bits[:len(msg)] - msg).sum(), 0.03 * blocklength)
136+
assert_array_equal(decoded_bits[:len(msg)], msg)
137+
138+
coded_bits = conv_encode(msg, self.trellis[i], termination='cont')
139+
coded_syms = 10.0 * coded_bits - 5 + randn(len(coded_bits)) * 2
140+
decoded_bits = viterbi_decode(coded_syms, self.trellis[i], 15, 'soft')
141+
assert_array_equal(decoded_bits, msg)
136142

137143
coded_bits = conv_encode(msg, self.trellis[i])
138144
coded_syms = (2.0 * coded_bits - 1) * inf
139145
decoded_bits = viterbi_decode(coded_syms, self.trellis[i], 15, 'soft')
140-
assert_array_less((decoded_bits[:len(msg)] - msg).sum(), 0.03 * blocklength)
146+
assert_array_equal(decoded_bits[:len(msg)], msg)
141147

142148
coded = conv_encode(msg, self.trellis[i], termination='cont')
143149
coded_bits = coded.astype(float)
144150
coded_bits[coded_bits == 1.0] = inf
145151
coded_bits[coded_bits == 0.0] = -inf
146-
decoded_bits = viterbi_decode(coded_bits, self.trellis[i], 15,'soft')
152+
decoded_bits = viterbi_decode(coded_bits, self.trellis[i], 15, 'soft')
147153
assert_array_equal(decoded_bits, msg)
154+
155+
156+
if __name__ == "__main__":
157+
seed(17121996)
158+
run_module_suite()
159+

commpy/tests/test_modulation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def decode(pt):
7171
err_msg='Wrong LLRs without noise')
7272

7373

74+
def test_kbest():
75+
pass # Tested in test_links
76+
77+
7478
if __name__ == "__main__":
7579
seed(17121996)
7680
run_module_suite()

0 commit comments

Comments
 (0)