📄 mapping_ber.m
字号:
%signal constellation arrangement scheme
SNR=0:5:30;
Nt=4;
Nr=4;
M=16;
SymTime=10;
packetNum=100;
const=[1+j,1+j*3,3+j,3+j*3,1-j,1-3*j,3-j,3-3*j,-1+j,-1+3*j,-3+j,-3+3*j,-1-j,-1-3*j,-3-j,-3-3*j];
bin1=[];bin2=[];bin3=[];bin4=[];
bit1=[];bit3=[];averber=[];averber1=[];averber2=[];
for SNRindex=1:length(SNR)
K=SNR(SNRindex);
BER=0; BER1=0;BER2=0;
for packetindex=1:packetNum
H=(randn(Nr,Nt)+j*randn(Nr,Nt))/sqrt(2);
for t=1:SymTime
transtime=1; transtime1=1;
bin1=randint(Nt,4);
str1=num2str(bin1);
data=bin2dec(str1);
a=genqammod(data,const);
r=awgn(H*a,SNR(SNRindex),'measured');
out=blastdetect_16qam(H,Nt,r,M);
[number ratio]=biterr(data,out);
ratio1=ratio;
x=real(genqammod(out,const));
for m=1:Nt
LLR1(m)=logm((exp(-K*(x(m)+1).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)-3).^2)));
LLR2(m)=logm((exp(-K*(x(m)-3).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)+1).^2)));
end
LLR_1=LLR1;
LLR_2=LLR2;
for condition=1:3
switch condition
case 1
if ratio~=0 %the second transmission
bin2(:,1:2)=bin1(:,3:4);
bin2(:,3:4)=~bin1(:,1:2);
str2=num2str(bin2);
data2=bin2dec(str2);
a=genqammod(data2,const);
r=awgn(H*a,SNR(SNRindex),'measured');
record_r=r;
out=blastdetect_16qam(H,Nt,r,M);
rec1=dec2bin(out);
if size(rec1,2)==4
rec=[~str2num(rec1(:,3)),~str2num(rec1(:,4)),str2num(rec1(:,1)),str2num(rec1(:,2))];
elseif size(rec1,2)==3
rec=[~str2num(rec1(:,2)),~str2num(rec1(:,3)),zeros(Nt,1),str2num(rec1(:,1))];
elseif size(rec1,2)==2
rec=[~str2num(rec1(:,1)),~str2num(rec1(:,2)),zeros(Nt,1),zeros(Nt,1)];
else
rec=[~zeros(Nt,1),~str2num(rec1(:,1)),zeros(Nt,1),zeros(Nt,1)];
end
out=bin2dec(num2str(rec));
x=real(genqammod(out,const));
for m=1:Nt
LLR1(m)=logm((exp(-K*(x(m)+1).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)-3).^2)))+LLR1(m);
LLR2(m)=logm((exp(-K*(x(m)-3).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)+1).^2)))+LLR2(m);
end
for m=1:Nt
if LLR1(m)>0
bit1(m,1)=1;
else
bit1(m,1)=0;
end
if LLR2(m)>0
bit3(m,1)=1;
else
bit3(m,1)=0;
end
end
combined_rec=[bit1,rec(:,2),bit3,rec(:,4)];
[number ratio]=biterr(data,bin2dec(num2str(combined_rec)));
if ratio~=0 %the third transmission
bin3(:,1:2)=bin1(:,3:4);
bin3(:,3:4)=bin1(:,1:2);
str3=num2str(bin3);
data3=bin2dec(str3);
a=genqammod(data3,const);
r=awgn(H*a,SNR(SNRindex),'measured');
out=blastdetect_16qam(H,Nt,r,M);
rec1=dec2bin(out);
if size(rec1,2)==4
rec=[str2num(rec1(:,3)),str2num(rec1(:,4)),str2num(rec1(:,1)),str2num(rec1(:,2))];
elseif size(rec1,2)==3
rec=[str2num(rec1(:,2)),str2num(rec1(:,3)),zeros(Nt,1),str2num(rec1(:,1))];
elseif size(rec1,2)==2
rec=[str2num(rec1(:,1)),str2num(rec1(:,2)),zeros(Nt,1),zeros(Nt,1)];
else
rec=[zeros(Nt,1),str2num(rec1(:,1)),zeros(Nt,1),zeros(Nt,1)];
end
out=bin2dec(num2str(rec));
x=real(genqammod(out,const));
for m=1:Nt
LLR1(m)=logm((exp(-K*(x(m)+1).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)-3).^2)))+LLR1(m);
LLR2(m)=logm((exp(-K*(x(m)-3).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)+1).^2)))+LLR2(m);
end
for m=1:Nt
if LLR1(m)>0
bit1(m,1)=1;
else
bit1(m,1)=0;
end
if LLR2(m)>0
bit3(m,1)=1;
else
bit3(m,1)=0;
end
end
combined_rec=[bit1,rec(:,2),bit3,rec(:,4)];
[number ratio]=biterr(data,bin2dec(num2str(combined_rec)));
if ratio~=0 %the fourth transmission
bin4(:,1:2)=bin1(:,1:2);
bin4(:,3:4)=~bin1(:,3:4);
str4=num2str(bin4);
data4=bin2dec(str4);
a=genqammod(data4,const);
r=awgn(H*a,SNR(SNRindex),'measured');
out=blastdetect_16qam(H,Nt,r,M);
rec1=dec2bin(out);
if size(rec1,2)==4
rec=[str2num(rec1(:,1)),str2num(rec1(:,2)),~str2num(rec1(:,3)),~str2num(rec1(:,4))];
elseif size(rec1,2)==3
rec=[zeros(Nt,1),str2num(rec1(:,1)),~str2num(rec1(:,2)),~str2num(rec1(:,3))];
elseif size(rec1,2)==2
rec=[zeros(Nt,1),zeros(Nt,1),~str2num(rec1(:,1)),~str2num(rec1(:,2))];
else
rec=[zeros(Nt,1),zeros(Nt,1),~zeros(Nt,1),~str2num(rec1(:,1))];
end
out=bin2dec(num2str(rec));
x=real(genqammod(out,const));
for m=1:Nt
LLR1(m)=logm((exp(-K*(x(m)+1).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)-3).^2)))+LLR1(m);
LLR2(m)=logm((exp(-K*(x(m)-3).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)+1).^2)))+LLR2(m);
end
for m=1:Nt
if LLR1(m)>0
bit1(m,1)=1;
else
bit1(m,1)=0;
end
if LLR2(m)>0
bit3(m,1)=1;
else
bit3(m,1)=0;
end
end
combined_rec=[bit1,rec(:,2),bit3,rec(:,4)];
[number ratio]=biterr(data,bin2dec(num2str(combined_rec)));
end
end
end
BER=BER+ratio;
case 2
r1=[];
r1(:,1)=record_r;
ratio=ratio1;
x=genqammod(data,const);
while (ratio~=0&transtime<=4)
transtime=transtime+1;
r1(:,transtime)=awgn(H*x,SNR(SNRindex),'measured');
r=sum(r1.').'/transtime;
out=blastdetect_16qam(H,Nt,r,M);
rec1=dec2bin(out);
if size(rec1,2)==4
rec=[str2num(rec1(:,1)),str2num(rec1(:,2)),str2num(rec1(:,3)),str2num(rec1(:,4))];
elseif size(rec1,2)==3
rec=[zeros(Nt,1),str2num(rec1(:,1)),str2num(rec1(:,2)),str2num(rec1(:,3))];
elseif size(rec1,2)==2
rec=[zeros(Nt,1),zeros(Nt,1),str2num(rec1(:,1)),str2num(rec1(:,2))];
else
rec=[zeros(Nt,1),zeros(Nt,1),zeros(Nt,1),str2num(rec1(:,1))];
end
out=bin2dec(num2str(rec));
x=real(genqammod(out,const));
for m=1:Nt
LLR1(m)=logm((exp(-K*(x(m)+1).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)-3).^2)))+LLR_1(m);
LLR2(m)=logm((exp(-K*(x(m)-3).^2)+exp(-K*(x(m)+3).^2))/(exp(-K*(x(m)-1).^2)+exp(-K*(x(m)+1).^2)))+LLR_2(m);
end
for m=1:Nt
if LLR1(m)>0
bit1(m,1)=1;
else
bit1(m,1)=0;
end
if LLR2(m)>0
bit3(m,1)=1;
else
bit3(m,1)=0;
end
end
combined_rec=[bit1,rec(:,2),bit3,rec(:,4)];
[number ratio]=biterr(data,bin2dec(num2str(combined_rec)));
end
BER1=BER1+ratio;
case 3
r2=[];r=[];
r2(:,1)=record_r;
ratio=ratio1;
x=genqammod(data,const);
while (ratio~=0&transtime1<=4)
transtime1=transtime1+1;
r2(:,transtime)=awgn(H*x,SNR(SNRindex),'measured');
r=sum(r2.').'/transtime1;
out=blastdetect_16qam(H,Nt,r,M);
[number ratio]=biterr(data,out);
end
BER2=BER2+ratio;
end
end
end
end
averber(SNRindex)=BER/SymTime/packetNum
averber1(SNRindex)=BER1/SymTime/packetNum
averber2(SNRindex)=BER2/SymTime/packetNum
end
semilogy(SNR,averber,'-r',SNR,averber1,'-b',SNR,averber2,'-g')
grid on
axis([0 30 10^-4 10^0])
legend('mapping diversity','bit chase combined','symbol chase combined')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -