You are on page 1of 8

Lab Report#11

Subject:
Digital Communications

Title:
linear block encoding
syndrome

SUBMITED by:
Zueem-Ul-Haq
20380

SUBMITED TO:
Ms.Afshan
Lab Report 9

Digital Communication

Lab Title
AWGN noise, Entropy

Submitted to:
Sir Ahmed

Submitted by:
Hammad Hafeez

ID:
20294
TASK-1 implementation of linear block encoding.
n=7
k=4
r=n-k
msg=[0 1 0 0]
p=[1 0 1 ; 1 1 0 ; 1 1 1 ; 0 1 1]
genmat=[eye(4),p]
encode(msg,n,k,'linear/binary',genmat

OUTPUT:
genmat =

1 0 0 0 1 0 1
0 1 0 0 1 1 0
0 0 1 0 1 1 1
0 0 0 1 0 1 1

ans =

0 1 0 0 1 1 0

For different value of parity and message:


n=6
k=3
r=n-k
msg=[1 0 1]
p=[0 1 1 ; 1 0 1 ; 1 1 0]
genmat=[eye(3),p]
encode(msg,n,k,'linear/binary',genmat)

OUTPUT:
genmat =

1 0 0 0 1 1

0 1 0 1 0 1

0 0 1 1 1 0

ans =

1 0 1 1 0 1
TASK-2 Generate MATLAB code to create 10 message
randomly having size of 4 bits.

n=7
k=4
msg=randi([0 1],10,k)
code1=encode(msg,n,k,'hamming/binary')
[permat,genmat]=hammgen(3)
code2=encode(msg,n,k,'linear/binary',genmat)
if(code1==code2)
disp('both code are same generated by linear encoding and hamming
encoding')
end

OUTPUT:

n=7

k=4

msg =

1 0 0 1

0 0 1 0

1 0 0 1

1 0 0 1

0 1 1 0

1 0 1 0

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 1

code1 =

0 1 1 1 0 0 1

1 1 1 0 0 1 0

0 1 1 1 0 0 1

0 1 1 1 0 0 1

1 0 0 0 1 1 0
0 0 1 1 0 1 0

1 1 0 1 0 0 0

1 1 0 1 0 0 0

1 1 0 1 0 0 0

0 1 1 1 0 0 1

permat =

1 0 0 1 0 1 1

0 1 0 1 1 1 0

0 0 1 0 1 1 1

genmat =

1 1 0 1 0 0 0

0 1 1 0 1 0 0

1 1 1 0 0 1 0

1 0 1 0 0 0 1

code2 =

0 1 1 1 0 0 1

1 1 1 0 0 1 0

0 1 1 1 0 0 1

0 1 1 1 0 0 1

1 0 0 0 1 1 0

0 0 1 1 0 1 0

1 1 0 1 0 0 0

1 1 0 1 0 0 0

1 1 0 1 0 0 0

0 1 1 1 0 0 1

both code are same generated by linear encoding and hamming encoding

TASK-3 implementation of syndrome.


r=[0 1 0 0 1 0 0]
msg=[0 1 0 0]
p=[1 0 1 ; 1 1 0 ; 1 1 1 ; 0 1 1]
code=encode(msg,n,k,'linear/binary',genmat)

%decoding
h=[p',eye(3)]
syndrome=rem(code*h’,2)

OUTPUT:

p =
1 0 1
1 1 0
1 1 1
0 1 1

code = 0 1 1 0 0 0 1

h =
1 1 1 0 1 0 0
0 1 1 1 0 1 0
1 0 1 1 0 0 1

0 0 1

syndrome = 0 0 0
For flipping the bit we get syndrome
syndrome =1 1 1

TASK-4
t=0:0.01:1
f=2
x=sin(2*pi*f*t)
subplot(311)
plot(t,x)
subplot(312)
x1=stem(t)
subplot(313)
stem(x1)
y=x*x1
subplot(321)
stem(y)

OUTPUT:
TASK-5
t=0:0.01:1
Nsym=6;
b=0.5;
sampspelsym=8;
shape='raised cosine'
rcosspec=fdesign.pulseshaping(sampspelsym,shape,'Nsym,beta',Nsym,b)
rcosflt=design(rcosspec)
rcosflt.numerator=rcosflt.numerator/max(rcosflt.numerator)
disp(rcosflt)
fvtool(rcosflt,'analysis','impulse')

length=20
r=100
fs=r*sampspelsym
rs=RandStream('mt19937ar','seed',0)
x=2*randi(rs,[0 1],length,1)-1

t1=1000*(0:length-1)/r
y1=filter(rcosflt,upsample([x;zeros(Nsym/2,1)],sampspelsym))
t2=1000*(0:(length+Nsym/2)*sampspelsym-1)/fs
fig1=figure
stem(t1,x,'kx');
hold on
plot(t2,y1,'b-');
hold off
axis([0 30 -1.7 1.7])
xlabel('time(ms)')
ylabel('amplitude')
legend('transmitted data','upsampled data')

OUTPUT:

You might also like