Matlab Code for 2X1 using Brute force ML
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% Golden Code(4-QAM) for 2X1 %%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all;
close all;
N = 2*10^4;
M=4;
theta = (1+sqrt(5))/2;
alpha=1+1i*(1-theta);
sigma_theta=1-theta;
G=(1/sqrt(5))*[1 -sigma_theta theta 1 0 0 0 0;
sigma_theta 1 -1 theta 0 0 0 0;
0 0 0 0 -theta -1 1 -sigma_theta;
0 0 0 0 1 -theta sigma_theta 1;
0 0 0 0 1 -sigma_theta theta 1;
0 0 0 0 sigma_theta 1 -1 theta;
1 -theta sigma_theta 1 0 0 0 0;
theta 1 -1 sigma_theta 0 0 0 0];
G = repmat(transpose(G),[1 ,N/4]);
x = randint(N,1,M);
x11=reshape(x,1,N);
y1=modulate(modem.qammod(M),x);
y1=reshape(y1,1,N);
y2=[real(y1);real(1i*(-y1))];
y2=reshape(y2,8,N/4);
y4=zeros(8,2*N);
y4(:,(1:8:end))=y2;y4(:,(2:8:end))=y2;y4(:,(3:8:end))=y2;y4(:,(4:8:end))=y2;
y4(:,(5:8:end))=y2;y4(:,(6:8:end))=y2;y4(:,(7:8:end))=y2;y4(:,(8:8:end))=y2;
Gs=sum(G.*y4,1);
Gs=reshape(Gs,8,2*N/8);
h11 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h12 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h21 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h22 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h=[h11;h21;h12;h22];
h1=reshape(h,2,N/2);
h2=zeros(2,N);
h2(:,(1:2:end))=h1;
h2(:,(2:2:end))=h1;
h3=kron(h2,[1;1]);
h4=zeros(4,2*N);
h4(:,(1:8:end))=h3(:,(1:4:end));
h4(:,(5:8:end))=h3(:,(1:4:end));
h4(:,(2:8:end))=h3(:,(2:4:end));
h4(:,(6:8:end))=h3(:,(2:4:end));
h4(:,(3:8:end))=h3(:,(3:4:end));
h4(:,(7:8:end))=h3(:,(3:4:end));
h4(:,(4:8:end))=h3(:,(4:4:end));
h4(:,(8:8:end))=h3(:,(4:4:end));
h4=[h4;h4];
mat=[1 1 0 0 0 0 0 0;
1 1 0 0 0 0 0 0;
1 1 0 0 0 0 0 0;
1 1 0 0 0 0 0 0;
0 0 0 0 1 1 0 0;
0 0 0 0 1 1 0 0;
0 0 0 0 1 1 0 0;
0 0 0 0 1 1 0 0;];
mat = repmat(mat,[1 ,N/4]);
h5=mat.*h4;
h5(1,(1:8:end))= real(h5(1,(1:8:end)));h5(2,(2:8:end))= real(h5(2,(2:8:end)));
h5(3,(3:8:end))= real(h5(3,(3:8:end)));h5(4,(4:8:end))= real(h5(4,(4:8:end)));
h5(5,(5:8:end))= real(h5(5,(5:8:end)));h5(6,(6:8:end))= real(h5(6,(6:8:end)));
h5(7,(7:8:end))= real(h5(7,(7:8:end)));h5(8,(8:8:end))= real(h5(8,(8:8:end)));
h5(2,(1:8:end))=real(1i*h5(2,(1:8:end)));h5(2,(3:8:end))=real(1i*h5(2,(3:8:end)));
h5(4,(1:8:end))=real(1i*h5(4,(1:8:end)));h5(4,(3:8:end))=real(1i*h5(4,(3:8:end)));
h5(6,(5:8:end))=real(1i*h5(6,(5:8:end)));h5(6,(7:8:end))=real(1i*h5(6,(7:8:end)));
h5(8,(5:8:end))=real(1i*h5(8,(5:8:end)));h5(8,(7:8:end))=real(1i*h5(8,(7:8:end)));
h5(3,(1:8:end))=real(h5(3,(1:8:end)));h5(4,(2:8:end))=real(h5(4,(2:8:end)));
h5(1,(3:8:end))=real(h5(1,(3:8:end)));h5(2,(4:8:end))=real(h5(2,(4:8:end)));
h5(5,(7:8:end))=real(h5(5,(7:8:end)));h5(6,(8:8:end))=real(h5(6,(8:8:end)));
h5(7,(5:8:end))=real(h5(7,(5:8:end)));h5(8,(6:8:end))=real(h5(8,(6:8:end)));
h5(1,(2:8:end))=real(1i*(-h5(1,(2:8:end))));h5(1,(4:8:end))=real(1i*(-h5(1,(4:8:end))));
h5(3,(2:8:end))=real(1i*(-h5(3,(2:8:end))));h5(3,(4:8:end))=real(1i*(-h5(3,(4:8:end))));
h5(5,(6:8:end))=real(1i*(-h5(5,(6:8:end))));h5(5,(8:8:end))=real(1i*(-h5(5,(8:8:end))));
h5(7,(6:8:end))=real(1i*(-h5(7,(6:8:end))));h5(7,(8:8:end))=real(1i*(-h5(7,(8:8:end))));
Gs1=zeros(8,2*N);
Gs1(:,(1:8:end))=Gs;Gs1(:,(2:8:end))=Gs;Gs1(:,(3:8:end))=Gs;Gs1(:,(4:8:end))=Gs;
Gs1(:,(5:8:end))=Gs;Gs1(:,(6:8:end))=Gs;Gs1(:,(7:8:end))=Gs;Gs1(:,(8:8:end))=Gs;
yout1=reshape(sum(h5.*Gs1),8,N/4);
yout(1,:)=yout1(1,:);yout(2,:)=yout1(2,:);
yout(3,:)=yout1(5,:);yout(4,:)=yout1(6,:);
snr=linspace(0,20,21);
ser=zeros(1,length(snr));
for i=1:length(snr)
N1=1/sqrt(2)*(randn(1,N)+1i*randn(1,N));
N1=reshape(N1,4,N/4);
ynoisy=yout+10^(-(snr(i)-10*log10(4))/20)*N1;
rvec=[];
for ii=0:255
r=mod(ii,4);
e=mod((ii-mod(ii,4))/4,4);
w=mod((ii-mod(ii,16))/16,4);
q=mod((ii-mod(ii,64))/64,4);
xx=[q;w;e;r];
xx = repmat(xx,[N/4,1 ]);
yy1=modulate(modem.qammod(M),xx);
yy1=reshape(yy1,1,N);
yy2=[real(yy1);real(1i*(-yy1))];
yy2=reshape(yy2,8,N/4);
yy4=zeros(8,2*N);
yy4(:,(1:8:end))=yy2;yy4(:,(2:8:end))=yy2;yy4(:,(3:8:end))=yy2;yy4(:,(4:8:end))=yy2;
yy4(:,(5:8:end))=yy2;yy4(:,(6:8:end))=yy2;yy4(:,(7:8:end))=yy2;yy4(:,(8:8:end))=yy2;
GGs=sum(G.*yy4,1);
GGs=reshape(GGs,8,2*N/8);
GGs1=zeros(8,2*N);
GGs1(:,(1:8:end))=GGs;GGs1(:,(2:8:end))=GGs;GGs1(:,(3:8:end))=GGs;GGs1(:,(4:8:end))=GGs;
GGs1(:,(5:8:end))=GGs;GGs1(:,(6:8:end))=GGs;GGs1(:,(7:8:end))=GGs;GGs1(:,(8:8:end))=GGs;
yyout1=reshape(sum(h5.*GGs1),8,N/4);
yyout(1,:)=yyout1(1,:);yyout(2,:)=yyout1(2,:);
yyout(3,:)=yyout1(5,:);yyout(4,:)=yyout1(6,:);
min1=abs(ynoisy-yyout);
min1=sum(min1.*min1,1);
min1=abs(min1);
rvec=[rvec;min1];
min1=[];
end
rvec;
[jj, dd] = min(rvec,[],1);
dd=dd-1;
dd3=zeros(1,N);
dd3(:,(4:4:end))=mod(dd,4);
dd3(:,(3:4:end))=mod((dd-mod(dd,4))/4,4);
dd3(:,(2:4:end))=mod((dd-mod(dd,16))/16,4);
dd3(:,(1:4:end))=mod((dd-mod(dd,64))/64,4);
[num ty]=symerr(x11,dd3);
dd=[];
ser(i)=ty;
end
semilogy(snr,ser,'r-*');
grid on;hold on;
title('Plot of Symbol error rate for Golden Code 2X1(4-QAM)','Color','k','FontSize',12);
legend('sim (nTx=2, nRx=1, Golden Code(4-QAM))','location','southwest');
xlabel('SNR(dB) ---->','Color','k','FontSize',11);Ylabel('Symbol Error rate ---->','Color','k','FontSize',11);
%%%%%%%%%%%%%%%%%%% Golden Code(4-QAM) for 2X1 %%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all;
close all;
N = 2*10^4;
M=4;
theta = (1+sqrt(5))/2;
alpha=1+1i*(1-theta);
sigma_theta=1-theta;
G=(1/sqrt(5))*[1 -sigma_theta theta 1 0 0 0 0;
sigma_theta 1 -1 theta 0 0 0 0;
0 0 0 0 -theta -1 1 -sigma_theta;
0 0 0 0 1 -theta sigma_theta 1;
0 0 0 0 1 -sigma_theta theta 1;
0 0 0 0 sigma_theta 1 -1 theta;
1 -theta sigma_theta 1 0 0 0 0;
theta 1 -1 sigma_theta 0 0 0 0];
G = repmat(transpose(G),[1 ,N/4]);
x = randint(N,1,M);
x11=reshape(x,1,N);
y1=modulate(modem.qammod(M),x);
y1=reshape(y1,1,N);
y2=[real(y1);real(1i*(-y1))];
y2=reshape(y2,8,N/4);
y4=zeros(8,2*N);
y4(:,(1:8:end))=y2;y4(:,(2:8:end))=y2;y4(:,(3:8:end))=y2;y4(:,(4:8:end))=y2;
y4(:,(5:8:end))=y2;y4(:,(6:8:end))=y2;y4(:,(7:8:end))=y2;y4(:,(8:8:end))=y2;
Gs=sum(G.*y4,1);
Gs=reshape(Gs,8,2*N/8);
h11 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h12 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h21 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h22 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h=[h11;h21;h12;h22];
h1=reshape(h,2,N/2);
h2=zeros(2,N);
h2(:,(1:2:end))=h1;
h2(:,(2:2:end))=h1;
h3=kron(h2,[1;1]);
h4=zeros(4,2*N);
h4(:,(1:8:end))=h3(:,(1:4:end));
h4(:,(5:8:end))=h3(:,(1:4:end));
h4(:,(2:8:end))=h3(:,(2:4:end));
h4(:,(6:8:end))=h3(:,(2:4:end));
h4(:,(3:8:end))=h3(:,(3:4:end));
h4(:,(7:8:end))=h3(:,(3:4:end));
h4(:,(4:8:end))=h3(:,(4:4:end));
h4(:,(8:8:end))=h3(:,(4:4:end));
h4=[h4;h4];
mat=[1 1 0 0 0 0 0 0;
1 1 0 0 0 0 0 0;
1 1 0 0 0 0 0 0;
1 1 0 0 0 0 0 0;
0 0 0 0 1 1 0 0;
0 0 0 0 1 1 0 0;
0 0 0 0 1 1 0 0;
0 0 0 0 1 1 0 0;];
mat = repmat(mat,[1 ,N/4]);
h5=mat.*h4;
h5(1,(1:8:end))= real(h5(1,(1:8:end)));h5(2,(2:8:end))= real(h5(2,(2:8:end)));
h5(3,(3:8:end))= real(h5(3,(3:8:end)));h5(4,(4:8:end))= real(h5(4,(4:8:end)));
h5(5,(5:8:end))= real(h5(5,(5:8:end)));h5(6,(6:8:end))= real(h5(6,(6:8:end)));
h5(7,(7:8:end))= real(h5(7,(7:8:end)));h5(8,(8:8:end))= real(h5(8,(8:8:end)));
h5(2,(1:8:end))=real(1i*h5(2,(1:8:end)));h5(2,(3:8:end))=real(1i*h5(2,(3:8:end)));
h5(4,(1:8:end))=real(1i*h5(4,(1:8:end)));h5(4,(3:8:end))=real(1i*h5(4,(3:8:end)));
h5(6,(5:8:end))=real(1i*h5(6,(5:8:end)));h5(6,(7:8:end))=real(1i*h5(6,(7:8:end)));
h5(8,(5:8:end))=real(1i*h5(8,(5:8:end)));h5(8,(7:8:end))=real(1i*h5(8,(7:8:end)));
h5(3,(1:8:end))=real(h5(3,(1:8:end)));h5(4,(2:8:end))=real(h5(4,(2:8:end)));
h5(1,(3:8:end))=real(h5(1,(3:8:end)));h5(2,(4:8:end))=real(h5(2,(4:8:end)));
h5(5,(7:8:end))=real(h5(5,(7:8:end)));h5(6,(8:8:end))=real(h5(6,(8:8:end)));
h5(7,(5:8:end))=real(h5(7,(5:8:end)));h5(8,(6:8:end))=real(h5(8,(6:8:end)));
h5(1,(2:8:end))=real(1i*(-h5(1,(2:8:end))));h5(1,(4:8:end))=real(1i*(-h5(1,(4:8:end))));
h5(3,(2:8:end))=real(1i*(-h5(3,(2:8:end))));h5(3,(4:8:end))=real(1i*(-h5(3,(4:8:end))));
h5(5,(6:8:end))=real(1i*(-h5(5,(6:8:end))));h5(5,(8:8:end))=real(1i*(-h5(5,(8:8:end))));
h5(7,(6:8:end))=real(1i*(-h5(7,(6:8:end))));h5(7,(8:8:end))=real(1i*(-h5(7,(8:8:end))));
Gs1=zeros(8,2*N);
Gs1(:,(1:8:end))=Gs;Gs1(:,(2:8:end))=Gs;Gs1(:,(3:8:end))=Gs;Gs1(:,(4:8:end))=Gs;
Gs1(:,(5:8:end))=Gs;Gs1(:,(6:8:end))=Gs;Gs1(:,(7:8:end))=Gs;Gs1(:,(8:8:end))=Gs;
yout1=reshape(sum(h5.*Gs1),8,N/4);
yout(1,:)=yout1(1,:);yout(2,:)=yout1(2,:);
yout(3,:)=yout1(5,:);yout(4,:)=yout1(6,:);
snr=linspace(0,20,21);
ser=zeros(1,length(snr));
for i=1:length(snr)
N1=1/sqrt(2)*(randn(1,N)+1i*randn(1,N));
N1=reshape(N1,4,N/4);
ynoisy=yout+10^(-(snr(i)-10*log10(4))/20)*N1;
rvec=[];
for ii=0:255
r=mod(ii,4);
e=mod((ii-mod(ii,4))/4,4);
w=mod((ii-mod(ii,16))/16,4);
q=mod((ii-mod(ii,64))/64,4);
xx=[q;w;e;r];
xx = repmat(xx,[N/4,1 ]);
yy1=modulate(modem.qammod(M),xx);
yy1=reshape(yy1,1,N);
yy2=[real(yy1);real(1i*(-yy1))];
yy2=reshape(yy2,8,N/4);
yy4=zeros(8,2*N);
yy4(:,(1:8:end))=yy2;yy4(:,(2:8:end))=yy2;yy4(:,(3:8:end))=yy2;yy4(:,(4:8:end))=yy2;
yy4(:,(5:8:end))=yy2;yy4(:,(6:8:end))=yy2;yy4(:,(7:8:end))=yy2;yy4(:,(8:8:end))=yy2;
GGs=sum(G.*yy4,1);
GGs=reshape(GGs,8,2*N/8);
GGs1=zeros(8,2*N);
GGs1(:,(1:8:end))=GGs;GGs1(:,(2:8:end))=GGs;GGs1(:,(3:8:end))=GGs;GGs1(:,(4:8:end))=GGs;
GGs1(:,(5:8:end))=GGs;GGs1(:,(6:8:end))=GGs;GGs1(:,(7:8:end))=GGs;GGs1(:,(8:8:end))=GGs;
yyout1=reshape(sum(h5.*GGs1),8,N/4);
yyout(1,:)=yyout1(1,:);yyout(2,:)=yyout1(2,:);
yyout(3,:)=yyout1(5,:);yyout(4,:)=yyout1(6,:);
min1=abs(ynoisy-yyout);
min1=sum(min1.*min1,1);
min1=abs(min1);
rvec=[rvec;min1];
min1=[];
end
rvec;
[jj, dd] = min(rvec,[],1);
dd=dd-1;
dd3=zeros(1,N);
dd3(:,(4:4:end))=mod(dd,4);
dd3(:,(3:4:end))=mod((dd-mod(dd,4))/4,4);
dd3(:,(2:4:end))=mod((dd-mod(dd,16))/16,4);
dd3(:,(1:4:end))=mod((dd-mod(dd,64))/64,4);
[num ty]=symerr(x11,dd3);
dd=[];
ser(i)=ty;
end
semilogy(snr,ser,'r-*');
grid on;hold on;
title('Plot of Symbol error rate for Golden Code 2X1(4-QAM)','Color','k','FontSize',12);
legend('sim (nTx=2, nRx=1, Golden Code(4-QAM))','location','southwest');
xlabel('SNR(dB) ---->','Color','k','FontSize',11);Ylabel('Symbol Error rate ---->','Color','k','FontSize',11);
Matlab Code for 2X2 using Brute force ML
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%% Golden Code(4-QAM) for 2X2 Using ML %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all;
close all;
N = 2*10^4;
M=4;
theta = (1+sqrt(5))/2;
alpha=1+1i*(1-theta);
sigma_theta=1-theta;
G=(1/sqrt(5))*[1 -sigma_theta theta 1 0 0 0 0;
sigma_theta 1 -1 theta 0 0 0 0;
0 0 0 0 -theta -1 1 -sigma_theta;
0 0 0 0 1 -theta sigma_theta 1;
0 0 0 0 1 -sigma_theta theta 1;
0 0 0 0 sigma_theta 1 -1 theta;
1 -theta sigma_theta 1 0 0 0 0;
theta 1 -1 sigma_theta 0 0 0 0];
G = repmat(transpose(G),[1 ,N/4]);
x = randint(N,1,M);
x11=reshape(x,1,N);
y1=modulate(modem.qammod(M),x);
y1=reshape(y1,1,N);
y2=[real(y1);real(1i*(-y1))];
y2=reshape(y2,8,N/4);
y4=zeros(8,2*N);
y4(:,(1:8:end))=y2;y4(:,(2:8:end))=y2;y4(:,(3:8:end))=y2;y4(:,(4:8:end))=y2;
y4(:,(5:8:end))=y2;y4(:,(6:8:end))=y2;y4(:,(7:8:end))=y2;y4(:,(8:8:end))=y2;
Gs=sum(G.*y4,1);
Gs=reshape(Gs,8,2*N/8);
hhh1 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
hhh2 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
hhh3 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
hhh4 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h=[hhh1;hhh2;hhh3;hhh4];
h1=reshape(h,2,N/2);
h2=zeros(2,N);
h2(:,(1:2:end))=h1;
h2(:,(2:2:end))=h1;
h3(1,:)=h2(1,:);
h3(2,:)=h2(1,:);
h3(3,:)=h2(2,:);
h3(4,:)=h2(2,:);
h4=zeros(4,2*N);
h4(:,(1:8:end))=h3(:,(1:4:end));
h4(:,(5:8:end))=h3(:,(1:4:end));
h4(:,(2:8:end))=h3(:,(2:4:end));
h4(:,(6:8:end))=h3(:,(2:4:end));
h4(:,(3:8:end))=h3(:,(3:4:end));
h4(:,(7:8:end))=h3(:,(3:4:end));
h4(:,(4:8:end))=h3(:,(4:4:end));
h4(:,(8:8:end))=h3(:,(4:4:end));
h4=[h4;h4];
mat=[1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;];
mat = repmat(mat,[1 ,N/4]);
h5=mat.*h4;
h5(1,(1:8:end))= real(h5(1,(1:8:end)));h5(2,(2:8:end))= real(h5(2,(2:8:end)));
h5(3,(3:8:end))= real(h5(3,(3:8:end)));h5(4,(4:8:end))= real(h5(4,(4:8:end)));
h5(5,(5:8:end))= real(h5(5,(5:8:end)));h5(6,(6:8:end))= real(h5(6,(6:8:end)));
h5(7,(7:8:end))= real(h5(7,(7:8:end)));h5(8,(8:8:end))= real(h5(8,(8:8:end)));
h5(2,(1:8:end))=real(1i*h5(2,(1:8:end)));h5(2,(3:8:end))=real(1i*h5(2,(3:8:end)));
h5(4,(1:8:end))=real(1i*h5(4,(1:8:end)));h5(4,(3:8:end))=real(1i*h5(4,(3:8:end)));
h5(6,(5:8:end))=real(1i*h5(6,(5:8:end)));h5(6,(7:8:end))=real(1i*h5(6,(7:8:end)));
h5(8,(5:8:end))=real(1i*h5(8,(5:8:end)));h5(8,(7:8:end))=real(1i*h5(8,(7:8:end)));
h5(3,(1:8:end))=real(h5(3,(1:8:end)));h5(4,(2:8:end))=real(h5(4,(2:8:end)));
h5(1,(3:8:end))=real(h5(1,(3:8:end)));h5(2,(4:8:end))=real(h5(2,(4:8:end)));
h5(5,(7:8:end))=real(h5(5,(7:8:end)));h5(6,(8:8:end))=real(h5(6,(8:8:end)));
h5(7,(5:8:end))=real(h5(7,(5:8:end)));h5(8,(6:8:end))=real(h5(8,(6:8:end)));
h5(1,(2:8:end))=real(1i*(-h5(1,(2:8:end))));h5(1,(4:8:end))=real(1i*(-h5(1,(4:8:end))));
h5(3,(2:8:end))=real(1i*(-h5(3,(2:8:end))));h5(3,(4:8:end))=real(1i*(-h5(3,(4:8:end))));
h5(5,(6:8:end))=real(1i*(-h5(5,(6:8:end))));h5(5,(8:8:end))=real(1i*(-h5(5,(8:8:end))));
h5(7,(6:8:end))=real(1i*(-h5(7,(6:8:end))));h5(7,(8:8:end))=real(1i*(-h5(7,(8:8:end))));
Gs1=zeros(8,2*N);
Gs1(:,(1:8:end))=Gs;Gs1(:,(2:8:end))=Gs;Gs1(:,(3:8:end))=Gs;Gs1(:,(4:8:end))=Gs;
Gs1(:,(5:8:end))=Gs;Gs1(:,(6:8:end))=Gs;Gs1(:,(7:8:end))=Gs;Gs1(:,(8:8:end))=Gs;
yout=reshape(sum(h5.*Gs1),8,N/4);
ser=[];ber=[];
snr=linspace(0,16,17);
for i=1:length(snr)
N1=1/sqrt(2)*(randn(1,2*N)+1i*randn(1,2*N));
N1=reshape(N1,8,N/4);
ynoisy=yout+10^(-(snr(i)-10*log10(4))/20)*N1;
rvec=[];
for ii=0:255
r=mod(ii,4);
e=mod((ii-mod(ii,4))/4,4);
w=mod((ii-mod(ii,16))/16,4);
q=mod((ii-mod(ii,64))/64,4);
xx=[q;w;e;r];
xx = repmat(xx,[N/4,1 ]);
yy1=modulate(modem.qammod(M),xx);
yy1=reshape(yy1,1,N);
yy2=[real(yy1);real(1i*(-yy1))];
yy2=reshape(yy2,8,N/4);
yy4=zeros(8,2*N);
yy4(:,(1:8:end))=yy2;yy4(:,(2:8:end))=yy2;yy4(:,(3:8:end))=yy2;yy4(:,(4:8:end))=yy2;
yy4(:,(5:8:end))=yy2;yy4(:,(6:8:end))=yy2;yy4(:,(7:8:end))=yy2;yy4(:,(8:8:end))=yy2;
GGs=sum(G.*yy4,1);
GGs=reshape(GGs,8,2*N/8);
GGs1=zeros(8,2*N);
GGs1(:,(1:8:end))=GGs;GGs1(:,(2:8:end))=GGs;GGs1(:,(3:8:end))=GGs;GGs1(:,(4:8:end))=GGs;
GGs1(:,(5:8:end))=GGs;GGs1(:,(6:8:end))=GGs;GGs1(:,(7:8:end))=GGs;GGs1(:,(8:8:end))=GGs;
yyout=reshape(sum(h5.*GGs1),8,N/4);
min1=abs(ynoisy-yyout);
min1=sum(min1.*min1,1);
min1=abs(min1);
rvec=[rvec;min1];
min1=[];
end
rvec;
[jj, dd] = min(rvec,[],1);
dd=dd-1;
dd3=zeros(1,N);
dd3(:,(4:4:end))=mod(dd,4);
dd3(:,(3:4:end))=mod((dd-mod(dd,4))/4,4);
dd3(:,(2:4:end))=mod((dd-mod(dd,16))/16,4);
dd3(:,(1:4:end))=mod((dd-mod(dd,64))/64,4);
[num ty]=symerr(x11,dd3);
dd=[];
ser=[ser,ty];
end
semilogy(snr,ser,'r-*');
grid on;hold on;
title('Plot of Symbol error rate for Golden Code 2X2(4-QAM)','Color','k','FontSize',12);
legend('sim (nTx=2, nRx=2, Golden Code(4-QAM)) Using ML','location','southwest');
xlabel('SNR(dB) ---->','Color','k','FontSize',11);Ylabel('Symbol Error rate ---->','Color','k','FontSize',11);
Matlab Code for 2X2 using Sphere Decoder
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% Golden Code(4-QAM) for 2X2 Using Sphere Decoder %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all;
close all;
N = 2*10^4;
M=4;
theta = (1+sqrt(5))/2;
alpha=1+1i*(1-theta);
sigma_theta=1-theta;
G1=(1/sqrt(5))*[1 -sigma_theta theta 1 0 0 0 0;
sigma_theta 1 -1 theta 0 0 0 0;
0 0 0 0 -theta -1 1 -sigma_theta;
0 0 0 0 1 -theta sigma_theta 1;
0 0 0 0 1 -sigma_theta theta 1;
0 0 0 0 sigma_theta 1 -1 theta;
1 -theta sigma_theta 1 0 0 0 0;
theta 1 -1 sigma_theta 0 0 0 0];
G = repmat(transpose(G1),[1 ,N/4]);
x = randint(N,1,M);
x11=reshape(x,1,N);
y1=modulate(modem.qammod(M),x);
y1=reshape(y1,1,N);
y2=[real(y1);real(1i*(-y1))];
y2=reshape(y2,8,N/4);
y4=zeros(8,2*N);
y4(:,(1:8:end))=y2;y4(:,(2:8:end))=y2;y4(:,(3:8:end))=y2;y4(:,(4:8:end))=y2;
y4(:,(5:8:end))=y2;y4(:,(6:8:end))=y2;y4(:,(7:8:end))=y2;y4(:,(8:8:end))=y2;
Gs=sum(G.*y4,1);
Gs=reshape(Gs,8,2*N/8);
h11 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h12 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h21 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h22 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h=[h11;h12;h21;h22];
h1=reshape(h,2,N/2);
h2=zeros(2,N);
h2(:,(1:2:end))=h1;
h2(:,(2:2:end))=h1;
h3(1,:)=h2(1,:);
h3(2,:)=h2(1,:);
h3(3,:)=h2(2,:);
h3(4,:)=h2(2,:);
h4=zeros(4,2*N);
h4(:,(1:8:end))=h3(:,(1:4:end));
h4(:,(5:8:end))=h3(:,(1:4:end));
h4(:,(2:8:end))=h3(:,(2:4:end));
h4(:,(6:8:end))=h3(:,(2:4:end));
h4(:,(3:8:end))=h3(:,(3:4:end));
h4(:,(7:8:end))=h3(:,(3:4:end));
h4(:,(4:8:end))=h3(:,(4:4:end));
h4(:,(8:8:end))=h3(:,(4:4:end));
h4=[h4;h4];
mat=[1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;];
mat = repmat(mat,[1 ,N/4]);
h5=mat.*h4;
h5(1,(1:8:end))= real(h5(1,(1:8:end)));h5(2,(2:8:end))= real(h5(2,(2:8:end)));
h5(3,(3:8:end))= real(h5(3,(3:8:end)));h5(4,(4:8:end))= real(h5(4,(4:8:end)));
h5(5,(5:8:end))= real(h5(5,(5:8:end)));h5(6,(6:8:end))= real(h5(6,(6:8:end)));
h5(7,(7:8:end))= real(h5(7,(7:8:end)));h5(8,(8:8:end))= real(h5(8,(8:8:end)));
h5(2,(1:8:end))=real(1i*h5(2,(1:8:end)));h5(2,(3:8:end))=real(1i*h5(2,(3:8:end)));
h5(4,(1:8:end))=real(1i*h5(4,(1:8:end)));h5(4,(3:8:end))=real(1i*h5(4,(3:8:end)));
h5(6,(5:8:end))=real(1i*h5(6,(5:8:end)));h5(6,(7:8:end))=real(1i*h5(6,(7:8:end)));
h5(8,(5:8:end))=real(1i*h5(8,(5:8:end)));h5(8,(7:8:end))=real(1i*h5(8,(7:8:end)));
h5(3,(1:8:end))=real(h5(3,(1:8:end)));h5(4,(2:8:end))=real(h5(4,(2:8:end)));
h5(1,(3:8:end))=real(h5(1,(3:8:end)));h5(2,(4:8:end))=real(h5(2,(4:8:end)));
h5(5,(7:8:end))=real(h5(5,(7:8:end)));h5(6,(8:8:end))=real(h5(6,(8:8:end)));
h5(7,(5:8:end))=real(h5(7,(5:8:end)));h5(8,(6:8:end))=real(h5(8,(6:8:end)));
h5(1,(2:8:end))=real(1i*(-h5(1,(2:8:end))));h5(1,(4:8:end))=real(1i*(-h5(1,(4:8:end))));
h5(3,(2:8:end))=real(1i*(-h5(3,(2:8:end))));h5(3,(4:8:end))=real(1i*(-h5(3,(4:8:end))));
h5(5,(6:8:end))=real(1i*(-h5(5,(6:8:end))));h5(5,(8:8:end))=real(1i*(-h5(5,(8:8:end))));
h5(7,(6:8:end))=real(1i*(-h5(7,(6:8:end))));h5(7,(8:8:end))=real(1i*(-h5(7,(8:8:end))));
Gs1=zeros(8,2*N);
Gs1(:,(1:8:end))=Gs;Gs1(:,(2:8:end))=Gs;Gs1(:,(3:8:end))=Gs;Gs1(:,(4:8:end))=Gs;
Gs1(:,(5:8:end))=Gs;Gs1(:,(6:8:end))=Gs;Gs1(:,(7:8:end))=Gs;Gs1(:,(8:8:end))=Gs;
yout=reshape(sum(h5.*Gs1),8,N/4);
ser1=[];
%%%%%%%%%%%%%%% Golden Code(4-QAM) for 2X2 Using ML %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all;
close all;
N = 2*10^4;
M=4;
theta = (1+sqrt(5))/2;
alpha=1+1i*(1-theta);
sigma_theta=1-theta;
G=(1/sqrt(5))*[1 -sigma_theta theta 1 0 0 0 0;
sigma_theta 1 -1 theta 0 0 0 0;
0 0 0 0 -theta -1 1 -sigma_theta;
0 0 0 0 1 -theta sigma_theta 1;
0 0 0 0 1 -sigma_theta theta 1;
0 0 0 0 sigma_theta 1 -1 theta;
1 -theta sigma_theta 1 0 0 0 0;
theta 1 -1 sigma_theta 0 0 0 0];
G = repmat(transpose(G),[1 ,N/4]);
x = randint(N,1,M);
x11=reshape(x,1,N);
y1=modulate(modem.qammod(M),x);
y1=reshape(y1,1,N);
y2=[real(y1);real(1i*(-y1))];
y2=reshape(y2,8,N/4);
y4=zeros(8,2*N);
y4(:,(1:8:end))=y2;y4(:,(2:8:end))=y2;y4(:,(3:8:end))=y2;y4(:,(4:8:end))=y2;
y4(:,(5:8:end))=y2;y4(:,(6:8:end))=y2;y4(:,(7:8:end))=y2;y4(:,(8:8:end))=y2;
Gs=sum(G.*y4,1);
Gs=reshape(Gs,8,2*N/8);
hhh1 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
hhh2 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
hhh3 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
hhh4 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h=[hhh1;hhh2;hhh3;hhh4];
h1=reshape(h,2,N/2);
h2=zeros(2,N);
h2(:,(1:2:end))=h1;
h2(:,(2:2:end))=h1;
h3(1,:)=h2(1,:);
h3(2,:)=h2(1,:);
h3(3,:)=h2(2,:);
h3(4,:)=h2(2,:);
h4=zeros(4,2*N);
h4(:,(1:8:end))=h3(:,(1:4:end));
h4(:,(5:8:end))=h3(:,(1:4:end));
h4(:,(2:8:end))=h3(:,(2:4:end));
h4(:,(6:8:end))=h3(:,(2:4:end));
h4(:,(3:8:end))=h3(:,(3:4:end));
h4(:,(7:8:end))=h3(:,(3:4:end));
h4(:,(4:8:end))=h3(:,(4:4:end));
h4(:,(8:8:end))=h3(:,(4:4:end));
h4=[h4;h4];
mat=[1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;];
mat = repmat(mat,[1 ,N/4]);
h5=mat.*h4;
h5(1,(1:8:end))= real(h5(1,(1:8:end)));h5(2,(2:8:end))= real(h5(2,(2:8:end)));
h5(3,(3:8:end))= real(h5(3,(3:8:end)));h5(4,(4:8:end))= real(h5(4,(4:8:end)));
h5(5,(5:8:end))= real(h5(5,(5:8:end)));h5(6,(6:8:end))= real(h5(6,(6:8:end)));
h5(7,(7:8:end))= real(h5(7,(7:8:end)));h5(8,(8:8:end))= real(h5(8,(8:8:end)));
h5(2,(1:8:end))=real(1i*h5(2,(1:8:end)));h5(2,(3:8:end))=real(1i*h5(2,(3:8:end)));
h5(4,(1:8:end))=real(1i*h5(4,(1:8:end)));h5(4,(3:8:end))=real(1i*h5(4,(3:8:end)));
h5(6,(5:8:end))=real(1i*h5(6,(5:8:end)));h5(6,(7:8:end))=real(1i*h5(6,(7:8:end)));
h5(8,(5:8:end))=real(1i*h5(8,(5:8:end)));h5(8,(7:8:end))=real(1i*h5(8,(7:8:end)));
h5(3,(1:8:end))=real(h5(3,(1:8:end)));h5(4,(2:8:end))=real(h5(4,(2:8:end)));
h5(1,(3:8:end))=real(h5(1,(3:8:end)));h5(2,(4:8:end))=real(h5(2,(4:8:end)));
h5(5,(7:8:end))=real(h5(5,(7:8:end)));h5(6,(8:8:end))=real(h5(6,(8:8:end)));
h5(7,(5:8:end))=real(h5(7,(5:8:end)));h5(8,(6:8:end))=real(h5(8,(6:8:end)));
h5(1,(2:8:end))=real(1i*(-h5(1,(2:8:end))));h5(1,(4:8:end))=real(1i*(-h5(1,(4:8:end))));
h5(3,(2:8:end))=real(1i*(-h5(3,(2:8:end))));h5(3,(4:8:end))=real(1i*(-h5(3,(4:8:end))));
h5(5,(6:8:end))=real(1i*(-h5(5,(6:8:end))));h5(5,(8:8:end))=real(1i*(-h5(5,(8:8:end))));
h5(7,(6:8:end))=real(1i*(-h5(7,(6:8:end))));h5(7,(8:8:end))=real(1i*(-h5(7,(8:8:end))));
Gs1=zeros(8,2*N);
Gs1(:,(1:8:end))=Gs;Gs1(:,(2:8:end))=Gs;Gs1(:,(3:8:end))=Gs;Gs1(:,(4:8:end))=Gs;
Gs1(:,(5:8:end))=Gs;Gs1(:,(6:8:end))=Gs;Gs1(:,(7:8:end))=Gs;Gs1(:,(8:8:end))=Gs;
yout=reshape(sum(h5.*Gs1),8,N/4);
ser=[];ber=[];
snr=linspace(0,16,17);
for i=1:length(snr)
N1=1/sqrt(2)*(randn(1,2*N)+1i*randn(1,2*N));
N1=reshape(N1,8,N/4);
ynoisy=yout+10^(-(snr(i)-10*log10(4))/20)*N1;
rvec=[];
for ii=0:255
r=mod(ii,4);
e=mod((ii-mod(ii,4))/4,4);
w=mod((ii-mod(ii,16))/16,4);
q=mod((ii-mod(ii,64))/64,4);
xx=[q;w;e;r];
xx = repmat(xx,[N/4,1 ]);
yy1=modulate(modem.qammod(M),xx);
yy1=reshape(yy1,1,N);
yy2=[real(yy1);real(1i*(-yy1))];
yy2=reshape(yy2,8,N/4);
yy4=zeros(8,2*N);
yy4(:,(1:8:end))=yy2;yy4(:,(2:8:end))=yy2;yy4(:,(3:8:end))=yy2;yy4(:,(4:8:end))=yy2;
yy4(:,(5:8:end))=yy2;yy4(:,(6:8:end))=yy2;yy4(:,(7:8:end))=yy2;yy4(:,(8:8:end))=yy2;
GGs=sum(G.*yy4,1);
GGs=reshape(GGs,8,2*N/8);
GGs1=zeros(8,2*N);
GGs1(:,(1:8:end))=GGs;GGs1(:,(2:8:end))=GGs;GGs1(:,(3:8:end))=GGs;GGs1(:,(4:8:end))=GGs;
GGs1(:,(5:8:end))=GGs;GGs1(:,(6:8:end))=GGs;GGs1(:,(7:8:end))=GGs;GGs1(:,(8:8:end))=GGs;
yyout=reshape(sum(h5.*GGs1),8,N/4);
min1=abs(ynoisy-yyout);
min1=sum(min1.*min1,1);
min1=abs(min1);
rvec=[rvec;min1];
min1=[];
end
rvec;
[jj, dd] = min(rvec,[],1);
dd=dd-1;
dd3=zeros(1,N);
dd3(:,(4:4:end))=mod(dd,4);
dd3(:,(3:4:end))=mod((dd-mod(dd,4))/4,4);
dd3(:,(2:4:end))=mod((dd-mod(dd,16))/16,4);
dd3(:,(1:4:end))=mod((dd-mod(dd,64))/64,4);
[num ty]=symerr(x11,dd3);
dd=[];
ser=[ser,ty];
end
semilogy(snr,ser,'r-*');
grid on;hold on;
title('Plot of Symbol error rate for Golden Code 2X2(4-QAM)','Color','k','FontSize',12);
legend('sim (nTx=2, nRx=2, Golden Code(4-QAM)) Using ML','location','southwest');
xlabel('SNR(dB) ---->','Color','k','FontSize',11);Ylabel('Symbol Error rate ---->','Color','k','FontSize',11);
Matlab Code for 2X2 using Sphere Decoder
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% Golden Code(4-QAM) for 2X2 Using Sphere Decoder %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all;
close all;
N = 2*10^4;
M=4;
theta = (1+sqrt(5))/2;
alpha=1+1i*(1-theta);
sigma_theta=1-theta;
G1=(1/sqrt(5))*[1 -sigma_theta theta 1 0 0 0 0;
sigma_theta 1 -1 theta 0 0 0 0;
0 0 0 0 -theta -1 1 -sigma_theta;
0 0 0 0 1 -theta sigma_theta 1;
0 0 0 0 1 -sigma_theta theta 1;
0 0 0 0 sigma_theta 1 -1 theta;
1 -theta sigma_theta 1 0 0 0 0;
theta 1 -1 sigma_theta 0 0 0 0];
G = repmat(transpose(G1),[1 ,N/4]);
x = randint(N,1,M);
x11=reshape(x,1,N);
y1=modulate(modem.qammod(M),x);
y1=reshape(y1,1,N);
y2=[real(y1);real(1i*(-y1))];
y2=reshape(y2,8,N/4);
y4=zeros(8,2*N);
y4(:,(1:8:end))=y2;y4(:,(2:8:end))=y2;y4(:,(3:8:end))=y2;y4(:,(4:8:end))=y2;
y4(:,(5:8:end))=y2;y4(:,(6:8:end))=y2;y4(:,(7:8:end))=y2;y4(:,(8:8:end))=y2;
Gs=sum(G.*y4,1);
Gs=reshape(Gs,8,2*N/8);
h11 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h12 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h21 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h22 = 1/sqrt(2)*(randn(1,N/4) + 1i*randn(1,N/4));
h=[h11;h12;h21;h22];
h1=reshape(h,2,N/2);
h2=zeros(2,N);
h2(:,(1:2:end))=h1;
h2(:,(2:2:end))=h1;
h3(1,:)=h2(1,:);
h3(2,:)=h2(1,:);
h3(3,:)=h2(2,:);
h3(4,:)=h2(2,:);
h4=zeros(4,2*N);
h4(:,(1:8:end))=h3(:,(1:4:end));
h4(:,(5:8:end))=h3(:,(1:4:end));
h4(:,(2:8:end))=h3(:,(2:4:end));
h4(:,(6:8:end))=h3(:,(2:4:end));
h4(:,(3:8:end))=h3(:,(3:4:end));
h4(:,(7:8:end))=h3(:,(3:4:end));
h4(:,(4:8:end))=h3(:,(4:4:end));
h4(:,(8:8:end))=h3(:,(4:4:end));
h4=[h4;h4];
mat=[1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;
0 0 0 0 1 1 1 1;];
mat = repmat(mat,[1 ,N/4]);
h5=mat.*h4;
h5(1,(1:8:end))= real(h5(1,(1:8:end)));h5(2,(2:8:end))= real(h5(2,(2:8:end)));
h5(3,(3:8:end))= real(h5(3,(3:8:end)));h5(4,(4:8:end))= real(h5(4,(4:8:end)));
h5(5,(5:8:end))= real(h5(5,(5:8:end)));h5(6,(6:8:end))= real(h5(6,(6:8:end)));
h5(7,(7:8:end))= real(h5(7,(7:8:end)));h5(8,(8:8:end))= real(h5(8,(8:8:end)));
h5(2,(1:8:end))=real(1i*h5(2,(1:8:end)));h5(2,(3:8:end))=real(1i*h5(2,(3:8:end)));
h5(4,(1:8:end))=real(1i*h5(4,(1:8:end)));h5(4,(3:8:end))=real(1i*h5(4,(3:8:end)));
h5(6,(5:8:end))=real(1i*h5(6,(5:8:end)));h5(6,(7:8:end))=real(1i*h5(6,(7:8:end)));
h5(8,(5:8:end))=real(1i*h5(8,(5:8:end)));h5(8,(7:8:end))=real(1i*h5(8,(7:8:end)));
h5(3,(1:8:end))=real(h5(3,(1:8:end)));h5(4,(2:8:end))=real(h5(4,(2:8:end)));
h5(1,(3:8:end))=real(h5(1,(3:8:end)));h5(2,(4:8:end))=real(h5(2,(4:8:end)));
h5(5,(7:8:end))=real(h5(5,(7:8:end)));h5(6,(8:8:end))=real(h5(6,(8:8:end)));
h5(7,(5:8:end))=real(h5(7,(5:8:end)));h5(8,(6:8:end))=real(h5(8,(6:8:end)));
h5(1,(2:8:end))=real(1i*(-h5(1,(2:8:end))));h5(1,(4:8:end))=real(1i*(-h5(1,(4:8:end))));
h5(3,(2:8:end))=real(1i*(-h5(3,(2:8:end))));h5(3,(4:8:end))=real(1i*(-h5(3,(4:8:end))));
h5(5,(6:8:end))=real(1i*(-h5(5,(6:8:end))));h5(5,(8:8:end))=real(1i*(-h5(5,(8:8:end))));
h5(7,(6:8:end))=real(1i*(-h5(7,(6:8:end))));h5(7,(8:8:end))=real(1i*(-h5(7,(8:8:end))));
Gs1=zeros(8,2*N);
Gs1(:,(1:8:end))=Gs;Gs1(:,(2:8:end))=Gs;Gs1(:,(3:8:end))=Gs;Gs1(:,(4:8:end))=Gs;
Gs1(:,(5:8:end))=Gs;Gs1(:,(6:8:end))=Gs;Gs1(:,(7:8:end))=Gs;Gs1(:,(8:8:end))=Gs;
yout=reshape(sum(h5.*Gs1),8,N/4);
ser1=[];
snr=linspace(0,10,11);
for jj=1:length(snr)
N1=1/sqrt(2)*(randn(1,2*N)+1i*randn(1,2*N));
N1=reshape(N1,8,N/4);
%ynoisy=yout+10^(-(snr(i)-10*log10(4))/20)*N1;
ynoisy=awgn(yout,snr(jj),'measured');
ynoisy1=reshape(ynoisy,8,1,N/4);
xoutput=[];
ydemod=[];
for kk=1:N/4
%%%%%%%%%%%%%%% Forming CHannel Matrix %%%%%%%%%%%%%%%%
H11 = h11(kk);
H12 = h12(kk);
H21 = h21(kk);
H22 = h22(kk);
H=[ real(H11) -imag(H11) real(H12) -imag(H12) 0 0 0 0;
imag(H11) real(H11) imag(H12) real(H12) 0 0 0 0;
real(H21) -imag(H21) real(H22) -imag(H22) 0 0 0 0;
imag(H21) real(H21) imag(H22) real(H22) 0 0 0 0;
0 0 0 0 real(H11) -imag(H11) real(H12) -imag(H12);
0 0 0 0 imag(H11) real(H11) imag(H12) real(H12);
0 0 0 0 real(H21) -imag(H21) real(H22) -imag(H22);
0 0 0 0 imag(H21) real(H21) imag(H22) real(H22);];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BChannel=H*G1;
[Q R]=qr(BChannel);
ydash=transpose(Q)*ynoisy1(:,:,kk);
i=8;c0=5;dc=c0;
T=zeros(1,8);x=zeros(1,8);
B=zeros(1,8);A=zeros(1,8);
E=zeros(1,8);
ii=2;
path=[];
came=0;
while ii<7
if ii==2
if dc<T(i)
ii=4;
else
A(i)=max(0,ceil(((1/R(i,i))*(ydash(i)-E(i)-sqrt(dc-T(i)))+1)/2));
B(i)=min(1,floor(((1/R(i,i))*(ydash(i)-E(i)+sqrt(dc-T(i)))+1)/2));
x(i)=A(i)-1;
ii=3;
end
end
if ii==3
x(i)=x(i)+1;
if x(i)<=B(i)
ii=5;
else
ii=4;
end
end
if ii==4
if i==8
ii=7;
if came==0
dc=dc+5;
ii=2;
end
else
i=i+1;
ii=3;
end
end
if ii==5
if i>1
T(i-1)=0;
E(i-1)=0;
for j=i:8
E(i-1)=R(i-1,j)*(2*x(j)-1)+E(i-1);
end
T(i-1)=T(i)+(ydash(i)-E(i)-R(i,i)*(2*x(i)-1))^2;
i=i-1;
ii=2;
else
ii=6;
end
end
if ii==6
dcap=T(1)+(ydash(1)-E(1)-R(1,1)*(2*x(1)-1))^2;
if dcap<dc
dc=dcap;
xcap=2*x-1;
came=1;
for k=1:8
B(k)=min(1,floor((1/R(k,k))*(ydash(k)-E(k)+sqrt(dc-T(k)))));
end
ii=3;
else
ii=7;
end
end
end
xcap=reshape(xcap,2,4);
recvd=xcap(1,:)+1i*xcap(2,:);
xdemod=qamdemod(recvd,M);
xoutput=[xoutput,xdemod];
end
[num ty]=symerr(xoutput,x11);
ser1=[ser1,ty];
end
semilogy(snr,ser1,'r-*');
grid on;hold on;
title('Plot of Symbol error rate for Golden Code 2X2(4-QAM)','Color','k','FontSize',12);
legend('sim (nTx=2, nRx=2, Golden Code(4-QAM)) Using Sphere Decoder','location','southwest');
xlabel('SNR(dB) ---->','Color','k','FontSize',11);Ylabel('Symbol Error rate ---->','Color','k','FontSize',11);
for jj=1:length(snr)
N1=1/sqrt(2)*(randn(1,2*N)+1i*randn(1,2*N));
N1=reshape(N1,8,N/4);
%ynoisy=yout+10^(-(snr(i)-10*log10(4))/20)*N1;
ynoisy=awgn(yout,snr(jj),'measured');
ynoisy1=reshape(ynoisy,8,1,N/4);
xoutput=[];
ydemod=[];
for kk=1:N/4
%%%%%%%%%%%%%%% Forming CHannel Matrix %%%%%%%%%%%%%%%%
H11 = h11(kk);
H12 = h12(kk);
H21 = h21(kk);
H22 = h22(kk);
H=[ real(H11) -imag(H11) real(H12) -imag(H12) 0 0 0 0;
imag(H11) real(H11) imag(H12) real(H12) 0 0 0 0;
real(H21) -imag(H21) real(H22) -imag(H22) 0 0 0 0;
imag(H21) real(H21) imag(H22) real(H22) 0 0 0 0;
0 0 0 0 real(H11) -imag(H11) real(H12) -imag(H12);
0 0 0 0 imag(H11) real(H11) imag(H12) real(H12);
0 0 0 0 real(H21) -imag(H21) real(H22) -imag(H22);
0 0 0 0 imag(H21) real(H21) imag(H22) real(H22);];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BChannel=H*G1;
[Q R]=qr(BChannel);
ydash=transpose(Q)*ynoisy1(:,:,kk);
i=8;c0=5;dc=c0;
T=zeros(1,8);x=zeros(1,8);
B=zeros(1,8);A=zeros(1,8);
E=zeros(1,8);
ii=2;
path=[];
came=0;
while ii<7
if ii==2
if dc<T(i)
ii=4;
else
A(i)=max(0,ceil(((1/R(i,i))*(ydash(i)-E(i)-sqrt(dc-T(i)))+1)/2));
B(i)=min(1,floor(((1/R(i,i))*(ydash(i)-E(i)+sqrt(dc-T(i)))+1)/2));
x(i)=A(i)-1;
ii=3;
end
end
if ii==3
x(i)=x(i)+1;
if x(i)<=B(i)
ii=5;
else
ii=4;
end
end
if ii==4
if i==8
ii=7;
if came==0
dc=dc+5;
ii=2;
end
else
i=i+1;
ii=3;
end
end
if ii==5
if i>1
T(i-1)=0;
E(i-1)=0;
for j=i:8
E(i-1)=R(i-1,j)*(2*x(j)-1)+E(i-1);
end
T(i-1)=T(i)+(ydash(i)-E(i)-R(i,i)*(2*x(i)-1))^2;
i=i-1;
ii=2;
else
ii=6;
end
end
if ii==6
dcap=T(1)+(ydash(1)-E(1)-R(1,1)*(2*x(1)-1))^2;
if dcap<dc
dc=dcap;
xcap=2*x-1;
came=1;
for k=1:8
B(k)=min(1,floor((1/R(k,k))*(ydash(k)-E(k)+sqrt(dc-T(k)))));
end
ii=3;
else
ii=7;
end
end
end
xcap=reshape(xcap,2,4);
recvd=xcap(1,:)+1i*xcap(2,:);
xdemod=qamdemod(recvd,M);
xoutput=[xoutput,xdemod];
end
[num ty]=symerr(xoutput,x11);
ser1=[ser1,ty];
end
semilogy(snr,ser1,'r-*');
grid on;hold on;
title('Plot of Symbol error rate for Golden Code 2X2(4-QAM)','Color','k','FontSize',12);
legend('sim (nTx=2, nRx=2, Golden Code(4-QAM)) Using Sphere Decoder','location','southwest');
xlabel('SNR(dB) ---->','Color','k','FontSize',11);Ylabel('Symbol Error rate ---->','Color','k','FontSize',11);