def lfsr_autocorrelation(L, P, k):
 if (not isinstance(L, list)):
  raise TypeError(('L (=%s) must be a list' % L))
 P = int(P)
 k = int(k)
 L0 = L[:P]
 L1 = (L0 + L0[:k])
 L2 = [((-1) ** (L1[i].to_int() + L1[(i + k)].to_int())) for i in range(P)]
 tot = sum(L2)
 return Rational(tot, P)

def lfsr_autocorrelation ( L , P , k ) : if ( not isinstance ( L , list ) ) : raise TypeError ( ( 'L (=%s) must be a list' % L ) ) P = int ( P ) k = int ( k ) L0 = L [ : P ] L1 = ( L0 + L0 [ : k ] ) L2 = [ ( ( - 1 ) ** ( L1 [ i ] . to_int ( ) + L1 [ ( i + k ) ] . to_int ( ) ) ) for i in range ( P ) ] tot = sum ( L2 ) return Rational ( tot , P )
this function computes the lfsr autocorrelation function .