?? div_1tx2rx.m
字號:
LB=100000; % Symbols transmitted
%L=LB*SF; % chips transmitted
Z=zeros(1,LB);
bk=zeros(1,LB);
bk_trans1=zeros(1,LB);
bk_trans2=zeros(1,LB);
ray0=zeros(1,LB); % tx0 -> rx0
ray1=zeros(1,LB); % tx0 -> rx1
bk(1,:)=randint(1,LB,2)*2-1;
noisex=randn(1,LB/2+128);
noisey=randn(1,LB/2+128);
fmn=0.01;
h=fir1(255,fmn);
noisex1=filter(h,1,noisex);
noisey1=filter(h,1,noisey);
ray0(1,1:2:end)=noisex1(1+128:end)+sqrt(-1)*noisey1(1+128:end);
ray0(1,2:2:end)=ray0(1,1:2:end);
ray0(1,:)=ray0(1,:)./std(ray0(1,:));
noisex=randn(1,LB/2+128);
noisey=randn(1,LB/2+128);
fmn=0.01;
h=fir1(255,fmn);
noisex1=filter(h,1,noisex);
noisey1=filter(h,1,noisey);
ray1(1,1:2:end)=noisex1(1+128:end)+sqrt(-1)*noisey1(1+128:end);
ray1(1,2:2:end)=ray1(1,1:2:end);
ray1(1,:)=ray1(1,:)./std(ray1(1,:));
noise0=(randn(1,LB)+sqrt(-1)*randn(1,LB))/sqrt(1);
noise1=(randn(1,LB)+sqrt(-1)*randn(1,LB))/sqrt(1);
for k=1:30; %%%%%%%% Calculate the different BER while SNR increaseing
SNRdB(k)=k-1;
SNR(k)=10^(-SNRdB(k)/20);
for p=1:LB
r0=ray0(1,p)*bk(1,p)+SNR(k)*noise0(1,p)/sqrt(2);
r1=ray1(1,p)*bk(1,p)+SNR(k)*noise1(1,p)/sqrt(2);
s0=conj(ray0(1,p))*r0+conj(ray1(1,p))*r1;
Z(1,p)=s0;
end
bk2=zeros(1,LB);
bk2(1,Z(1,:)>0)=1;
bk2(1,Z(1,:)==0)=1;
bk2(1,Z(1,:)<0)=-1;
delayB=0;
diffB_BPSK= (bk(1,1:end-delayB) - bk2(1,delayB+1:end))/2;
BER_BPSK(1,k) = sum(abs(diffB_BPSK))/(length(bk)-delayB);
disp(sprintf('bit error probability (BPSK) = %f',BER_BPSK(1,k)));
end;
%disp(sprintf('bit error probability (BPSK) = %f',BER_BPSK(U,12)));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BER of BPSK theorey
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k=1:length(SNRdB);
Q_BPSK(k)=0.5*erfc(1/10^(-SNRdB(k)/20));
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -