Skip to content

Commit e78beea

Browse files
committed
Typo & Test for conv_encode
1 parent 21c090f commit e78beea

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

commpy/channelcoding/tests/test_convcode.py

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

4+
from commpy.channelcoding.convcode import Trellis, conv_encode, viterbi_decode
45
from numpy import array, inf
56
from numpy.random import randint, randn
67
from numpy.testing import assert_array_equal, dec, assert_array_less
78

8-
from commpy.channelcoding.convcode import Trellis, conv_encode, viterbi_decode
9-
109

1110
class TestConvCode(object):
1211

@@ -15,6 +14,8 @@ def setup_class(cls):
1514
cls.trellis = []
1615
cls.desired_next_state_table = []
1716
cls.desired_output_table = []
17+
cls.desired_encode_msg = []
18+
cls.mes = array((0, 0, 1, 0))
1819

1920
### 1/2 - rate codes ###
2021

@@ -30,6 +31,7 @@ def setup_class(cls):
3031
[3, 0],
3132
[1, 2],
3233
[2, 1]]))
34+
cls.desired_encode_msg.append(array([0., 0., 0., 0., 1., 1., 0., 1.]))
3335

3436
# Convolutional Code 2: G(D) = [1 1+D+D^2/1+D]
3537
memory = array([2])
@@ -44,6 +46,7 @@ def setup_class(cls):
4446
[0, 3],
4547
[1, 2],
4648
[1, 2]]))
49+
cls.desired_encode_msg.append(array([0., 0., 0., 0., 1., 1., 0., 1.]))
4750

4851
### 2/3 - rate codes ###
4952

@@ -67,6 +70,7 @@ def setup_class(cls):
6770
[1, 0, 7, 6],
6871
[4, 5, 2, 3],
6972
[7, 6, 1, 0]]))
73+
cls.desired_encode_msg.append(array([0., 0., 0., 1., 1., 0.]))
7074

7175
# Convolutional Code 2: G(D) = [[1, 0, 0], [0, 1, 1+D]]; F(D) = [[D, D], [1+D, 1]]
7276
memory = array([1, 1])
@@ -81,6 +85,7 @@ def setup_class(cls):
8185
[1, 2, 5, 6],
8286
[0, 3, 4, 7],
8387
[1, 2, 5, 6]]))
88+
cls.desired_encode_msg.append(array([0., 0., 0., 1., 0., 0.]))
8489

8590
@classmethod
8691
def teardown_class(cls):
@@ -95,7 +100,8 @@ def test_output_table(self):
95100
assert_array_equal(self.trellis[i].output_table, self.desired_output_table[i])
96101

97102
def test_conv_encode(self):
98-
pass
103+
for i in range(len(self.trellis)):
104+
assert_array_equal(conv_encode(self.mes, self.trellis[i],'cont'), self.desired_encode_msg[i])
99105

100106
def test_viterbi_decode(self):
101107
pass
@@ -132,3 +138,10 @@ def test_conv_encode_viterbi_decode(self):
132138
coded_syms = (2.0 * coded_bits - 1) * inf
133139
decoded_bits = viterbi_decode(coded_syms, self.trellis[i], 15, 'soft')
134140
assert_array_less((decoded_bits[:len(msg)] - msg).sum(), 0.03 * blocklength)
141+
142+
coded = conv_encode(msg, self.trellis[i], termination='cont')
143+
coded_bits = coded.astype(float)
144+
coded_bits[coded_bits == 1.0] = inf
145+
coded_bits[coded_bits == 0.0] = -inf
146+
decoded_bits = viterbi_decode(coded_bits, self.trellis[i], 15,'soft')
147+
assert_array_equal(decoded_bits, msg)

commpy/modulation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
from itertools import product
2323

2424
import matplotlib.pyplot as plt
25+
from commpy.utilities import bitarray2dec, dec2bitarray
2526
from numpy import arange, array, zeros, pi, cos, sin, sqrt, log2, argmin, \
2627
hstack, repeat, tile, dot, shape, concatenate, exp, \
2728
log, vectorize, empty, eye, kron, inf
2829
from numpy.fft import fft, ifft
2930
from numpy.linalg import qr, norm
3031

31-
from commpy.utilities import bitarray2dec, dec2bitarray
32-
3332
__all__ = ['PSKModem', 'QAMModem', 'ofdm_tx', 'ofdm_rx', 'mimo_ml', 'kbest', 'bit_lvl_repr', 'max_log_approx']
3433

3534

@@ -395,7 +394,7 @@ def max_log_approx(y, h, noise_var, pts_list, demode):
395394
396395
return
397396
------
398-
LLR : 1D nbarray of floats
397+
LLR : 1D ndarray of floats
399398
Log-Likelihood Ratio for each bit (same length as the return of decode)
400399
"""
401400
# Decode all pts

0 commit comments

Comments
 (0)