def conv_encoder(self,input,state):
output = []<EOL>if(self.rate == Fraction(<NUM_LIT:1>,<NUM_LIT:2>)):<EOL><INDENT>for n in range(len(input)):<EOL><INDENT>u1 = int(input[n])<EOL>u2 = int(input[n])<EOL>for m in range(<NUM_LIT:1>,self.constraint_length):<EOL><INDENT>if int(self.G_polys[<NUM_LIT:0>][m]) == <NUM_LIT:1>: <EOL><INDENT>u1 = u1 ^ int(state[m-<NUM_LIT:1>])<EOL><DEDENT>if int(self.G_polys[<NUM_LIT:1>][m]) == <NUM_LIT:1>: <EOL><INDENT>u2 = u2 ^ int(state[m-<NUM_LIT:1>])<EOL><DEDENT><DEDENT>output = np.hstack((output, [u1, u2]))<EOL>state = bin(int(input[n]))[-<NUM_LIT:1>] + state[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>elif(self.rate == Fraction(<NUM_LIT:1>,<NUM_LIT:3>)):<EOL><INDENT>for n in range(len(input)):<EOL><INDENT>if(int(self.G_polys[<NUM_LIT:0>][<NUM_LIT:0>]) == <NUM_LIT:1>):<EOL><INDENT>u1 = int(input[n])<EOL><DEDENT>else:<EOL><INDENT>u1 = <NUM_LIT:0><EOL><DEDENT>if(int(self.G_polys[<NUM_LIT:1>][<NUM_LIT:0>]) == <NUM_LIT:1>):<EOL><INDENT>u2 = int(input[n])<EOL><DEDENT>else:<EOL><INDENT>u2 = <NUM_LIT:0><EOL><DEDENT>if(int(self.G_polys[<NUM_LIT:2>][<NUM_LIT:0>]) == <NUM_LIT:1>):<EOL><INDENT>u3 = int(input[n])<EOL><DEDENT>else:<EOL><INDENT>u3 = <NUM_LIT:0><EOL><DEDENT>for m in range(<NUM_LIT:1>,self.constraint_length):<EOL><INDENT>if int(self.G_polys[<NUM_LIT:0>][m]) == <NUM_LIT:1>: <EOL><INDENT>u1 = u1 ^ int(state[m-<NUM_LIT:1>])<EOL><DEDENT>if int(self.G_polys[<NUM_LIT:1>][m]) == <NUM_LIT:1>: <EOL><INDENT>u2 = u2 ^ int(state[m-<NUM_LIT:1>])<EOL><DEDENT>if int(self.G_polys[<NUM_LIT:2>][m]) == <NUM_LIT:1>: <EOL><INDENT>u3 = u3 ^ int(state[m-<NUM_LIT:1>])<EOL><DEDENT><DEDENT>output = np.hstack((output, [u1, u2, u3]))<EOL>state = bin(int(input[n]))[-<NUM_LIT:1>] + state[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>return output, state<EOL>
output, state = conv_encoder(input,state)
We get the 1/2 or 1/3 rate from self.rate
Polys G1 and G2 are entered as binary strings, e.g,
G1 = '111' and G2 = '101' for K = 3
G1 = '1011011' and G2 = '1111001' for K = 7
G3 is also included for rate 1/3
Input state as a binary string of length K-1, e.g., '00' or '0000000' 
e.g., state = '00' for K = 3
e.g., state = '000000' for K = 7
Mark Wickert and Andrew Smit 2018