通信原理 DPSK FSK ASK PSK 检波及波形实现的MATLAB程序

更新时间:2023-07-29 04:03:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

十、附录程序

程序一2ASK调制解调程序及注释

clear all close all i=10;%10个码元 j=5000; t=linspace(0,5,j);%0-5之间产生5000个点行矢量,即分成5000份 fc=10;%载波频率 fm=i/5;%码元速率 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%产生基带信号

x=(rand(1,i))%rand函数产生在0-1之间随机数,共1-10个 figure(2) plot(x) a=round(x);%随机序列,round取最接近小数的整数 figure(3) stem(a)%火柴梗状图 st=t; for n=1:10 if a(n)<1; for m=j/i*(n-1)+1:j/i*n st(m)=0; end else for m=j/i*(n-1)+1:j/i*n st(m)=1; end end end figure(1); subplot(421); plot(t,st); axis([0,5,-1,2]); title('基带信号st'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%载波

s1=cos(2*pi*fc*t); subplot(422); plot(s1); title('载波信号s1'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%调制

e_2ask=st.*s1; subplot(423); plot(t,e_2ask); title('已调信号'); noise =rand(1,j); e_2ask=e_2ask+noise;%加入噪声 subplot(424); plot(t,e_2ask); title('加入噪声的信号'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%相干解调

at=e_2ask.*cos(2*pi*fc*t); at=at-mean(at);%因为是单极性波形,还有直流分量,应去掉 subplot(425); plot(t,at); title('与载波相乘后信号'); [f,af] = T2F(t,at);%通过低通滤波器 [t,at] = lpf(f,af,2*fm); subplot(426); plot(t,at);

title('相干解调后波形'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%抽样判决

for m=0:i-1; if at(1,m*500+250)+0.5<0.5; for j=m*500+1:(m+1)*500; at(1,j)=0; end else for j=m*500+1:(m+1)*500; at(1,j)=1; end end end subplot(427); plot(t,at); axis([0,5,-1,2]); title('抽样判决后波形')

程序二2FSK调制解调程序及注释

clear all close all i=10;%基带信号码元数 j=5000; a=round(rand(1,i));%产生随机序列 t=linspace(0,5,j); f1=10;%载波1频率 f2=5;%载波2频率 fm=i/5;%基带信号频率 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%产生基带信号

st1=t; for n=1:10 if a(n)<1; for m=j/i*(n-1)+1:j/i*n st1(m)=0; end else for m=j/i*(n-1)+1:j/i*n st1(m)=1; end end end st2=t; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%基带信号求反

for n=1:j; if st1(n)>=1; st2(n)=0; else st2(n)=1; end end; figure(1); subplot(411); plot(t,st1); title('基带信号st1'); axis([0,5,-1,2]); subplot(412); plot(t,st2); title('基带信号反码st2'); axis([0,5,-1,2]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%载波信号

s1=cos(2*pi*f1*t) s2=cos(2*pi*f2*t) subplot(413),plot(s1); title('载波信号s1'); subplot(414),plot(s2); title('载波信号s2'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%调制

F1=st1.*s1;%加入载波1 F2=st2.*s2;%加入载波2 figure(2); subplot(411); plot(t,F1); title('F1=s1*st1'); subplot(412); plot(t,F2); title('F2=s2*st2'); e_fsk=F1+F2; subplot(413); plot(t,e_fsk); title('2FSK信号')%键控法产生的信号在相邻码元之间相位不一定连续 nosie=rand(1,j); fsk=e_fsk+nosie; subplot(414); plot(t,fsk); title('加噪声后信号') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%相干解调

st1=fsk.*s1;%与载波1相乘 [f,sf1] = T2F(t,st1);%通过低通滤波器 [t,st1] = lpf(f,sf1,2*fm); figure(3); subplot(311); plot(t,st1); title('与s1相乘后波形'); st2=fsk.*s2;%与载波2相乘 [f,sf2] = T2F(t,st2);%通过低通滤波器 [t,st2] = lpf(f,sf2,2*fm); subplot(312); plot(t,st2); title('与s2相乘后波形'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%抽样判决

for m=0:i-1; if st1(1,m*500+250)<st2(1,m*500+250); for j=m*500+1:(m+1)*500; at(1,j)=0; end else for j=m*500+1:(m+1)*500; at(1,j)=1; end end end; subplot(313); plot(t,at); axis([0,5,-1,2]); title('抽样判决后波形')

程序三2PSK调制解调程序及注释

clear all close all i=10; j=5000; fc=4;%载波频率

fm=i/5;%码元速率 B=2*fm; t=linspace(0,5,j); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%产生基带信号

a=round(rand(1,i));%随机序列,基带信号 figure(3); stem(a); st1=t; for n=1:10 if a(n)<1; for m=j/i*(n-1)+1:j/i*n st1(m)=0; end else for m=j/i*(n-1)+1:j/i*n st1(m)=1; end end end figure(1); subplot(411); plot(t,st1); title('基带信号st1'); axis([0,5,-1,2]); %%%%%%%%%%%&&&&&&%%%%%%%%%%%%%%%%%基带信号求反

%由于PSK中的是双极性信号,因此对上面所求单极性信号取反来与之一起构成双极性码 st2=t; for k=1:j; if st1(k)>=1; st2(k)=0; else st2(k)=1; end end; subplot(412); plot(t,st2); title('基带信号反码st2'); axis([0,5,-1,2]); st3=st1-st2; subplot(413); plot(t,st3); title('双极性基带信号st3'); axis([0,5,-2,2]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%载波信号

s1=sin(2*pi*fc*t); subplot(414); plot(s1); title('载波信号s1'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%调制

e_psk=st3.*s1; figure(2); subplot(511); plot(t,e_psk); title('e_2psk'); noise=rand(1,j); psk=e_psk+noise;%加入噪声 subplot(512); plot(t,psk); title('加噪后波形'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%相干解调

psk=psk.*s1;%与载波相乘 subplot(513);

plot(t,psk); title('与载波s1相乘后波形'); [f,af] = T2F(t,psk);%%%%%%%%%%%通过低通滤波器 [t,psk] = lpf(f,af,B); subplot(514); plot(t,psk); title('低通滤波后波形'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%抽样判决

for m=0:i-1; if psk(1,m*500+250)<0; for j=m*500+1:(m+1)*500; psk(1,j)=0; end else for j=m*500+1:(m+1)*500; psk(1,j)=1; end end end subplot(515); plot(t,psk); axis([0,5,-1,2]); title('抽样判决后波形')

程序四 2DPSK调制解调程序及注释 clear all close all i=10; j=5000; fc=4;%载波频率 fm=i/5;%码元速率 B=2*fm; t=linspace(0,5,j); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%产生基带信号

a=round(rand(1,i)); figure(4); stem(a); st1=t; for n=1:10 if a(n)<1; for m=j/i*(n-1)+1:j/i*n st1(m)=0; end else for m=j/i*(n-1)+1:j/i*n st1(m)=1; end end end figure(1); subplot(321); plot(t,st1); title('绝对码'); axis([0,5,-1,2]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%差分变换

b=zeros(1,i);%%%%%%%%全零矩阵 b(1)=a(1); for n=2:10 if a(n)>=1; if b(n-1)>=1 b(n)=0; else

b(n)=1; end else b(n)=b(n-1); end end st1=t; for n=1:10 if b(n)<1; for m=j/i*(n-1)+1:j/i*n st1(m)=0; end else for m=j/i*(n-1)+1:j/i*n st1(m)=1; end end end subplot(323); plot(t,st1); title('相对码st1'); axis([0,5,-1,2]); st2=t; for k=1:j; if st1(k)>=1; st2(k)=0; else st2(k)=1; end end; subplot(324); plot(t,st2); title('相对码反码st2'); axis([0,5,-1,2]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%载波信号 s1=sin(2*pi*fc*t); subplot(325); plot(s1); title('载波信号s1'); s2=sin(2*pi*fc*t+pi); subplot(326); plot(s2); title('载波信号s2'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%信号调制 d1=st1.*s1; d2=st2.*s2; figure(2); subplot(411); plot(t,d1); title('st1*s1'); subplot(412); plot(t,d2); title('st2*s2'); e_dpsk=d1+d2; subplot(413); plot(t,e_dpsk); title('调制后波形'); noise=rand(1,j); dpsk=e_dpsk+noise;%%%%%%%%%%加入噪声 subplot(414); plot(t,dpsk); title('加噪声后信号');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%相干解调 dpsk=dpsk.*s1;%%%%与载波s1相乘 figure(3); subplot(411); plot(t,dpsk); title('与载波相乘后波形'); [f,af]=T2F(t,dpsk);%%%%通过低通滤波器 [t,dpsk]=lpf(f,af,B); subplot(412); plot(t,dpsk); title('低通滤波后波形'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%抽样判决 st=zeros(1,i);%%全零矩阵 for m=0:i-1; if dpsk(1,m*500+250)<0; st(m+1)=0; for j=m*500+1:(m+1)*500; dpsk(1,j)=0; end else for j=m*500+1:(m+1)*500; st(m+1)=1; dpsk(1,j)=1; end end end subplot(413); plot(t,dpsk); axis([0,5,-1,2]); title('抽样判决后波形') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%码反变换 dt=zeros(1,i);%%全零矩阵 dt(1)=st(1); for n=2:10; if (st(n)-st(n-1))<=0&&(st(n)-st(n-1))>-1; dt(n)=0; else dt(n)=1; end end st=t; for n=1:10 if dt(n)<1; for m=j/i*(n-1)+1:j/i*n st(m)=0; end else for m=j/i*(n-1)+1:j/i*n st(m)=1; end end end subplot(414); plot(t,st); axis([0,5,-1,2]); title('码反变换后波形');

本文来源:https://www.bwwdw.com/article/6xdm.html

Top