📄 cpsk.m
字号:
function Pe = CPSK(snr_in_db)%UNTITLED1 Summary of this function goes here% Detailed explanation goes here% snr_in_db=4;fc=50;T=0.15;N=10000;ts=0.0001;VT=0; %1/2log(lamta)-1/2*int(s0^2-s1^2)A=(5^1/2)/50; %awgn(x,snr_in_db)的x必须是1mw的功率的(0dbw),故须算出此时幅度大小为多少,A^2/2,故A= % E=1; % lamta=1; t=[0:ts:T]; %这就是怎么把 for 转化成矩阵的方法 S0=A*sin(2*pi*fc.*t); %不能写s0(t)= ... ,因为括号里的 值必须是整数; S1=-A*sin(2*pi*fc.*t); % SNR=exp(snr_in_db*log(10)/10); % sgma=E/sqrt(2*SNR);k=length(t);r=zeros(N,k);numoferr=0;for i=1:N temp=rand; if(temp<0.5) dsource(i)=0; else dsource(i)=1; end if(dsource(i)==0) r(i,1:k)= awgn(S0,snr_in_db); else r(i,1:k)= awgn(S1,snr_in_db); end RT1(i)=int1(r(i,1:k).*S1,ts);% RT1=int(r(i).*S1)是错的,这样会只跟第一个量相乘而已 RT2(i)=int1(r(i,1:k).*S0,ts); test1(i)=int1(S1.*S1,ts); test2(i)=int1(S0.*S0,ts); if( RT1(i)-RT2(i)>VT) R(i)=1; else R(i)=0; end if(R(i)~=dsource(i)) numoferr=numoferr+1; endendPe=numoferr/N;% K=S1.*S1;% K1=S0.*S0;% M1=int1(K,ts);% M2=int1(K1,ts);% %deploy int(r(t).*S1(t)&'发送信号' ,and so on% i=[1:N];% subplot(3,2,1);% plot(i,RT1);% xlabel('i');% ylabel('int(r(t).*S1(t)');% subplot(3,2,2);% plot(i,test1);% xlabel('i');% ylabel('int(S1(t).*S1(t)');% subplot(3,2,3);% plot(i,RT2);% xlabel('i');% ylabel('int(r(t).*S0(t)');% subplot(3,2,4);% plot(i,test2);% xlabel('i');% ylabel('int(S0(t).*S0(t)');% subplot(3,2,5);% plot(i,dsource(i));% xlabel('i');% ylabel('发送信号');% subplot(3,2,6);% plot(i,R(i));% xlabel('i');% ylabel('得到信号');% % plot(i,RT1,i,test1,i,dsource(i))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -