📄 danfaduoshou.m
字号:
close all;
clear all;
rand('state',sum(100*clock));%Initialize RAND
randn('state',sum(100*clock));%Initialize RANDN
QPSK_C=[1+j,-1+j,-1-j,1-j]; %Signal set
QPSK_B=[0 0; 0 1;1 1;1 0]; %Binary mapping
SizeOfSignalSet=size(QPSK_B,1);%The size of the signal set
BitsPerSymbol=size(QPSK_B,2); %number of bits carried by one symbol
Es=sum(QPSK_C.*conj(QPSK_C))/length(QPSK_C); %Average symbol energy
Eb=Es/BitsPerSymbol; %bit energy
recIndex=1;
for EbN0=0:2:14
N0=Eb*10^(-EbN0/10); %get the noise power
testCount=0;
errCount=0;
while(1)
h0=(randn(1)+j*randn(1))/sqrt(2);%Generate the channel (Complex gaussian, Rayleigh apmlitude)
h1=(randn(1)+j*randn(1))/sqrt(2);%Generate the channel (Complex gaussian, Rayleigh apmlitude)
%Randomly generate a source symbol
SrcIndex=floor(rand(1)*SizeOfSignalSet)+1;
x=QPSK_C(SrcIndex); %get the signal symbol
%Generate the noise
xi_0=(randn(1)+j*randn(1))/sqrt(2);
xi_0=xi_0*sqrt(N0); %control the noise power, N0
xi_1=(randn(1)+j*randn(1))/sqrt(2);
xi_1 =xi_1*sqrt(N0); %control the noise power, N0
%The channel with noise
y0=h0*x+xi_0; % TX to RX 0
y1=h1*x+xi_1; % TX to RX 1
%Detect the signal, minimal distance decision
vec0=y0-h0*QPSK_C;
vec1=y1-h1*QPSK_C;
Dist=vec0.*conj(vec0)+vec1.*conj(vec1);
[minVlaue DecIndex]=min(Dist);
if(DecIndex ~= SrcIndex)
errBinary=mod(QPSK_B(SrcIndex,:)+QPSK_B(DecIndex,:),2);
errCount=errCount+sum(errBinary);
end
testCount=testCount+1;
testLength=testCount*BitsPerSymbol;%Get the binary length
%stop control
if(testLength<100000) %test length lower bound
continue;
end
BER=errCount/testLength;
if(BER<1e-10)
continue;
end
testLevel=500.0/BER; %confidence level
if(testLength>testLevel)
break;
end
end
BER_rec(recIndex)=BER;%record the test result
EbN0_rec(recIndex)=EbN0;
recIndex=recIndex+1;
%Display the results
BER_rec
EbN0_rec
end
semilogy(EbN0_rec,BER_rec,'-');
xlabel('Eb/N0 in dB');
ylabel('Bit error rate');
hold on;
BER_rec_T1_R1=[0.14812,0.10866,0.07452,0.05225,0.03592,0.02267,0.01496,0.01008,0.00576,0.00404136551368,0.00254586107018,0.00154064725636,0.00100066844652,0.00063655344503,0.00036775824557,0.00025897691687];
EbN0_rec_T1_R1=0:2:30;
semilogy(EbN0_rec_T1_R1,BER_rec_T1_R1,'r-');
xlabel('Eb/N0 in dB');
ylabel('Bit error rate');
legend('Tx 1, Rx 2','Tx 1, Rx 1');
grid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -