clear all
clc
N=800;
SNR=linspace(0,30,10);
% SNR=0:5:30;
BER1=zeros(1,length(SNR));
BER2=zeros(1,length(SNR));
% Nt=16;
% Nr=4;
% M=64;
Nt=4;
Nr=4;
M1=4;%SM调制阶数4PSK
M2=2;%GSM调制阶数BPSK
Na=2;
for m=1:length(SNR)
noise_power=1/(10^(SNR(m)/10));
for test_N=1:10
psudo_bit_sequence = randint(N,1);
sequence1 = SMBitMapping(psudo_bit_sequence,Nt,M1);
sequence2 = GSMBitMapping(psudo_bit_sequence);
Length=length(sequence1);
sigma=0.5/(sqrt(Nt)*10^(SNR(m)/10));
for k = 1:Length
H=(randn(Nr,Nt)+1j*randn(Nr,Nt))/sqrt(2);
X1=cell2mat(sequence1(k)).';%SM发射符号
X2=sequence2{k}.';%GSM发射符号
d_min_SM=EDAS_SM(H,X1,Nt);
d_min_GSM=EDAS_GSM(H,X2,Na);
if d_min_SM < d_min_GSM
y_SM=(H*X1)/sqrt(Nt)+sqrt(sigma)*(randn(Nr,1)+1j*randn(Nr,1));
[Tx_SM,s_SM]=ML_SM(y_SM,H,Nt,M1);
yz{k}=Bitdecode(Tx_SM,s_SM,M1);
else
y_GSM=(H*X2)/sqrt(Na)+sqrt(noise_power)*(randn(Nr,1)+1j*randn(Nr,1))/sqrt(2);
symbol_vectorl=ML_GSM(y_GSM,H,Na);
end
end
% Length=length(sequence);
% sigma=0.5/(sqrt(Nt)*10^(SNR(m)/10));
% for k = 1:Length
% H=(randn(Nr,Nt)+1j*randn(Nr,Nt))/sqrt(2);
% X=cell2mat(sequence(k)).';
% % y=awgn(H*X/sqrt(Nt),SNR(m));
% y=(H*X)/sqrt(Nt)+sqrt(sigma)*(randn(Nr,1)+1j*randn(Nr,1));
[Tx,s]=ML(y,H,Nt,M);
% yz{k}=Bitdecode(Tx,s,M);
% finalsequence=cell2mat(yz);
%
% end
[~,ratio1]=biterr(psudo_bit_sequence,finalsequence');
BER1(m)=BER1(m)+ratio1;
end
BER1(m)=BER1(m)/test_N
end
semilogy(SNR,BER1,'--or')
xlabel('SNR [dB]');
ylabel('BER');
grid on;
hold on;