📄 myselfchase_soft.m
字号:
%==========================================
%16QAM; 1/2,3conv; TX=4;RX=4; 硬判决
%==========================================
clc;
clear
Tx=4;
Rx=4;
M=16;
h=modem.qammod(M);
h2=modem.qamdemod(M);
Factor=10;
Table_bit=zeros(M,log2(M));
for i=2:M
Table_bit(i,:)=de2bi(i-1,log2(M));
end
%Ch_Q=[1.65 2.3 3.25 5 7.6 11.55 18];
Ch_Q=1.65;
%L=input('please enter the length of the frame:');
%SNRdB=input('please enter SNR:');
%lenl=input('please enter the length of bit:');
SNRdB=8;
lenl=96;
%len=96*10;
L=1;
%SNRdB=5;
Num_order=M;
for SNRindex=1:length(SNRdB)
SNRtemp=10.^((SNRdB+3)/10);
SNR=SNRtemp(SNRindex);
sigma_n2=sqrt(Tx)/sqrt(SNR);
len=lenl(SNRindex);
msg=randint(len,1);
trel=poly2trellis(3,[6,7]);
code=convenc(msg,trel);
y=randintrlv(code,4831);
Sig_code=buffer(y,Tx*L*log2(M));
Sym_code=zeros(Tx*L*log2(M),2*len/(Tx*L*log2(M)));
for BloInd=1:2*len/(Tx*L*log2(M))
% transmit signal
TxMatrix_bit_src=Sig_code(:,BloInd);
TxMatrix_bit_map=reshape(TxMatrix_bit_src,Tx*L,log2(M));
TxMatrix_sym_temp=bi2de(TxMatrix_bit_map);
TxMatrix_sym=modulate(h,TxMatrix_sym_temp)/sqrt(Factor);
TxMatrix=reshape(TxMatrix_sym,Tx,L);
%channel
for i=1:Rx
Ch=(randn(Tx,L)+sqrt(-1)*randn(Tx,L)).*sqrt(0.5);
TxPassCh=Ch.*TxMatrix;
TxSum_temp=sum(TxPassCh);
for k=1:L
Ch_Equ(Rx*(k-1)+i,Tx*(k-1)+1:Tx*k)=(Ch(:,k)).';
end
Tx_Sum(i,:)=TxSum_temp;
end
% receive signal
RxSig=Tx_Sum+sigma_n2*(randn(Rx,L)+sqrt(-1)*randn(Rx,L))/sqrt(2);
RxSig_MF=reshape(RxSig,Rx*L,1);
Ch_Total=Ch_Equ;
%[BLR,DeSymb,ind]=LLR1Layer(RxSig_MF,Ch_Total,M,sigma_n2,1,2);
[BLR,DeSymb,IX]=LLRnLayer(RxSig_MF,Ch_Total,M,sigma_n2,1,2,1);
ind=IX(1);
ChanCoeff=Ch_Total(:,ind);
Chan=horzcat(Ch_Total(:,1:ind-1),Ch_Total(:,ind+1:Tx));
DetSignal=demodulate(h2,sqrt(Factor)*[DeSymb(ind,1)]);
Det_bit=de2bi(DetSignal,log2(M),2);
Bit_Vec=reshape(Det_bit,log2(M),1);
Table_pertur=zeros(Num_order,log2(M));
Phi=zeros(Num_order,1);
Temp_Ind=0;
for i=1:Num_order
Table_pertur(i,:)=xor(Table_bit(i,:),Bit_Vec.');
Phi(i)=Phi(i)+Table_pertur(i,1:log2(M))*abs(BLR(1,1:log2(M)).');
if Phi(i)<=Ch_Q(SNRindex)
Temp_Ind=Temp_Ind+1;
IndSet(Temp_Ind)=i;
end
end
IndSet=IndSet(:,1:Temp_Ind);
MLValue0=zeros(Tx*L*log2(M),1);
MLValue1=zeros(Tx*L*log2(M),1);
for i=1:Temp_Ind
Search_bit=Table_bit(IndSet(i),:);
DetBitMap=reshape(Search_bit,1,log2(M));
OrgSymb=bi2de(DetBitMap);
Sym1=modulate(h,OrgSymb)/sqrt(Factor);
% cacellating the interference caused by current detected signal
ReSig=RxSig_MF-ChanCoeff.*Sym1;
Det_sig_temp=MIMONCZF(ReSig,Chan,M,sigma_n2,Factor,0);
DetTemp=vertcat(Det_sig_temp(1:ind-1,1),OrgSymb(1,1),Det_sig_temp(ind:Tx-1,1));
Tx_sym=modulate(h,DetTemp)/sqrt(Factor);
Tx_sym_1=reshape(Tx_sym,Tx,L);
Sigma=2*sigma_n2*sigma_n2;
Det_bit=de2bi(DetTemp,log2(M),2);
dd_bit=reshape(Det_bit,Tx*L*log2(M),1);
for j=1:Tx*L*log2(M)
if dd_bit(j,1)==0
MLValue0(j,1)=MLValue0(j,1)+exp(-norm(RxSig-Ch_Total*Tx_sym_1,'fro')^2/Sigma);
else
MLValue1(j,1)=MLValue1(j,1)+exp(-norm(RxSig-Ch_Total*Tx_sym_1,'fro')^2/Sigma);
end
end
end
%LLR(j)=log(MLValue1/MLValue0);
NormFactor=sqrt(MLValue1.*MLValue1+MLValue0.*MLValue0);
MLValue1=MLValue1./NormFactor;
MLValue0=MLValue0./NormFactor;
SoftMean=MLValue0-MLValue1;
%if LLR(j)>=0
% dd_bit(1,j)=1;
%else
% dd_bit(1,j)=0;
%end
Sym_code(:,BloInd)=SoftMean.';
end
%Pavg(runs)=mean(D);
%D=zeros(1,BloInd);
ncode=reshape(Sym_code,2*len,1);
b1=randdeintrlv(ncode,4831);
decoded = vitdec(b1,trel,3,'trunc','unquant'); % Decode.
ber(SNRindex)=length(find(decoded-msg))/len;
end
% plot the curve
semilogy(SNRdB, ber);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -