msk的调制解调MATLAB源代码本文由shenfei20贡献msk的调制解调MATLAB源代码functionout=delay(data,n,sample_number)%data:延迟的数据%n:延迟码元个数%sample_number:码元采样个数out=zeros(1,length(data));out(n*sample_number+1:length(data))=data(1:length(data)-n*sample_number);function[data_diff]=difference(data)%差分编码%**************************************************************************%data%data_diff输入信号差分编码后信号%**************************************************************************%-------------------------------------------------------------------------data_diff=zeros(1,length(data));data_diff(1)=1*data(1);fori=2:length(data)data_diff(i)=data_diff(i-1)*data(i);end%**************************************************************************%1为差分编码的初始参考值function[signal_out,I_out,Q_out]=mod_msk(data,data_len,sample_number,Rb)%MSK基带调制%**************************************************************************%data%data_len调制信号码元个数每个码元采样点数%sample_number%Rb%signal_out%I_out%Q_out码元速率基带调制输出I路输出Q路输出%**************************************************************************%data_len=10;%sample_number=8;%Rb=16000;%码元个数%采样点数%码元速率%data1=randint(1,data_len);%data=2*data1-1;%传输的序列Tb=1/Rb;fs=Rb*sample_number;%码元时间%采样速率%-------------------------------------------------------------------------%差分编码[data_diff]=difference(data);%**************************************************************************%-------------------------------------------------------------------------%并串转换,延时I(1)=1;%fai0=0,cos(fai0)=1fori=1:2:data_lenQ(i)=data_diff(i);Q(i+1)=data_diff(i);endfori=2:2:data_lenI(i+1)=data_diff(i);I(i)=data_diff(i);endfori=1:sample_numberI1(i:sample_number:data_len*sample_number)=I(1:data_len);Q1(i:sample_number:data_len*sample_number)=Q(1:data_len);end%**************************************************************************%-------------------------------------------------------------------------%乘加权函数t=1/fs:1/fs:data_len*Tb;I_out=I1.*cos(pi*t/2/Tb);Q_out=Q1.*sin(pi*t/2/Tb);%**************************************************************************%-------------------------------------------------------------------------%调制信号产生signal_out=I_out+j*Q_out;%**************************************************************************%%-------------------------------------------------------------------------%%画图%subplot(221)%plot(data,'.-');title('MSK传输的数据');xlabel('时间');ylabel('幅度')%subplot(222)%plot(data_diff,'.-');title('差分后的数据');xlabel('时间');ylabel('幅度')%subplot(223)%plot(I1,'.-');title('加权前I路');xlabel('时间');ylabel('幅度');%subplot(224)%plot(Q1,'.-');title('加权前Q路');xlabel('时间');ylabel('幅度');%%figure(2)%subplot(221)%plot(cos(pi*t/2/Tb),'.-');title('加权函数cos(πt/(2Tb))');xlabel('时间');ylabel('幅度')%subplot(222)%plot(sin(pi*t/2/Tb),'.-');title('加权函数sin(πt/(2Tb))');xlabel('时间');ylabel('幅度')%subplot(223)%plot(I_out,'.-');title('加权后I路');xlabel('时间');ylabel('幅度');%subplot(224)%plot(Q_out,'.-');title('加权后Q路');xlabel('时间');ylabel('幅度');%%**************************************************************************function[signal_out,I_out,Q_out,phase]=mod_msk2(data,data_len,sample_number,Rb)%MSK基带调制%**************************************************************************%data%data_len调制信号码元个数每个码元采样点数%sample_number%Rb%signal_out%I_out%Q_out码元速率基带调制输出I路输出Q路输出%**************************************************************************%data_len=10;%sample_number=8;%Rb=16000;%码元个数%采样点数%码元速率%data1=randint(1,data_len);%data=2*data1-1;%传输的序列Tb=1/Rb;fs=Rb*sample_number;%码元时间%采样速率%--------------------------------------------------------------------------%采样fori=1:sample_numberdata_sample(i:sample_number:data_len*sample_number)=data;end%**************************************************************************%-------------------------------------------------------------------------%计算相位phase=zeros(1,data_len*sample_number);phase(1)=data_sample(1)*pi/2/sample_number;fori=2:data_len*sample_numberphase(i)=phase(i-1)+data_sample(i-1)*pi/2/sample_number;end%**************************************************************************%-------------------------------------------------------------------------%I/QI_out=cos(phase);Q_out=sin(phase);%**************************************************************************%-------------------------------------------------------------------------%调制信号产生signal_out=I_out+j*Q_out;%**************************************************************************%MSK调制,差分解调方法一clearallcloseall%-------------------------------------------------------------------------%参数设置data_len=10000;sample_number=8;Rb=24000;fc=96000;%码元个数%采样个数%码元速率%载波频率%**************************************************************************%-------------------------------------------------------------------------%随机产生传输信号data=rand_binary(data_len);%**************************************************************************%-------------------------------------------------------------------------%MSK基带调制[signal_out,I_out,Q_out]=mod_msk(data,data_len,sample_number,Rb);%**********************************