def cyclic_encoder(self,x,G='<STR_LIT>'):
<EOL>if(len(x) % self.k or len(x) < self.k):<EOL><INDENT>raise ValueError('<STR_LIT>' %self.k)<EOL><DEDENT>if(np.dtype(x[<NUM_LIT:0>]) != int):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>Num_blocks = int(len(x) / self.k)<EOL>codewords = np.zeros((Num_blocks,self.n),dtype=int)<EOL>x = np.reshape(x,(Num_blocks,self.k))<EOL>for p in range(Num_blocks):<EOL><INDENT>S = np.zeros(len(self.G))<EOL>codeword = np.zeros(self.n)<EOL>current_block = x[p,:]<EOL>for i in range(<NUM_LIT:0>,self.n):<EOL><INDENT>if(i < self.k):<EOL><INDENT>S[<NUM_LIT:0>] = current_block[i]<EOL>S0temp = <NUM_LIT:0><EOL>for m in range(<NUM_LIT:0>,len(self.G)):<EOL><INDENT>if(self.G[m] == '<STR_LIT:1>'):<EOL><INDENT>S0temp = S0temp + S[m]<EOL><DEDENT><DEDENT>S0temp = S0temp % <NUM_LIT:2><EOL>S = np.roll(S,<NUM_LIT:1>)<EOL>codeword[i] = current_block[i]<EOL>S[<NUM_LIT:1>] = S0temp<EOL><DEDENT>else:<EOL><INDENT>out = <NUM_LIT:0><EOL>for m in range(<NUM_LIT:1>,len(self.G)):<EOL><INDENT>if(self.G[m] == '<STR_LIT:1>'):<EOL><INDENT>out = out + S[m]<EOL><DEDENT><DEDENT>codeword[i] = out % <NUM_LIT:2><EOL>S = np.roll(S,<NUM_LIT:1>)<EOL>S[<NUM_LIT:1>] = <NUM_LIT:0><EOL><DEDENT><DEDENT>codewords[p,:] = codeword<EOL><DEDENT>codewords = np.reshape(codewords,np.size(codewords))<EOL>return codewords.astype(int)<EOL>
Encodes input bit array x using cyclic block code.

parameters
----------
x: vector of source bits to be encoded by block encoder. Numpy array
   of integers expected.

returns
-------
codewords: vector of code words generated from input vector

Andrew Smit November 2018