%-----------------------------pi/4-QDPSK----------------------------------
clear all;
close all;
clc;
%--------------------------------------------------------------------------
%参数设置
Fc = 5e6;
data_len=1000;
%--------------------------------------------------------------------------
%随机产生传输信号
rand_data =randn(1,data_len);
for i=1:data_len
if rand_data(i)>=0.5
input(i)=1;
else
input(i)=0;
end
end
%--------------------------------------------------------------------------
%串并转换
for i=1:data_len
if rem(i,2)==1
if input(i)==1
I(i)=-1;
I(i+1)=-1;
else
I(i)=1;
I(i+1)=1;
end
else
if input(i)==1
Q(i-1)=-1;
Q(i)=-1;
else
Q(i-1)=1;
Q(i)=1;
end
end
end
%--------------------------------------------------------------------------
% 码变换
I_diff=zeros(1,data_len);
Q_diff=zeros(1,data_len);
I_diff(1)=I(1);
Q_diff(1)=Q(1);
for i=2:data_len
if I(i)==1&&Q(i)==1 % 0->+1 1->-1
if I_diff(i-1)==1&&Q_diff(i-1)==1
I_diff(i)=1;
Q_diff(i)=1;
elseif I_diff(i-1)==-1&&Q_diff(i-1)==1
I_diff(i)=-1;
Q_diff(i)=1;
elseif I_diff(i-1)==-1&&Q_diff(i-1)==-1
I_diff(i)=-1;
Q_diff(i)=-1;
else
I_diff(i)=1;
Q_diff(i)=-1;
end
elseif I(i)==-1&&Q(i)==1
if I_diff(i-1)==1&&Q_diff(i-1)==1
I_diff(i)=-1;
Q_diff(i)=1;
elseif I_diff(i-1)==-1&&Q_diff(i-1)==1
I_diff(i)=-1;
Q_diff(i)=-1;
elseif I_diff(i-1)==-1&&Q_diff(i-1)==-1
I_diff(i)=1;
Q_diff(i)=-1;
else
I_diff(i)=1;
Q_diff(i)=1;
end
elseif I(i)==-1&&Q(i)==-1
if I_diff(i-1)==1&&Q_diff(i-1)==1
I_diff(i)=-1;
Q_diff(i)=-1;
elseif I_diff(i-1)==-1&&Q_diff(i-1)==1
I_diff(i)=1;
Q_diff(i)=-1;
elseif I_diff(i-1)==-1&&Q_diff(i-1)==-1
I_diff(i)=1;
Q_diff(i)=1;
else
I_diff(i)=-1;
Q_diff(i)=1;
end
else
if I_diff(i-1)==1&&Q_diff(i-1)==1
I_diff(i)=1;
Q_diff(i)=-1;
elseif I_diff(i-1)==-1&&Q_diff(i-1)==1
I_diff(i)=1;
Q_diff(i)=1;
elseif I_diff(i-1)==-1&&Q_diff(i-1)==-1
I_diff(i)=-1;
Q_diff(i)=1;
else
I_diff(i)=-1;
Q_diff(i)=-1;
end
end
end
%--------------------------------------------------------------------------
%零内插
zero=5; % 采样率为25MHz
for i=1:zero*data_len
if rem(i,zero)==1
Izero(i)=I_diff(fix((i-1)/zero)+1);
Qzero(i)=Q_diff(fix((i-1)/zero)+1);
else
Izero(i)=0;
Qzero(i)=0;
end
end
%--------------------------------------------------------------------------
%脉冲成形滤波器
NT =50;
N=2*zero*NT;
Fs=25e6;
rf=0.1;
psf=rcosfir(rf,NT,zero,Fs,'sqrt');
Ipulse= conv(Izero,psf);
Qpulse= conv(Qzero,psf);
%--------------------------------------------------------------------------
%调制
for i=1:zero*data_len+N
t(i)=(i-1)/(Fc*zero);
Imod(i)=Ipulse(i).*sqrt(2)*cos(2*pi*Fc*t(i));
Qmod(i)=Qpulse(i).*(-sqrt(2)*sin(2*pi*Fc*t(i)));
end
sum=Imod+Qmod;
%--------------------------------------------------------------------------
plot(sum)
评论0