📄 myselfchase_hard.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:');
%len=96*10;
L=1;
%SNRdB=5;
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))
%tranmit 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=Tx_Sum;
RxSig_MF=reshape(RxSig,Rx*L,1) ;
Ch_Total=Ch_Equ;
[BLR,DeSymb,IX]=LLRnLayer(RxSig_MF,Ch_Total,M,sigma_n2,1,1,1);
ind=IX(1);
ChanCoff=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(M,log2(M));
Phi=zeros(M,1);
Temp_Ind=0;
for i=1:M
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);
ML_Matrix=zeros(Temp_Ind,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);
ReSig=RxSig_MF-ChanCoff.*Sym1;
Det_sig_temp=MIMONCZF(ReSig,Chan,M,sigma_n2,Factor,0);
DetTemp(:,i)=vertcat(Det_sig_temp(1:ind-1,1),OrgSymb(1,1),Det_sig_temp(ind:Tx-1,1));
Tx_sym=modulate(h,DetTemp(:,i))/sqrt(Factor);
ML_Matrix(i)=norm(RxSig_MF-Ch_Total*Tx_sym,'fro')^2;
end
[MinValue,Index]=min(ML_Matrix);
Det_sym_temp=DetTemp(:,Index);
Det_bit=de2bi(Det_sym_temp,log2(M),2);
dd_bit=reshape(Det_bit,Tx*L*log2(M),1);
Sym_code(:,BloInd)=dd_bit.';
end
ncode=reshape(Sym_code,2*len,1);
b1 = randdeintrlv(ncode,4831);
decoded = vitdec(b1,trel,3,'trunc','hard');
ber(SNRindex)=length(find(decoded-msg))/len;
end
semilogy(SNRdB,ber)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -