Вы находитесь на странице: 1из 4

Tb=0.

1;
A=[1 0];
B=[0 1];
F=[ones(1,5)]/5;
G=[ones(1,5) zeros(1,5)]/5;
H=[zeros(1,5) ones(1,5)]/5;
L=[ones(1,5) zeros(1,5) zeros(1,5)]/5;
M=[zeros(1,5) ones(1,5) zeros(1,5)]/5;
N=[zeros(1,5) zeros(1,5) ones(1,5)]/5;
Data_bits=round(rand(1,10000));
S=2.*Data_bits-1;
BPSK=S(1,1)*F;
for i=2:1:10000
BPSK=[BPSK S(1,i)*F];
end;
QPSK=S(1,1)*sqrt(1/2)*G + S(1,2)*sqrt(1/2)*H;
for i=3:2:9999
QPSK=[QPSK S(1,i)*sqrt(1/2)*G+S(1,i+1)*sqrt(1/2)*H];
end;
EPSK=S(1,1)*sqrt(1/3)*L + S(1,2)*sqrt(1/3)*M + S(1,3)*sqrt(1/3)*N;
for i=4:3:9997
EPSK=[EPSK S(1,i)*sqrt(1/3)*L+S(1,i+1)*sqrt(1/3)*M+S(1,i+2)*sqrt(1/3)*N];
end;
for i=1:4:9997
if (S(1,i)<0 && S(1,i+1)<0 && S(1,i+2)<0 && S(1,i+3)<0) QAM(1,1+(i-1)/2:2+(i-1)/
2)=3*A+3*B;
elseif (S(1,i)<0 && S(1,i+1)>0 && S(1,i+2)<0 && S(1,i+3)<0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=1*A+3*B;
elseif (S(1,i)>0 && S(1,i+1)>0 && S(1,i+2)<0 && S(1,i+3)<0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=-1*A+3*B;
elseif (S(1,i)>0 && S(1,i+1)<0 && S(1,i+2)<0 && S(1,i+3)<0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=-3*A+3*B;
elseif (S(1,i)<0 && S(1,i+1)<0 && S(1,i+2)<0 && S(1,i+3)>0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=3*A+1*B;
elseif (S(1,i)<0 && S(1,i+1)>0 && S(1,i+2)<0 && S(1,i+3)>0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=1*A+1*B;
elseif (S(1,i)>0 && S(1,i+1)>0 && S(1,i+2)<0 && S(1,i+3)>0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=-1*A+1*B;
elseif (S(1,i)>0 && S(1,i+1)<0 && S(1,i+2)<0 && S(1,i+3)>0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=-3*A+1*B;
elseif (S(1,i)<0 && S(1,i+1)<0 && S(1,i+2)>0 && S(1,i+3)>0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=3*A-1*B;
elseif (S(1,i)<0 && S(1,i+1)>0 && S(1,i+2)>0 && S(1,i+3)>0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=1*A-1*B;
elseif (S(1,i)>0 && S(1,i+1)>0 && S(1,i+2)>0 && S(1,i+3)>0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=-1*A-1*B;
elseif (S(1,i)>0 && S(1,i+1)<0 && S(1,i+2)>0 && S(1,i+3)>0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=-3*A-1*B;
elseif (S(1,i)<0 && S(1,i+1)<0 && S(1,i+2)>0 && S(1,i+3)<0) QAM(1,1+(i-1)/2:2+(i

-1)/2)=3*A-3*B;
elseif (S(1,i)<0 && S(1,i+1)>0 && S(1,i+2)>0 && S(1,i+3)<0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=1*A-3*B;
elseif (S(1,i)>0 && S(1,i+1)>0 && S(1,i+2)>0 && S(1,i+3)<0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=-1*A-3*B;
elseif (S(1,i)>0 && S(1,i+1)<0 && S(1,i+2)>0 && S(1,i+3)<0) QAM(1,1+(i-1)/2:2+(i
-1)/2)=-3*A-3*B;
end;
end;
for i=1:1:41
SNR(1,i)=i-11;
No=10^(-0.1*(i-11));
XBPSK(i,:)=BPSK+ sqrt(No/2)*randn(1,50000);
XQPSK(i,:)=QPSK+ sqrt(No/2)*randn(1,50000);
XEPSK(i,:)=EPSK+ sqrt(No/2)*randn(1,49995);
XQAM(i,:)= QAM+ sqrt(No/2)*randn(1,5000);
BER_BPSK_TH(1,i)=0.5*erfc(sqrt(1/No));
BER_QPSK_TH(1,i)=erfc(sqrt(1/No)) - (erfc(sqrt(1/No)))^2;
BER_EPSK_TH(1,i)=erfc(sin(pi/8)*sqrt(1/No));
BER_QAM_TH(1,i)=3/8*erfc(sqrt(1/2.5/No));
end;
NOE_BPSK=zeros(1,41);
for g=1:1:41
for i=1:1:10000
T=XBPSK(g,5*(i-1)+1:5*i).*F;
RBPSK(g,i)=0;
for j=1:1:5
RBPSK(g,i)=RBPSK(g,i)+T(1,j);
end;
if (RBPSK(g,i)>0) RBPSK(g,i)=1; else RBPSK(g,i)=-1; end;
if (RBPSK(g,i)~=S(1,i)) NOE_BPSK(1,g)=NOE_BPSK(1,g)+1; end;
end;
BER_BPSK(1,g)=NOE_BPSK(1,g)/10000;
end;

NOE_QPSK=zeros(1,41);
for g=1:1:41
for i=1:1:5000
T1=XQPSK(g,10*(i-1)+1:10*i).*G;
T2=XQPSK(g,10*(i-1)+1:10*i).*H;
x1(g,i)=0; x2(g,i)=0;
for j=1:1:10
x1(g,i)=x1(g,i)+T1(1,j);
x2(g,i)=x2(g,i)+T2(1,j);
end;
if (x1(g,i)>0 && x2(g,i)>0) RQPSK(g,2*i-1)= 1; RQPSK(g,2*i)= 1;
elseif (x1(g,i)<0 && x2(g,i)>0) RQPSK(g,2*i-1)=-1; RQPSK(g,2*i)= 1;
elseif (x1(g,i)<0 && x2(g,i)<0) RQPSK(g,2*i-1)=-1; RQPSK(g,2*i)=-1;
elseif (x1(g,i)>0 && x2(g,i)<0) RQPSK(g,2*i-1)= 1; RQPSK(g,2*i)=-1;
end;
end;
for i=1:1:10000
if (RQPSK(g,i)~=S(1,i)) NOE_QPSK(1,g)=NOE_QPSK(1,g)+1; end;
BER_QPSK(1,g)=NOE_QPSK(1,g)/10000;

end;
end;
NOE_EPSK=zeros(1,41);
for g=1:1:41
for i=1:1:3333
T1=XEPSK(g,15*(i-1)+1:15*i).*L;
T2=XEPSK(g,15*(i-1)+1:15*i).*M;
T3=XEPSK(g,15*(i-1)+1:15*i).*N;
x1(g,i)=0; x2(g,i)=0; x3(g,i)=0;
for j=1:1:15
x1(g,i)=x1(g,i)+T1(1,j);
x2(g,i)=x2(g,i)+T2(1,j);
x3(g,i)=x3(g,i)+T3(1,j);
end;
if (x1(g,i)>0 && x2(g,i)>0 && x3(g,i)>0) Z=[
elseif (x1(g,i)<0 && x2(g,i)>0 && x3(g,i)>0)
elseif (x1(g,i)>0 && x2(g,i)<0 && x3(g,i)>0)
elseif (x1(g,i)<0 && x2(g,i)<0 && x3(g,i)>0)
elseif (x1(g,i)>0 && x2(g,i)>0 && x3(g,i)<0)
elseif (x1(g,i)<0 && x2(g,i)>0 && x3(g,i)<0)
elseif (x1(g,i)>0 && x2(g,i)<0 && x3(g,i)<0)
elseif (x1(g,i)<0 && x2(g,i)<0 && x3(g,i)<0)
end;

1 1 1];
Z=[-1 1 1];
Z=[ 1 -1 1];
Z=[-1 -1 1];
Z=[ 1 1 -1];
Z=[-1 1 -1];
Z=[ 1 -1 -1];
Z=[-1 -1 -1];

if (i==1) REPSK(g,1:3)=Z; else REPSK(g,3*i-2:3*i)=Z; end;


end;
for i=1:1:9999
if(REPSK(g,i)~=S(1,i)) NOE_EPSK(1,g)=NOE_EPSK(1,g)+1; end;
BER_EPSK(1,g)=NOE_EPSK(1,g)/10000;
end;
end;
NOE_QAM=zeros(1,41);
for g=1:1:41
for i=1:1:2500
T1=XQAM(g,2*(i-1)+1:2*i).*A;
T2=XQAM(g,2*(i-1)+1:2*i).*B;
x1(g,i)=0; x2(g,i)=0;
for j=1:1:2
x1(g,i)=x1(g,i)+T1(1,j);
x2(g,i)=x2(g,i)+T2(1,j);
end;
if (x1(g,i)> 2 && x2(g,i)> 2) Z=[-1 -1 -1 -1];
elseif (x1(g,i)> 0 && x2(g,i)> 2) Z=[-1 1 -1 -1];
elseif (x1(g,i)>-2 && x2(g,i)> 2) Z=[ 1 1 -1 -1];
elseif (x1(g,i)>-4 && x2(g,i)> 2) Z=[ 1 -1 -1 -1];
elseif (x1(g,i)> 2 && x2(g,i)> 0) Z=[-1 -1 -1 1];
elseif (x1(g,i)> 0 && x2(g,i)> 0) Z=[-1 1 -1 1];
elseif (x1(g,i)>-2 && x2(g,i)> 0) Z=[ 1 1 -1 1];
elseif (x1(g,i)>-4 && x2(g,i)> 0) Z=[ 1 -1 -1 1];
elseif (x1(g,i)> 2 && x2(g,i)>-2) Z=[-1 -1 1 1];
elseif (x1(g,i)> 0 && x2(g,i)>-2) Z=[-1 1 1 1];
elseif (x1(g,i)>-2 && x2(g,i)>-2) Z=[ 1 1 1 1];
elseif (x1(g,i)>-4 && x2(g,i)>-2) Z=[ 1 -1 1 1];
elseif (x1(g,i)> 2 && x2(g,i)>-4) Z=[-1 -1 1 -1];
elseif (x1(g,i)> 0 && x2(g,i)>-4) Z=[-1 1 1 -1];
elseif (x1(g,i)>-2 && x2(g,i)>-4) Z=[ 1 1 1 -1];
elseif (x1(g,i)>-4 && x2(g,i)>-4) Z=[ 1 -1 1 -1];

end;
if (i==1) RQAM(g,1:4)=Z; else RQAM(g,4*i-3:4*i)=Z; end;
end;
for i=1:1:10000
if (RQAM(g,i)~=S(1,i)) NOE_QAM(1,g)=NOE_QAM(1,g)+1; end;
BER_QAM(1,g)=NOE_QAM(1,g)/10000;
end;
end;
subplot(5,1,1),plot(SNR,BER_BPSK_TH , SNR,BER_BPSK,'r');
subplot(5,1,2),plot(SNR,BER_QPSK_TH , SNR,BER_QPSK,'r');
subplot(5,1,3),plot(SNR,BER_EPSK_TH , SNR,BER_EPSK,'r');
subplot(5,1,4),plot(SNR,BER_QAM_TH , SNR,BER_QAM,'r');
subplot(5,1,5),plot(SNR,BER_BPSK , SNR,BER_QPSK,'r' , SNR,BER_EPSK,'g' , SNR,BER
_QAM,'y');
SNR,BER_EPSK,'g' , SNR,BER_QAM,'y');