Friday, January 17, 2020

block codes

#Program to generate parity check matrix
from numpy import ones,zeros,identity,transpose,hstack,mat
n=5
k=1
m=1
I=identity(n-k)
P=ones(n-k)
I=mat(I)
P=mat(P)
H=hstack([I,transpose(P)])
print('\n parity check matrix\n',H)
print('\n identity matrix\n',I)

#Program to generate code vectors
from numpy import ones,zeros,identity,multiply,mat,concatenate,hstack,transpose
from pylab import show
k=4
n=7
d=n-k
I=identity(k)
I=mat(I)
print('identity matrix Ik\n',I)
p=[[1,1,0],[0,1,1],[1,1,1],[1,0,1]]
p=mat(p)
print('\n coefficient matrix p\n',p)
G=hstack([p,I])
print('generator matrix G\n',G)
H=hstack([identity(k-1),transpose(p)])
print('parity check matrix H\n',H)
d=[[0,0,0,0],[0,0,0,1],[0,0,1,0],[0,0,1,1],
   [0,1,0,0],[0,1,0,1],[0,1,1,0],[0,1,1,1],
   [1,0,0,0],[1,0,0,1],[1,0,1,0],[1,0,1,1],
   [1,1,0,0],[1,1,0,1],[1,1,1,0],[1,1,1,1]]
c=d*G
c=(c%2)
print('codes block of(7,4)hamming code\n',c)

No comments:

Post a Comment

qpsk

from numpy import ones,arange,cos,sin,pi from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show M =4# i = range(0,M) t = a...