⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 err2.m

📁 一个用matlab写的跳频通信系统仿真
💻 M
字号:
function [p]=err2(rho_in_dB)
rho=10^(rho_in_dB/10);
Eb=rho;
E=Eb/2;
if (rho>2),
    alpha=2/rho;
else
    alpha=1;
end;
if (E>1),
    sgma=sqrt(E/2);
else
    sgma=sqrt(1/2);
end;
N=10000;
for i=1:N,
    temp=rand;
    if (temp<0.5)
        data(i)=1;
    else
        data(i)=0;
    end;
end;

for i=1:N,
    if (data(i)==0),
        tr11c(i)=sqrt(E); tr12c(i)=sqrt(E);
        tr11s(i)=0; tr12s(i)=0;
        tr21c(i)=0; tr22c(i)=0;
        tr21s(i)=0; tr22s(i)=0;
    else
        tr11c(i)=0; tr12c(i)=0;
        tr11s(i)=0; tr12s(i)=0;
        tr21c(i)=sqrt(E); tr22c(i)=sqrt(E);
        tr21s(i)=0; tr22s(i)=0;
    end;
end;

num_of_err=0;
for i=1:N,
    if (rand<alpha),
        jamming1=1;
    else
        jamming1=0;
    end;
    if (rand<alpha),
        jamming2=1;  
    else
        jamming2=0;
    end;
    
    if (jamming1==1)
        r11c=tr11c(i)+gngauss(sgma); r11s=tr11s(i)+gngauss(sgma);
        r21c=tr21c(i)+gngauss(sgma); r21s=tr21s(i)+gngauss(sgma);
    else
        r11c=tr11c(i); r11s=tr11s(i);
        r21c=tr21c(i); r21s=tr21s(i);
    end;
    
    if (jamming2==1)
        r12c=tr12c(i)+gngauss(sgma); r12s=tr12s(i)+gngauss(sgma);
        r22c=tr22c(i)+gngauss(sgma); r22s=tr22s(i)+gngauss(sgma);
    else
        r12c=tr12c(i); r12s=tr12s(i);
        r22c=tr22c(i); r22s=tr22s(i);   
    end;
    
    if (jamming1==1),
        w1=1/sgma^2;
    else
        w1=10;
    end;
    
    if (jamming2==1),
        w2=1/sgma^2;
    else
        w2=10;
    end;
    
    r11=r11c^2+r11s^2;
    r12=r12c^2+r12s^2;
    r21=r21c^2+r21s^2;
    r22=r22c^2+r22s^2;
    
    x=w1*r11+w2*r12;
    y=w1*r21+w2*r22;
    
    if (x>y),
        decis=0;
    else
        decis=1;
    end;
     if (decis~=data(i)),
            num_of_err=num_of_err+1;
        end;
    end;
    p=num_of_err/N
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -