-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConvTrellisDef.py
More file actions
53 lines (39 loc) · 1.69 KB
/
ConvTrellisDef.py
File metadata and controls
53 lines (39 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env python
# title : ConvTrellis.py
# description : This class implements functions on a trellis of a convolutional code.
# Its input is the generator polynomal of the code.
# author : Felix Arnold
# python_version : 3.5.2
import numpy as np
from utils import dec2bin
from utils import get_bit
class ConvTrellisDef(object):
def __init__(self, gen_matrix_norm, gen_feedback_norm=[]):
self.gen_matrix = np.fliplr(np.array(gen_matrix_norm))
self.K = self.get_k() # constraint length
self.Ns = 2 ** (self.K - 1) # number of states
self.Nb = 2 ** self.K # number of branches
self.wc = self.get_rate()
self.wu = 1 # 1 data bit per stage
self.gen_feedback = np.fliplr(np.array([gen_feedback_norm]))
self.rsc = len(gen_feedback_norm) > 0
def get_rate(self):
return self.gen_matrix.shape[0]
def get_k(self):
return self.gen_matrix.shape[1]
def get_next_state(self, branch):
return branch >> 1
def get_prev_state(self, branch):
return branch & (2 ** (self.K - 1) - 1)
def get_prev_branches(self, state):
return np.array([state << 1, (state << 1) + 1])
def get_next_branches(self, state):
return np.array([state, 2 ** (self.K - 1) + state])
def get_enc_bits(self, branch):
return list(np.mod(np.matmul(self.gen_matrix, (dec2bin(branch, self.K))), 2))
def get_dat(self, branch):
if not self.rsc:
return [int((branch & (2 ** (self.K - 1))) > 0)]
else:
return list(
np.mod(np.matmul(self.gen_feedback, (dec2bin(branch, self.K))) + get_bit(branch, self.K - 1), 2))