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=[00; 01;11;10]; %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:30
N0=Eb*10^(-EbN0/10); %get the noise power,larger equal to 1,lower equal to 10^-3
testCount=0;
errCount=0;
while(1)
h=(randn(1)+j*randn(1))/sqrt(2);%Generate the channel (Complex gaussian, Rayleigh apmlitude),complex conjugate divide 2
%Randomly generate a source symbol
SrcIndex=floor(rand(1)*SizeOfSignalSet)+1;
x=QPSK_C(SrcIndex); %get the signal symbol
%Generate the noise
n=(randn(1)+j*randn(1))/sqrt(2);
n=n*sqrt(N0); %control the noise power, N0,complex conjugate multiply
%The channel with noise
r=h*x+n;
%Detect the signal
y=r/h;
%Decision
Error=(y-QPSK_C);
Dist=Error.*conj(Error);%calculate distance of every set
[minVlaue DecIndex]=min(Dist);%find minimum distance and set
if(DecIndex ~= SrcIndex)
errBinary=mod(QPSK_B(SrcIndex,:)+QPSK_B(DecIndex,:),2);%calculate difference of set point
errCount=errCount+sum(errBinary);%numbers of real error bit
end
testCount=testCount+1;
testLength=testCount*BitsPerSymbol;%Get the binary length
%stop control
if(testLength<100000) %test length lower bound less than 100/10^-3
continue;
end
BER=errCount/testLength;
if(BER<1e-10)%errCount not equal to naught/zero
continue;
end
testLevel=500.0/BER; %confidence level,errCount >= 10^3 / BitsPerSymbol
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 ratio');
title('QPSK relation of Tx1 Rx1 BER');
grid
- 1
- 2
- 3
前往页