You are on page 1of 1

EbNodB=6;

R=4/7;
EbNo=10^(EbNodB/10);
sigma = sqrt(1/(2*R*EbNo));
k=4;
n=7;
cword=[ 0 0 0 0 0 0 0;
0 0 0 1 0 1 1;
0 0 1 0 1 1 0;
0 0 1 1 1 0 1;
0 1 0 0 1 1 1;
0 1 0 1 1 0 0;
0 1 1 0 0 0 1;
0 1 1 1 0 1 0;
1 0 0 0 1 0 1;
1 0 0 1 1 1 0;
1 0 1 0 0 1 1;
1 0 1 1 0 0 0;
1 1 0 0 0 1 0;
1 1 0 1 0 0 1;
1 1 1 0 1 0 0;
1 1 1 1 1 1 1];
Nerrs = 0;
Nblocks=1000;
for i=1:Nblocks
msg =randi([0 1],1,k);
cword =[msg mod(msg(1)+msg(2)+msg(3),2)...
mod(msg(2)+msg(3)+msg(4),2)...
mod(msg(1)+msg(2)+msg(4),2)];
s=1-2*cword;
r=s+sigma*randn(1,n);
%AWNG CHANNEL
%HARD-decision decoding
b=(r<0);
dist = mod(repmat(b,16,1) +cwords,2)*ones(7,1);
[mind1,pos]= min(dist);
mag_cap1= cwords(pos,1:4);

%SOFT-DECISION DECODING
corr = (1-2*cwords)*r';

[mind2,pos]= max(corr);
mag_cap2= cwords(pos,1:4);
Nerrs = Nerrs + sum(msg ~= msg_cap2);
end
BER_sim =Nerrs/k/Nblocks;
disp([EbNodB BER-sim Nerrs K*Nblocks])

You might also like