clc;
clear all;
close all;
c=hadamard(8);
h=zeros(8,8);
for i=1:8
for j=1:8
h(i,j)=(c(i,j)+1)/2;
end;
end;
% h1=c(9,:);
h2=c(2,:);
h3=c(3,:);
h4=c(4,:);
h5=c(5,:);
h6=c(6,:);
h7=c(7,:);
h8=c(8,:);
% data_h1=length(h1);
data_h2=length(h2);
data_h3=length(h3);
data_h4=length(h4);
data_h5=length(h5);
data_h6=length(h6);
data_h7=length(h7);
data_h8=length(h8);
% % t1 = 1:1:10;
% d1=randint(1,1000);
d2=randint(1,1000);
d3=randint(1,1000);
d4=randint(1,1000);
d5=randint(1,1000);
d6=randint(1,1000);
d7=randint(1,1000);
d8=randint(1,1000);
% data1=length(d1);
data2=length(d2);
data3=length(d3);
data4=length(d4);
data5=length(d5);
data6=length(d6);
data7=length(d7);
data8=length(d8);
for i=1:data2
% d11=2*d1 - 1;
d12=2*d2 - 1;
d13=2*d3 - 1;
d14=2*d4 - 1;
d15=2*d5 - 1;
d16=2*d6 - 1;
d17=2*d7 - 1;
d18=2*d8 - 1;
end;
% spred1=data1*data_h1;
spred2=data2*data_h2;
spred3=data3*data_h3;
spred4=data4*data_h4;
spred5=data5*data_h5;
spred6=data6*data_h6;
spred7=data7*data_h7;
spred8=data8*data_h8;
% a1=zeros(data_h1,data1);
a2=zeros(data_h2,data2);
a3=zeros(data_h3,data3);
a4=zeros(data_h4,data4);
a5=zeros(data_h5,data5);
a6=zeros(data_h6,data6);
a7=zeros(data_h7,data7);
a8=zeros(data_h8,data8);
for m1 = 1:data2
% if d11(m1)== -1
% a1(:,m1)=h1;
% else
% a1(:,m1)=(-1)*h1;
% end;
if d12(m1)== -1
a2(:,m1)=h2;
else
a2(:,m1)=(-1)*h2;
end;
if d13(m1)== -1
a3(:,m1)=h3;
else
a3(:,m1)=(-1)*h3;
end;
if d14(m1)== -1
a4(:,m1)=h4;
else
a4(:,m1)=(-1)*h4;
end;
if d15(m1)== -1
a5(:,m1)=h5;
else
a5(:,m1)=(-1)*h5;
end;
if d16(m1)== -1
a6(:,m1)=h6;
else
a6(:,m1)=(-1)*h6;
end;
if d17(m1)== -1
a7(:,m1)=h7;
else
a7(:,m1)=(-1)*h7;
end;
if d18(m1)== -1
a8(:,m1)=h8;
else
a8(:,m1)=(-1)*h8;
end;
end;
% a1sym = reshape(a1,1,[]);
a2sym = reshape(a2,1,[]);
a3sym = reshape(a3,1,[]);
a4sym = reshape(a4,1,[]);
a5sym = reshape(a5,1,[]);
a6sym = reshape(a6,1,[]);
a7sym = reshape(a7,1,[]);
a8sym = reshape(a8,1,[]);
A=a2sym+a3sym+a4sym+a5sym+a6sym+a7sym+a8sym;
EbNovec =0:1:20;
sn=length(EbNovec);
% ber1 = zeros(1,sn);
ber2 = zeros(1,sn);
ber3 = zeros(1,sn);
ber4 = zeros(1,sn);
ber5 = zeros(1,sn);
ber6 = zeros(1,sn);
ber7 = zeros(1,sn);
ber8 = zeros(1,sn);
for i=1:sn
EbNo = EbNovec(i);
snr=EbNo;
r = awgn(A,snr);
rth=zeros(1,spred2);
r1=zeros(1,spred2);
for m=1:spred2
if r(m)<0.5
rth(m)=-1;
else
rth(m)=1;
end;
r1(m)=(rth(m)+1)/2;
end;
r1re=reshape(r1,data_h2,[]);
r1t=transpose(r1re);
% y1=zeros(data_h1,data1);
y2=zeros(data_h2,data2);
y3=zeros(data_h3,data3);
y4=zeros(data_h4,data4);
y5=zeros(data_h5,data5);
y6=zeros(data_h6,data6);
y7=zeros(data_h7,data7);
y8=zeros(data_h8,data8);
for m1 = 1:data2
% y1(:,m1)=bitxor(h(9,:),r1t(m1,:));
y2(:,m1)=bitxor(h(2,:),r1t(m1,:));
y3(:,m1)=bitxor(h(3,:),r1t(m1,:));
y4(:,m1)=bitxor(h(4,:),r1t(m1,:));
y5(:,m1)=bitxor(h(5,:),r1t(m1,:));
y6(:,m1)=bitxor(h(6,:),r1t(m1,:));
y7(:,m1)=bitxor(h(7,:),r1t(m1,:));
y8(:,m1)=bitxor(h(8,:),r1t(m1,:));
% y11=2*y1 - 1;
y12=2*y2 - 1;
y13=2*y3 - 1;
y14=2*y4 - 1;
y15=2*y5 - 1;
y16=2*y6 - 1;
y17=2*y7 - 1;
y18=2*y8 - 1;
end;
% Rx1=mean(y11);
Rx2=mean(y12);
Rx3=mean(y13);
Rx4=mean(y14);
Rx5=mean(y15);
Rx6=mean(y16);
Rx7=mean(y17);
Rx8=mean(y18);
% Rx11=zeros(1,data1);
Rx12=zeros(1,data2);
Rx13=zeros(1,data3);
Rx14=zeros(1,data4);
Rx15=zeros(1,data5);
Rx16=zeros(1,data6);
Rx17=zeros(1,data7);
Rx18=zeros(1,data8);
for a=1:data2
% if Rx1(a)<=0
% Rx11(a)=-1;
% else
% Rx11(a)=1;
% end;
if Rx2(a)<=0
Rx12(a)=-1;
else
Rx12(a)=1;
end;
if Rx3(a)<=0
Rx13(a)=-1;
else
Rx13(a)=1;
end;
if Rx4(a)<=0
Rx14(a)=-1;
else
Rx14(a)=1;
end;
if Rx5(a)<=0
Rx15(a)=-1;
else
Rx15(a)=1;
end;
if Rx6(a)<=0
Rx16(a)=-1;
else
Rx16(a)=1;
end;
if Rx7(a)<=0
Rx17(a)=-1;
else
Rx17(a)=1;
end;
if Rx8(a)<=0
Rx18(a)=-1;
else
Rx18(a)=1;
end;
end;
% x1=zeros(1,data1);
x2=zeros(1,data2);
x3=zeros(1,data3);
x4=zeros(1,data4);
x5=zeros(1,data5);
x6=zeros(1,data6);
x7=zeros(1,data7);
x8=zeros(1,data8);
for m3=1:data2
% if(d11(m3)==Rx11(m3))
% x1(m3)=1;
% else
% x1(m3)=0;
% end;
if(d12(m3)==Rx12(m3))
x2(m3)=1;
else
x2(m3)=0;
end;
if(d13(m3)==Rx13(m3))
x3(m3)=1;
else
x3(m3)=0;
end;
if(d14(m3)==Rx14(m3))
x4(m3)=1;
else
x4(m3)=0;
end;
if(d15(m3)==Rx15(m3))
x5(m3)=1;
else
x5(m3)=0;
end;
if(d16(m3)==Rx16(m3))
x6(m3)=1;
else
x6(m3)=0;
end;
if(d17(m3)==Rx17(m3))
x7(m3)=1;
else
x7(m3)=0;
end;
if(d18(m3)==Rx18(m3))
x8(m3)=1;
else
x8(m3)=0;
end;
end;
% newerrs1 = 0;
newerrs2 = 0;
newerrs3 = 0;
newerrs4 = 0;
newerrs5 = 0;
newerrs6 = 0;
newerrs7 = 0;
newerrs8 = 0;
for a=1:data2
% if(x1(a)== 0)
% newerrs1 = newerrs1 + 1;
% end;
if(x2(a)== 0)
newerrs2 = newerrs2 + 1;
end;
if(x3(a)== 0)
newerrs3= newerrs3 + 1;
end;
if(x4(a)== 0)
newerrs4= newerrs4 + 1;
end;
if(x5(a)== 0)
newerrs5= newerrs5 + 1;
end;
if(x6(a)== 0)
newerrs6= newerrs6 + 1;
end;
if(x7(a)== 0)
newerrs7= newerrs7 + 1;
end;
if(x8(a)== 0)
newerrs8= newerrs8 + 1;
end;
end;
% numerrs1=newerrs1;
% ber1(i)=numerrs1/spred1;
%
numerrs2=newerrs2;
ber2(i)=numerrs2/spred2;
numerrs3=newerrs3;
ber3(i)=numerrs3/spred3;
numerrs4=newerrs4;
ber4(i)=numerrs4/spred4;
numerrs5=newerrs5;
ber5(i)=numerrs5/spred5;
numerrs6=newerrs6;
ber6(i)=numerrs6/spred6;
numerrs7=newerrs7;
ber7(i)=numerrs7/spred7;
numerrs8=newerrs8;
ber8(i)=numerrs8/spred8;
% [ber1(i), intv1] = berconfint(numerrs1,d1,.98);
% intv{i} = intv1; % Store in cell array for later use.
% disp(['EbNo = ' num2str(EbNo) ' dB, ' num2str(numerrs1) ...
% ' errors, BER1 = ' num2str(ber1(i))])
disp(['EbNo = ' num2str(EbNo) ' dB, ' num2str(numerrs2) ...
' errors, BER2 = ' num2str(ber2(i))])
disp(['EbNo = ' num2str(EbNo) ' dB, ' num2str(numerrs3) ...
' errors, BER3 = ' num2str(ber3(i))])
disp(['EbNo = ' num2str(EbNo) ' dB, ' num2str(numerrs4) ...
' errors, BER4 = ' num2str(ber4(i))])
disp(['EbNo = ' num2str(EbNo) ' dB, ' num2str(numerrs5) ...
' errors, BER5 = ' num2str(ber5(i))])
disp(['EbNo = ' num2str(EbNo) ' dB, ' num2str(numer