《2022年msk的调制解调MATLAB源代码 .pdf》由会员分享,可在线阅读,更多相关《2022年msk的调制解调MATLAB源代码 .pdf(28页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、msk 的调制解调 MATLAB源代码function out=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 差分编码后信号%*名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共
2、28 页 -%-data_diff=zeros(1,length(data);data_diff(1)=1*data(1);%1 为差分编码的初始参考值for i=2:length(data)data_diff(i)=data_diff(i-1)*data(i);end%*function signal_out,I_out,Q_out=mod_msk(data,data_len,sample_number,Rb)%MSK 基带调制%*%data 调制信号%data_len 码元个数%sample_number 每个码元采样点数名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 28
3、页 -%Rb 码元速率%signal_out 基带调制输出%I_out I 路输出%Q_out 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);%*名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 28 页 -%-%并串转换,延时I(1)=1;%fai0=0,cos(f
4、ai0)=1 for i=1:2:data_len Q(i)=data_diff(i);Q(i+1)=data_diff(i);end for i=2:2:data_len I(i+1)=data_diff(i);I(i)=data_diff(i);end for i=1:sample_number I1(i:sample_number:data_len*sample_number)=I(1:data_len);Q1(i:sample_number:data_len*sample_number)=Q(1:data_len);end%*%-%乘加权函数名师资料总结-精品资料欢迎下载-名师精心整理
5、-第 4 页,共 28 页 -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(加权前
6、 I 路);xlabel(时间);ylabel(幅度);%subplot(224)%plot(Q1,.-);title(加权前 Q 路);xlabel(时间);ylabel(幅度);名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 28 页 -%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(幅
7、度)%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 基带调制名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 28 页 -%*%data 调制信号%data_len 码元个数%sample_number
8、 每个码元采样点数%Rb 码元速率%signal_out 基带调制输出%I_out I 路输出%Q_out 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;%采样速率%-名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 28 页 -%采样for i=1:sample_number data_sample(i:sample_number:data_
9、len*sample_number)=data;end%*%-%计算相位phase=zeros(1,data_len*sample_number);phase(1)=data_sample(1)*pi/2/sample_number;for i=2:data_len*sample_number phase(i)=phase(i-1)+data_sample(i-1)*pi/2/sample_number;end%*%-%I/Q I_out=cos(phase);Q_out=sin(phase);名师资料总结-精品资料欢迎下载-名师精心整理-第 8 页,共 28 页 -%*%-%调制信号产生si
10、gnal_out=I_out+j*Q_out;%*%MSK 调制,差分解调方法一clear all close all%-%参数设置data_len=10000;%码元个数sample_number=8;%采样个数Rb=24000;%码元速率fc=96000;%载波频率名师资料总结-精品资料欢迎下载-名师精心整理-第 9 页,共 28 页 -%*%-%随机产生传输信号data=rand_binary(data_len);%*%-%MSK 基带调制signal_out,I_out,Q_out=mod_msk(data,data_len,sample_number,Rb);%*%-%中频搬移mul
11、ti=fc/Rb;I_temp=interp(I_out,multi);Q_temp=interp(Q_out,multi);名师资料总结-精品资料欢迎下载-名师精心整理-第 10 页,共 28 页 -Fs=fc*sample_number;t=1/Fs:1/Fs:length(I_temp)*1/Fs;signal_i=I_temp.*cos(2*pi*fc*t);signal_q=Q_temp.*sin(2*pi*fc*t);signal_mod=I_temp.*cos(2*pi*fc*t)-Q_temp.*sin(2*pi*fc*t);%*%-%加噪声for SNR=0:8 signal
12、_mod1=awgn(signal_mod,SNR);%-%去载波N=300;%滤波器的阶数为(N+1)F=0,fc-1000,fc+1000,Fs/2*2/Fs;A=1,1,0,0;lpf=firls(N,F,A);amp_lpf,w=freqz(lpf);I_dem=signal_mod1.*cos(2*pi*fc*t)*2;名师资料总结-精品资料欢迎下载-名师精心整理-第 11 页,共 28 页 -I_dem=conv(I_dem,lpf);I_dem=I_dem(N/2+1:N/2+length(I_temp);Q_dem=signal_mod1.*sin(2*pi*fc*t)*2;Q
13、_dem=conv(Q_dem,lpf);Q_dem=-Q_dem(N/2+1:N/2+length(I_temp);I_dem_out=zeros(1,length(I_dem)/multi);%抽取Q_dem_out=zeros(1,length(Q_dem)/multi);for i=1:length(I_dem_out)I_dem_out(i)=I_dem(multi*(i-1)+1);Q_dem_out(i)=Q_dem(multi*(i-1)+1);end;%*%-%差分解调demod_data=zeros(1,data_len);demod_data(1)=Q_dem_out(s
14、ample_number);for i=2:data_len demod_data(i)=Q_dem_out(i*sample_number)*I_dem_out(i-1)*sample_number)-名师资料总结-精品资料欢迎下载-名师精心整理-第 12 页,共 28 页 -I_dem_out(i*sample_number)*Q_dem_out(i-1)*sample_number);end%*%-%判决demod_data=demod_data0;demod_data=2*demod_data-1;%*%-%计算误码率num,ber(SNR+1)=symerr(demod_data,d
15、ata);%*end%*%-名师资料总结-精品资料欢迎下载-名师精心整理-第 13 页,共 28 页 -%误码率曲线semilogy(0:8,ber,r*-);%*%-%误码率理论值snr=0:0.1:8;for i=1:length(snr)snr1(1,i)=10(snr(1,i)/10);ps(1,i)=1/2*erfc(sqrt(snr1(1,i);pe(1,i)=2*ps(1,i);end hold on semilogy(0:.1:8,pe);%*名师资料总结-精品资料欢迎下载-名师精心整理-第 14 页,共 28 页 -%MSK 调制,差分解调方法二clear all close
16、 all%-%参数设置data_len=10000;%码元个数sample_number=8;%采样个数Rb=24000;%码元速率fc=96000;%载波频率%*%-%随机产生传输信号data=rand_binary(data_len);%*名师资料总结-精品资料欢迎下载-名师精心整理-第 15 页,共 28 页 -%-%MSK 基带调制signal_out,I_out,Q_out=mod_msk(data,data_len,sample_number,Rb);%*%-%中频搬移multi=fc/Rb;I_temp=interp(I_out,multi);Q_temp=interp(Q_ou
17、t,multi);Fs=fc*sample_number;t=1/Fs:1/Fs:length(I_temp)*1/Fs;signal_i=I_temp.*cos(2*pi*fc*t);signal_q=Q_temp.*sin(2*pi*fc*t);signal_mod=I_temp.*cos(2*pi*fc*t)-Q_temp.*sin(2*pi*fc*t);%*%-名师资料总结-精品资料欢迎下载-名师精心整理-第 16 页,共 28 页 -%加噪声for SNR=0:8 signal_mod1=awgn(signal_mod,SNR);%-%去载波N=300;%滤波器的阶数为(N+1)F=
18、0,fc-1000,fc+1000,Fs/2*2/Fs;A=1,1,0,0;lpf=firls(N,F,A);amp_lpf,w=freqz(lpf);I_dem=signal_mod1.*cos(2*pi*fc*t)*2;I_dem=conv(I_dem,lpf);I_dem=I_dem(N/2+1:N/2+length(I_temp);Q_dem=signal_mod1.*sin(2*pi*fc*t)*2;Q_dem=conv(Q_dem,lpf);Q_dem=-Q_dem(N/2+1:N/2+length(I_temp);I_dem_out=zeros(1,length(I_dem)/m
19、ulti);%抽取Q_dem_out=zeros(1,length(Q_dem)/multi);for i=1:length(I_dem_out)名师资料总结-精品资料欢迎下载-名师精心整理-第 17 页,共 28 页 -I_dem_out(i)=I_dem(multi*(i-1)+1);Q_dem_out(i)=Q_dem(multi*(i-1)+1);end;%*%-%差分解调demod_data=zeros(1,data_len);demod_data(1)=Q_dem_out(sample_number);for i=2:2:data_len demod_data(i)=-I_dem_
20、out(i*sample_number)*Q_dem_out(i-1)*sample_number);end for i=3:2:data_len demod_data(i)=Q_dem_out(i*sample_number)*I_dem_out(i-1)*sample_number);end%*%-名师资料总结-精品资料欢迎下载-名师精心整理-第 18 页,共 28 页 -%判决demod_data=demod_data0;demod_data=2*demod_data-1;%*%-%计算误码率num,ber(SNR+1)=symerr(demod_data,data);%*end%*%-
21、%误码率曲线semilogy(0:8,ber,r*);%*%-名师资料总结-精品资料欢迎下载-名师精心整理-第 19 页,共 28 页 -%误码率理论值snr=0:0.1:8;for i=1:length(snr)snr1(1,i)=10(snr(1,i)/10);ps(1,i)=1/2*erfc(sqrt(snr1(1,i);pe(1,i)=2*ps(1,i);end hold on semilogy(0:.1:8,pe);%*%MSK 调制,解调名师资料总结-精品资料欢迎下载-名师精心整理-第 20 页,共 28 页 -clear all close all%-%参数设置data_len=
22、30000;%码元个数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);名师资料总结-精品资料欢迎下载-名师精心整理-第 21 页,共 28 页 -%*%-%中频搬移multi=fc/Rb;I_temp=interp(I_out,multi);Q_temp=interp(Q_out,multi);Fs=fc*sampl
23、e_number;t=1/Fs:1/Fs:length(I_temp)*1/Fs;signal_i=I_temp.*cos(2*pi*fc*t);signal_q=Q_temp.*sin(2*pi*fc*t);signal_mod=I_temp.*cos(2*pi*fc*t)-Q_temp.*sin(2*pi*fc*t);%signal_mod1=real(I_temp+j*Q_temp).*exp(j*2*pi*fc*t);%*%-%加噪声for SNR=0:8 signal_mod1=0.01*awgn(signal_mod,SNR);名师资料总结-精品资料欢迎下载-名师精心整理-第 22
24、 页,共 28 页 -%-%去载波N=300;%滤波器的阶数为(N+1)F=0,fc-1000,fc+1000,Fs/2*2/Fs;A=1,1,0,0;lpf=firls(N,F,A);amp_lpf,w=freqz(lpf);I_dem=signal_mod1.*cos(2*pi*fc*t)*2.*cos(pi*t*Rb/2);I_dem=conv(I_dem,lpf);I_dem=I_dem(N/2+1:N/2+length(I_temp);Q_dem=signal_mod1.*sin(2*pi*fc*t)*2.*sin(pi*t*Rb/2);Q_dem=conv(Q_dem,lpf);Q
25、_dem=-Q_dem(N/2+1:N/2+length(I_temp);I_dem_out=zeros(1,length(I_dem)/multi);%抽取Q_dem_out=zeros(1,length(Q_dem)/multi);for i=1:length(I_dem_out)I_dem_out(i)=I_dem(multi*(i-1)+1);Q_dem_out(i)=Q_dem(multi*(i-1)+1);end;名师资料总结-精品资料欢迎下载-名师精心整理-第 23 页,共 28 页 -%*%-%解调,判决demod_data=zeros(1,data_len);for i=1:
26、data_len I_dem1(i)=I_dem_out(i*sample_number)0;Q_dem1(i)=Q_dem_out(i*sample_number)0;end for i=1:2:data_len m1(i)=Q_dem1(i);end for i=2:2:data_len m1(i)=I_dem1(i);end m1=2*m1-1;%*%-%差分解码名师资料总结-精品资料欢迎下载-名师精心整理-第 24 页,共 28 页 -demod_data=zeros(1,data_len);demod_data(1)=1*m1(1);for i=2:data_len demod_da
27、ta(i)=m1(i-1)*m1(i);end%*%-%计算误码率num,ber(SNR+1)=symerr(demod_data,data);%*end%/for snr%*%-%误码率曲线semilogy(0:8,ber,r*-);%*名师资料总结-精品资料欢迎下载-名师精心整理-第 25 页,共 28 页 -%-%误码率理论值snr=0:0.1:8;for i=1:length(snr)snr1(1,i)=10(snr(1,i)/10);ps(1,i)=1/2*erfc(sqrt(snr1(1,i);pe(1,i)=2*ps(1,i);end hold on semilogy(0:.1:
28、8,pe);%*名师资料总结-精品资料欢迎下载-名师精心整理-第 26 页,共 28 页 -function data_binary,data_binary1=rand_binary(data_len);%随机产生一个二进制序列作为仿真用的消息序列%*%data 序列长度%data_binary 产生的二进制序列%*%-data1=randn(1,data_len);data_binary=zeros(1,data_len);data_binary1=zeros(1,data_len);for i=1:data_len if data1(i)0 data_binary(i)=-1;data_binary1(i)=0;else data_binary(i)=1;data_binary1(i)=1;名师资料总结-精品资料欢迎下载-名师精心整理-第 27 页,共 28 页 -end end 名师资料总结-精品资料欢迎下载-名师精心整理-第 28 页,共 28 页 -