function[pb,ps]=cm_sm32(snr_in_dB)
%[pb,ps]=cm_sm32(snr_in_dB)
% CM_SM32求出QPSK以dB为单位的给定信噪比的
% 比特误码率和符号误码率
N=10000;
E=1; %每符号能量
snr=10^(snr_in_dB/10); %信噪比
sgma=sqrt(E/(3*2*snr)); %噪声标准方差
%信号映射
s000=[1,0];
s001=[cos(pi/4),sin(pi/4)];
s010=[cos(3*pi/4),sin(3*pi/4)];
s011=[0,1];
s100=[cos(7*pi/4),sin(7*pi/4)];
s101=[0,-1];
s110=[-1,0];
s111=[cos(5*pi/4),sin(5*pi/4)];
%数据源的产生
for i=1:N,
temp=rand; %在区间(0,1 )间的一个均匀随机变量
if (temp<0.125), %信源输出为“000”的概率为1/8
dsource1(i)=0;
dsource2(i)=0;
dsource3(i)=0;
elseif (temp<0.25), %信源输出为“001”的概率为1/8
dsource1(i)=0;
dsource2(i)=0;
dsource3(i)=1;
elseif (temp<0.375), %信源输出为“010”的概率为1/8
dsource1(i)=0;
dsource2(i)=1;
dsource3(i)=0;
elseif (temp<0.5), %信源输出为“011”的概率为1/8
dsource1(i)=0;
dsource2(i)=1;
dsource3(i)=1;
elseif (temp<0.625), %信源输出为“100”的概率为1/8
dsource1(i)=1;
dsource2(i)=0;
dsource3(i)=0;
elseif (temp<0.75), %信源输出为“101”的概率为1/8
dsource1(i)=1;
dsource2(i)=0;
dsource3(i)=1;
elseif (temp<0.875), %信源输出为“110”的概率为1/8
dsource1(i)=1;
dsource2(i)=1;
dsource3(i)=0;
else %信源输出为“111”的概率为1/8
dsource1(i)=1;
dsource2(i)=1;
dsource3(i)=1;
end;
end;
%判决、误码率的计算
numofsymbolerror=0;
numofbiterror=0;
for i=1:N,
%在判决器处的接收信号,对于第i个符号为:
n(1)=gngauss(sgma);
n(2)=gngauss(sgma);
if ((dsource1(i)==0) & (dsource2(i)==0) & (dsource3(i)==0)),
r=s000+n;
elseif ((dsource1(i)==0) & (dsource2(i)==0) & (dsource3(i)==1)),
r=s001+n;
elseif ((dsource1(i)==0) & (dsource2(i)==1) & (dsource3(i)==0)),
r=s010+n;
elseif ((dsource1(i)==0) & (dsource2(i)==1) & (dsource3(i)==1)),
r=s011+n;
elseif ((dsource1(i)==1) & (dsource2(i)==0) & (dsource3(i)==0)),
r=s100+n;
elseif ((dsource1(i)==1) & (dsource2(i)==0) & (dsource3(i)==1)),
r=s101+n;
elseif ((dsource1(i)==1) & (dsource2(i)==1) & (dsource3(i)==0)),
r=s110+n;
else
r=s111+n;
end;
%以下为计算互相关量度
c000=dot(r , s000);
c001=dot(r , s001);
c010=dot(r , s010);
c011=dot(r , s011);
c100=dot(r , s100);
c101=dot(r , s101);
c110=dot(r , s110);
c111=dot(r , s111);
%第i个符号的判决按如下方式进行
c_max=max([c000 c001 c010 c011 c100 c101 c110 c111]);
if (c000==c_max)
decis1=0;decis2=0;decis3=0;
elseif (c001==c_max)
decis1=0;decis2=0;decis3=1;
elseif (c010==c_max)
decis1=0;decis2=1;decis3=0;
elseif (c011==c_max)
decis1=0;decis2=1;decis3=1;
elseif (c100==c_max)
decis1=1;decis2=0;decis3=0;
elseif (c101==c_max)
decis1=1;decis2=0;decis3=1;
elseif (c110==c_max)
decis1=1;decis2=1;decis3=0;
else
decis1=1;decis2=1;decis3=1;
end;
%如果判决不对,计错器加1
symbolerror=0;
if (decis1~=dsource1(i)),
numofbiterror=numofbiterror+1;
symbolerror=1;
end;
if (decis2~=dsource2(i)),
numofbiterror=numofbiterror+1;
symbolerror=1;
end;
if (decis3~=dsource3(i)),
numofbiterror=numofbiterror+1;
symbolerror=1;
end;
if (symbolerror==1),
numofsymbolerror=numofsymbolerror+1;
end;
end;
ps=numofsymbolerror/N; %因为总共有N个符号
pb=numofbiterror/(3*N); %因为发送了3N个比特
clear all
echo off
SNRindB1=0:2:10;
SNRindB2=0:0.1:10;
for i=1:length (SNRindB1),
[pb , ps]=cm_sm32 (SNRindB1 (i)); %仿真比特和符号误码率
smld_bit_err_prb (i)=pb;
smld_symbol_err_prb (i)=ps;
end;
for i=1:length (SNRindB2),
SNR=exp(SNRindB2(i)*log(10)/10); %信噪比
theo_err_prb(i)=2*Qfunct(sqrt(6*SNR)*sin(pi/8))/3; %理论比特误码率
end;
%%%%%%%随后绘图曲线%%%%%%%
semilogy (SNRindB1,smld_bit_err_prb,'*');
hold
semilogy (SNRindB1,smld_symbol_err_prb,'O');
semilogy (SNRindB2,theo_err_prb);
grid on
xlabel('Eb/No in dB')
ylabel('error probability')
title('8PSK系统的蒙特卡罗仿真')
%gtext('(注:“—”理论误码率;“*”误比特率;“o”误符号率)')
clear
clear all
N=21;
bit_sequence=rand(1,N)>0.5;
bpsk=bit_sequence*2-1;
temp=[0.5+1j 1+0.5j -0.5+1j -1+0.5j -0.5-1j -1-0.5j 0.5-1j 1-0.5j]/sqrt(3);
transformbit = [0 0 0];
qpsk_sequence = ones(1,N/3);
psk_dianpingi=ones(1,N/3);
psk_dianpingq=ones(1,N/3);
for k=1:N/3
transformbit = bit_sequence(3*k-2:3*k);
if transformbit== [0 0 0]
qpsk_sequence(k) = temp(1);
ge(k)=conj(temp(1));
psk_dianpingi(k)=-0.383;
psk_dianpingq(k)=-0.924;
end
if transformbit== [0 0 1]
qpsk_sequence(k) = temp(2);
ge(k)=conj(temp(2)) ;
psk_dianpingi(k)=-0.924;
psk_dianpingq(k)=-0.383;
end
if transformbit== [0 1 0]
qpsk_sequence(k) = temp(3);
ge(k)=conj(temp(3));
psk_dianpingi(k)=-0.383;
psk_dianpingq(k)=0.924;
end
if transformbit== [0 1 1]
qpsk_sequence(k) = temp(4);
ge(k)=conj(temp(4));
psk_dianpingi(k)=-0.924;
psk_dianpingq(k)=0.383;
end
if transformbit== [1 0 0]
qpsk_sequence(k) = temp(5);
ge(k)=conj(temp(5));
psk_dianpingi(k)=0.383;
psk_dianpingq(k)=-0.924;
end
if transformbit== [1 0 1]
qpsk_sequence(k) = temp(6);
ge(k)=conj(temp(6));
psk_dianpingi(k)=0.924;
psk_dianpingq(k)=-0.383;
end
if transformbit== [1 1 0]
qpsk_sequence(k) = temp(7);
ge(k)=conj(temp(7))
psk_dianpingi(k)=0.383;
psk_dianpingq(k)=0.924;
end
if transformbit== [1 1 1]
qpsk_sequence(k) = temp(8);
ge(k)=conj(temp(8));
psk_dianpingi(k)=0.924;
psk_dianpingq(k)=0.383;
end
x(k)=(qpsk_sequence(k)+ge(k))/2 ;
y(k)=(qpsk_sequence(k)-ge(k))/2j;
t=3*k-3:0.01:3*k;
x1=(psk_dianpingi(k)*cos(2*pi*psk_dianpingi(k)*t)-psk_dianpingq(k)*sin(2*pi*t));
subplot(4,1,4)
axis([0,N-2,-2.5,2.5])
plot(t,x1);hold on
xx=bit_sequence(1);
for ii=1:N;
for kk=ii:0.01:ii+1;
b=ones(1,100);
subplot(4,1,1);
plot(kk,bit_sequence(ii));axis([0,N+1,-2,2]);hold on
if bit_sequence(ii)~=xx;
aa=0:0.01:1;plot(ii,aa);
end
xx=bit_sequence(ii);
end
end
end
xxx=psk_dianpingi(1);
for iii=3:3:21
for kkk=iii:0.01:iii+3
b=ones(1,100);
subplot(4,1,2)
jjj=iii/3;
plot(kkk,psk_dianpingi(jjj));axis([0,21,-2,2]);hold on
ccc=psk_dianpingi(jjj);
if ccc~=xxx;
if xxx<ccc
aaa=xxx:0.01:ccc;plot(iii,aaa,'-b');
else aaa=xxx:-0.01:ccc;plot(iii,aaa,'-b');
end
end
xxx=psk_dianpingi(jjj);
end
end
xxxx=psk_dianpingq(1);
for iiii=3:3:21;
for kkkk=iiii:0.01:iiii+3
b=ones(1,100);
subplot(4,1,3)
jjjj=iiii/3;
plot(kkkk,psk_dianpingq(jjjj));axis([0,21,-2,2]);hold on
cccc=psk_dianpingq(jjjj);
if cccc~=xxxx;
if xxxx<cccc
aaaa=xxxx:0.01:cccc;plot(iiii,aaaa,'-b');
else aaaa=xxxx:-0.01:cccc;plot(iiii,aaaa,'-b');
end
end
xxxx=psk_dianpingq(jjjj);
end
end
subplot(4,1,4);title('8psk调制波形')
subplot(4,1,1);title('随机二进制序
- 1
- 2
- 3
- 4
- 5
前往页