要求是:发送二进制信息为1,0,0,1,1,1,0,1,码元速率为1波特,载波为cosωt,幅值为1,初始相位为0。当载波频率为2Hz,相位(或相位差)0°代表“0”,相位(或相位差)180°代表“1”。
测试结果
明明采用的是同一个时间长度t,为什么DPSK的X轴刻度会大10倍呢?
而且文中的.*(t>=t_begin&t<t_end)是具体什么作用,先t=0:0.01:10设置一个容器,然后再把值存储进去?
代码
fs=12 %采样频率,取载波频域的6倍
Ts=1/fs
fc=2 %载波频率
Rb=1
Tb=1/Rb %传输信息速率,Rb = RB * log2M
t=0:0.01:10
binary_msg=[1 0 0 1 1 1 0 1]
len_bmsg=length(binary_msg);
%绘制调制信号
t_begin=0
t_end=1
mt=0
for i=1:len_bmsg
if(binary_msg(i)==1)
mt=mt+1.*(t>=t_begin&t<t_end)
else mt=mt+0.*(t>=t_begin&t<t_end)
end
t_begin=t_begin+1
t_end=t_end+1
end
figure
subplot(2,2,1)
plot(t,mt);
ylim([-0.25,1.25]);
title('调制信号')
%调制PSK
PSK=0
t_begin=0
t_end=1
for i=1:len_bmsg
if(binary_msg(i)==1)
PSK=PSK+cos(2*pi*fc*t).*(t>=t_begin&t<t_end)
else PSK=PSK+cos(2*pi*fc*t+pi).*(t>=t_begin&t<t_end)
end
t_begin=t_begin+1
t_end=t_end+1
end
subplot(2,2,3)
plot(t,PSK);
ylim([-1.5,1.5]);
title('2PSK信号')
%调制ASK
t_begin=0
t_end=1
ASK=0
for i=1:len_bmsg
if(binary_msg(i)==1)
ASK=ASK+cos(2*pi*fc*t).*(t>=t_begin&t<t_end)
else ASK=ASK+0.*(t>=t_begin&t<t_end)
end
t_begin=t_begin+1
t_end=t_end+1
end
subplot(2,2,2)
plot(t,ASK);
ylim([-1.5,1.5]);
title('2ASK信号')
%调制DPSK
md=0
ti_begin=0
ti_end=1
%码型变换-相对码
DiffBits = zeros(len_bmsg+1,1); %码元长度增加了
for i = 2:len_bmsg+1
DiffBits(i) =mod( DiffBits(i - 1) + binary_msg(i-1) , 2 );
end
%码型变换至双极性不归零码
Diffbb = 2*DiffBits- 1;
for j=1:length(Diffbb)
if(Diffbb(j)==-1)
md=md+(-1).*(t>=ti_begin&t<ti_end)
else md=md+1.*(t>=ti_begin&t<ti_end)
end
ti_begin=ti_begin+1
ti_end=ti_end+1
end
DBPSK = md .* cos(2* pi * fc * t);
subplot(2,2,4)
plot(DBPSK);
xlim([0,1000])
ylim([-1.5,1.5]);
title('DBPSK信号')
参考这两篇文章
https://blog.csdn.net/weixin_43861730/article/details/103576018