% communication DPSK demodulation
% name:Chen Yu
% student ID:12353032
function Lab9
%
% 参数设置
%
Ts=1/100; %码元周期
Rs=1/Ts; %码元频率
n1=10; %载波频率系数
fc=Rs*n1; %载波频率
n2=64; %采样频率系数
fs=fc*n2; %采样频率,N_sample = 640
N_sample=fs*Ts; %每个码元的抽样点数=n1*n2,经测试小于128时,效果较差
dt=Ts/N_sample; %抽样时间间隔
N=10; %码元数
t=0:dt:((N+1)*N_sample-1)*dt;%传输序列持续时间,考虑了参考电平0
%
%基本码元g(t)=1,还有高斯白噪声
%
gt=cos(2*pi*fc*t(1:N_sample)+pi); %相位pi对应码元1
%噪声,均值=0,标准差=0.01
noise=normrnd(0,0.1,1,length(t));
s=zeros(1,(N+1)*N_sample);%采样点
absolute_code = randi([0,1],1,N); %生成绝对码
relative_code = zeros(1,N+1);
relative_code(1) = 0; %参考码元为0,为第一个码元
for k = 2:N+1
relative_code(k) = xor(absolute_code(k-1),relative_code(k-1));%生成相对码
end
%生成调制信号
s(1:N_sample) = -1*gt;
for i = 2:N+1
if relative_code(i) == 1 %得到波形图
s((i-1)*N_sample+1:i*N_sample) = gt; %码元为1
else
s((i-1)*N_sample+1:i*N_sample) = -1*gt; %码元为0
end
end
figure(1);
plot(t,s);
title('调制信号前两个码元');
axis([0,0.02,-1.5,1.5]);
grid on
%加入高斯白噪声
st = s + noise;
figure(2);
plot(t,st);
title('加入高斯白噪声后,调制信号前两个码元');
axis([0,0.02,-1.5,1.5]);
grid on
%带通滤波,去除AWGN
w1 = 2*(fc-Rs)/fs; %下截止频率
w2 = 2*(fc+Rs)/fs; %上截止频率
numerator= fir1(60,[w1,w2]); %FIR滤波器,numerator是FIR滤波器的系数
sfBandpass=filter(numerator,1,st); %st为时间信号
figure(3);
plot(t,sfBandpass);
title('通过带通滤波器后,调制信号前两个码元');
axis([0,0.02,-1.5,1.5]);
grid on
%进行相干解调
sfModulation = sfBandpass.*cos(2*pi*fc*t);
figure(4);
plot(t,sfModulation);
title('通过解调后,解调信号前两个码元');
axis([0,0.02,-1.5,1.5]);
grid on
%低通滤波
w1 = [];
w2 = 2*(Rs)/fs; %截止频率
numerator= fir1(60,[w1,w2]); %FIR滤波器,numerator是FIR滤波器的系数
sfLowpass=filter(numerator,1,sfModulation); %st为时间信号
figure(5);
plot(t,sfLowpass);
title('通过低通滤波器后的调制信号');
axis([0,0.1,-1.5,1.5]);
grid on
%抽样判决,我选取的是中间时刻
decide=zeros(1,N+1);
for k=1:N+1
if(sfLowpass((k-1)*N_sample+N_sample/2)>0)
decide(k)=1;
else
decide(k)=0;
end
end
%还原绝对码
get_absolute_code = zeros(1,N);
for j = 1:N
get_absolute_code(j) = xor(decide(j),decide(j+1));
end
%画出绝对码前后对比
n=1:N;
%输出原始码元
figure(6);
stem(n,absolute_code,'r','LineStyle','none');
%输出解调码元
hold on
stem(n,get_absolute_code,'*','b','LineStyle','none');
hleg=legend('原始码元','解调码元');
set(hleg,'Location','Northeast');
Matlab之DPSK
最新推荐文章于 2022-12-29 20:15:20 发布