数字2DPSK频带传输系统的设计(文内附完整代码)

使用MATLAB实现二进制数字频带系统2DPSK,完成基带信号产生、差分变换、调制解调、抽样判决、码反变换等功能。

2DPSK —— 二进制差分相移键控

码率:24Kbps
信道:高斯信道
解调采用相干解调
画出相应时域和频域波形图

RB=24000;    %码率
fs=48000; %采样率48Khz
T=1; %采样时间1S
j=fs*T; %采样点个数
i=10; %显示码元数
t=linspace(0,1,j);
fc=48000000; %载波频率 48Mhz
fm=i/5;
W=2*fm;
 
%产生基带信号(随机)
a=round(rand(1,i));
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(511);
st1_compared=st1;
plot(t*10/RB,st1); %因为显示十个码元,所以只需要横坐标囊括十个码元周期
title('绝对码');
axis([0,10/RB,-2,2]);
 
%差分变换
%0为参考位
b=zeros(1,i);%全零矩阵
if(a(1)==0)
    b(1)=0;
else
    b(1)=1;
end
for n=2:10
    if a(n)==b(n-1)
        b(n)=0;
    else
        b(n)=1;
    end
end
st1=t;
for n=1:10
    if b(n)==0
        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(512);
plot(t*10/RB,st1);
title('相对码st1');
axis([0,10/RB,-2,2]);
 
st2=t;
for k=1:j
    if st1(k)==1
        st2(k)=0;
    else
        st2(k)=1;
    end
end
subplot(513);
plot(t*10/RB,st2);
title('相对码反码st2');
axis([0,10/RB,-2,2]);
 
%载波信号
s1=sin(2*pi*fc*t);
subplot(514);
plot(t/j,s1);
axis([0,2/fc,-2,2]);
title('载波信号s1');

s2=sin(2*pi*fc*t+pi);%移了一个相位
subplot(515);
plot(t/j,s2);
axis([0,2/fc,-2,2]);
title('载波信号s2');

在这里插入图片描述

%信号调制
d1=st1.*s1;
d2=st2.*s2;
figure(2);
subplot(411);
plot(t*10/RB,d1);
title('st1*s1');
subplot(412);
plot(t*10/RB,d2);
title('st2*s2');
e_dpsk=d1+d2;
subplot(413);
plot(t*10/RB,e_dpsk);
axis([0,10/RB,-2,2]);
title('调制后波形');
[f0,af0]=T2F(t,e_dpsk);
plot(f0*j,abs(af0)); %频域波形的横坐标应该为f0乘上采样点数
title('调制后频域波形');
axis([-2*fc,2*fc,-0.1,0.3]);
 
%加噪
noise=normrnd(0,1,1,j);
dpsk=e_dpsk+noise;%加入噪声
subplot(414);
plot(t,dpsk);
axis([0,10/RB,-2,2]);
title('加噪声后信号');
[f1,af1]=T2F(t,dpsk);
plot(f1*j,abs(af1));
axis([-2*fc,2*fc,-0.1,0.3]);
title('加噪声后频域波形');

在这里插入图片描述

%相干解调
dpsk=dpsk.*s1;%与载波s1相乘
figure(3);
subplot(311);
plot(t*10/RB,dpsk);
axis([0,10/RB,-5,5]);
title('与载波相乘后时域波形');

subplot(312);
[f,af]=T2F(t,dpsk);%傅里叶变换
plot(f*j,abs(af));
axis([-3*fc,3*fc,-0.1,0.3]);
title('与载波相乘后频域波形');

[t,dpsk]=lpf(f,af,W);%通过低通滤波器,滤除部分噪声
subplot(313);
plot(t*10/RB,dpsk);
axis([0,10/RB,-2,2]);
title('低通滤波后波形');
[f_end,af_end]=T2F(t,dpsk);%傅里叶变换
plot(f_end*j,abs(af_end));
axis([-2*fc,2*fc,-0.1,0.3]);
title('低通滤波后频域波形');

在这里插入图片描述

%抽样判决
%正值判成1,负值判成0
st=zeros(1,i);%%全零矩阵
for m=0:i-1
    if dpsk(1,m*4800+2400)<0
        st(m+1)=0;
        for j=m*4800+1:(m+1)*4800
            dpsk(1,j)=0;
        end
    else
        for j=m*4800+1:(m+1)*4800
            st(m+1)=1;
            dpsk(1,j)=1;
        end
    end
end
figure(4);
subplot(311);
plot(t*10/RB,dpsk);
axis([0,10/RB,-2,2]);
title('抽样判决后波形')
 
%码反变换 
dt=zeros(1,i);%%全零矩阵
dt(1)=st(1);
for n=2:10
    if (st(n)~=st(n-1))
        dt(n)=1;
    else
        dt(n)=0;
    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(312);
plot(t*10/RB,st);
axis([0,10/RB,-2,2]);
title('码反变换后波形');

subplot(313);
plot(t*10/RB,st1_compared);
title('原绝对码');
axis([0,10/RB,-2,2]);

在这里插入图片描述
用到的自定义函数代码如下:

function [f,sf]= T2F(t,st)
%利用FFT计算信号的频谱并与信号的真实频谱的抽样比较。
%定义了函数T2F,计算信号的傅立叶变换。
dt = t(2)-t(1);
T=t(end);
df = 1/T;
N = length(st);
f=-N/2*df : df : N/2*df-df;
sf = fft(st);
sf = T/N*fftshift(sf);
end

function [t,st]=F2T(f,sf)
%定义了函数F2T,计算信号的反傅立叶变换。
df = f(2)-f(1);
Fmx = ( f(end)-f(1) +df);
dt = 1/Fmx;
N = length(sf);
T = dt*N;
%t=-T/2:dt:T/2-dt;
t = 0:dt:T-dt;
sff = fftshift(sf);
st = Fmx*ifft(sff);
end

function [t,st]=lpf(f,sf,B)
%定义了函数lpf,低通滤波
df = f(2)-f(1);
T = 1/df;
hf = zeros(1,length(f));%全零矩阵
bf = [-floor( B/df ): floor( B/df )] + floor( length(f)/2 );
hf(bf)=1;
yf=hf.*sf;
[t,st]=F2T(f,yf);
st = real(st);
end
  • 2
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

盛世危言

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值