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

📄 modulator.m

📁 个人硕士论文的关于数字接收机调制解调方面的matlab程序
💻 M
字号:
%rb 码率;fc 载频; df 频偏;
%N 码元个数,L 每个码字采样数
%k 调制类型  123 2ASK,BPSK,2FSK   456 4ASK,QPSK,4FSK   78 8PSK,8FSK
%9 16QAM
function x=modulator(rb,fc,snr_in_db,k,df,N,L)
fs=rb*L;
Ns=N*L;
t=0:1/fs:(1/fs)*(Ns-1);
switch k
    case{1,2,3}
        M=2;
    case{4,5,6}
        M=4;
    case{7,8}
        M=8;
    case{9}
        M=16;
    otherwise
        disp('error')
end
%%----------------------------------------------------
%produce M rand signal with fs rate
x=zeros(1,Ns);
x=randint(1,Ns,M);
%%---------------------------------------------------
%produce Mrand signal with rb rate
for i=1:L:(Ns-L+1)
    count=zeros(1,M);
    for j=i:(i+L-1)
        h=x(j)+1;
        count(h)=count(h)+1;
    end
    [mx,indx]=max(count);
    for j=i:(i+L-1)
        x(j)=indx-1;
    end
end
%%----------------------------------------------------
%produce modulated signal
%if(nargin==4)
    %df=480;
    %end
temp=rand;phi=2*pi*temp*0;
switch k
    case 1           %2ASK
        for i=1:Ns
            x(i)=x(i)*cos(2*pi*fc*t(i)+phi);
        end
    case 2           %BPSK
        PH=[0 1];
        for i=1:Ns
            x(i)=cos(2*pi*fc*t(i)+pi*PH(x(i)+1)+phi);
        end
    case 3           %2FSK
        FD=[0 1];
        for i=1:Ns
            x(i)=cos(2*pi*(fc+FD(x(i)+1)*df)*t(i)+phi);
        end
    case 4          %4ASK
        for i=1:Ns
            x(i)=x(i)*cos(2*pi*fc*t(i)+phi);
        end
        x=x/max(x);
    case 5         %QPSK
        PH=[0 1/2 1 3/2];
        for i=1:Ns
            x(i)=cos(2*pi*fc*t(i)+pi*PH(x(i)+1)+phi);
        end
    case 6         %4FSK
        FD=[0 1 2 3]
        for i=1:Ns
            x(i)=cos(2*pi*(fc+FD(x(i)+1)*df)*t(i)+phi);
        end
    case 7         %8PSK
        PH=[0 1/4 1/2 3/4 1 5/4 3/2 7/4];
        for i=1:Ns
            x(i)=cos(2*pi*fc*t(i)+pi*PH(x(i)+1)+phi);
        end
    case 8         %8FSK
        FD=[0 1 2 3 4 5 6 7];
        for i=1:Ns
            x(i)=cos(2*pi*(fc+FD(x(i)+1)*df)*t(i)+phi);
        end
    case 9
        d=sqrt(2)/3;
        V=[-3*d 3*d;
            -d 3*d;
            d 3*d;
            3*d 3*d;
            -3*d d;
            -d d;
            d d;
            3*d d;
            -3*d -d;
            -d -d;
            d -d;
            3*d -d;
            -3*d -3*d;
            -d -3*d;
            d -3*d;
            3*d -3*d;];
        for i=1:Ns
            s=sqrt(V(x(i)+1,1)^2+V(x(i)+1,2)^2);
            p=atan(V(x(i)+1,2)/V(x(i)+1,1));
            x(i)=s*cos(2*pi*fc*t(i)+p+phi);
        end
        x=x/max(x);
    otherwise
        disp('error in K')
end
%%--------------------------------------------
%产生含高斯噪声的调制信号
snr=10^((snr_in_db)/10);
r=rand(1,Ns);
w=sqrt(mean(x.^2)/snr)*sqrt(-log(r)/2).*cos(2*pi*r);
x=x+w;

            
        

⌨️ 快捷键说明

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