程序:
%定时恢复程序:
clear all
N=6000; %符号数
K=4; %每个符号采4个样点
Ns=K*N; %总的采样点数
w=[0.5,zeros(1,N-1)]; %环路滤波器输出寄存器,初值设为0.5
n=[0.7 zeros(1,Ns-1)]; %NCO寄存器,初值设为0.9
n_temp=[n(1),zeros(1,Ns-1)];
u=[0.6,zeros(1,2*N-1)];%NCO输出的定时分数间隔寄存器,初值设为0.6
yI=zeros(1,2*N); %I路内插后的输出数据
yQ=zeros(1,2*N); %Q路内插后的输出数据
time_error=zeros(1,N); %Gardner提取的时钟误差寄存器
i=1; %用来表示Ts的时间序号,指示n,n_temp,nco,
k=1; %用来表示Ti时间序号,指示u,yI,yQ
ms=1; %用来指示T的时间序号,用来指示a,b以及w
strobe=zeros(1,Ns);
c1=5.41*10^(-3); c2=3.82*10^(-6); %环路滤波器系数
%############################
%这段代码是原程序中仿真输入的psk数据
bitstream=randint(1,N,2);
psk2=pskmod(bitstream,2);
xI=zeros(1,Ns);
xQ=zeros(1,Ns);
xI(1:8:8*N)=real(psk2);%8倍插值?为何要这样设计
xQ(1:8:8*N)=imag(psk2);
%截短后的根升余弦匹配滤波器
h1=rcosfir(0.5,[-8,8],4,1,'sqrt');
hw=kaiser(65,3.97);
hh=h1.*hw.';aI1=conv(xI,h1);
bQ1=conv(xQ,h1);
L=length(aI1);
%仿真输入数据
aI=[aI1(26:2:L),0,0];%2倍抽取?为何先8倍插值,再2倍抽取?
bQ=[bQ1(26:2:L),0,0];
%##############################
ns=length(aI)-2;
while(i<ns)
n_temp(i+1)=n(i)-w(ms);
if(n_temp(i+1)>0)
n(i+1)=n_temp(i+1);
else
n(i+1)=mod(n_temp(i+1),1);
%内插滤波器模块
FI1=0.5*aI(i+2)-0.5*aI(i+1)-0.5*aI(i)+0.5*aI(i-1);
FI2=1.5*aI(i+1)-0.5*aI(i+2)-0.5*aI(i)-0.5*aI(i-1);
FI3=aI(i);
yI(k)=(FI1*u(k)+FI2)*u(k)+FI3;
FQ1=0.5*bQ(i+2)-0.5*bQ(i+1)-0.5*bQ(i)+0.5*bQ(i-1);
FQ2=1.5*bQ(i+1)-0.5*bQ(i+2)-0.5*bQ(i)-0.5*bQ(i-1);
FQ3=bQ(i);
yQ(k)=(FQ1*u(k)+FQ2)*u(k)+FQ3;
strobe(k)=mod(k,2);
%时钟误差提取模块,采用的是GARDNER算法
if(strobe(k)==0)
%每个数据符号计算一次时钟误差
if(k>2)
time_error(ms)=yI(k-1)*(yI(k)-yI(k-2))+yQ(k-1)*(yQ(k)-yQ(k-2));
else
time_error(ms)=(yI(k-1)*yI(k)+yQ(k-1)*yQ(k));
end
%环路滤波器.每个数据符号计算一次环路滤波器输出
if(ms>1)
w(ms+1)=w(ms)+c1*(time_error(ms)-time_error(ms-1))+c2*time_error(ms);
else
w(ms+1)=w(ms)+c1*time_error(ms)+c2*time_error(ms);
end
ms=ms+1;
end
k=k+1;
u(k)=n(i)/w(ms);
end
i=i+1;
end
figure(1);
subplot(311);plot(u);
subplot(312);plot(time_error);
subplot(313);plot(w);
%##############################
% bt=0.01;
% c1=8/3*bt;
% c2=c1*4/3*bt;
N=6000; %符号数
K=4; %每个符号采4个样点
Ns=K*N; %总的采样点数
w=[0.5,zeros(1,N-1)]; %环路滤波器输出寄存器,初值设为0.5
n=[0.7 zeros(1,Ns-1)]; %NCO寄存器,初值设为0.9
n_temp=[n(1),zeros(1,Ns-1)];
u=[0.6,zeros(1,2*N-1)];%NCO输出的定时分数间隔寄存器,初值设为0.6
yI=zeros(1,2*N); %I路内插后的输出数据
yQ=zeros(1,2*N); %Q路内插后的输出数据
time_error=zeros(1,N); %Gardner提取的时钟误差寄存器
i=1; %用来表示Ts的时间序号,指示n,n_temp,nco,
k=1; %用来表示Ti时间序号,指示u,yI,yQ
ms=1; %用来指示T的时间序号,用来指示a,b以及w
strobe=zeros(1,Ns);
bitstream=randint(1,N,2);
psk2=pskmod(bitstream,2);
%直接对psk调制信号进行4倍插值滤波后得到仿真数据
aI=rcosflt(real(psk2),1,4,'sqrt',0.5);
bQ=rcosflt(imag(psk2),1,4,'sqrt',0.5);
%采用这种数据产生方式,从仿真波形看为何不收敛?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ns=length(aI)-16;
while(i<ns)
n_temp(i+1)=n(i)-w(ms);
if(n_temp(i+1)>0)
n(i+1)=n_temp(i+1);
else
n(i+1)=mod(n_temp(i+1),1);
%内插滤波器模块
FI1=0.5*aI(i+2)-0.5*aI(i+1)-0.5*aI(i)+0.5*aI(i-1);
FI2=1.5*aI(i+1)-0.5*aI(i+2)-0.5*aI(i)-0.5*aI(i-1);
FI3=aI(i);
yI(k)=(FI1*u(k)+FI2)*u(k)+FI3;
FQ1=0.5*bQ(i+2)-0.5*bQ(i+1)-0.5*bQ(i)+0.5*bQ(i-1);
FQ2=1.5*bQ(i+1)-0.5*bQ(i+2)-0.5*bQ(i)-0.5*bQ(i-1);
FQ3=bQ(i);
yQ(k)=(FQ1*u(k)+FQ2)*u(k)+FQ3;
strobe(k)=mod(k,2);
%时钟误差提取模块,采用的是GARDNER算法
if(strobe(k)==0)
%每个数据符号计算一次时钟误差
if(k>2)
time_error(ms)=yI(k-1)*(yI(k)-yI(k-2))+yQ(k-1)*(yQ(k)-yQ(k-2));
else
time_error(ms)=(yI(k-1)*yI(k)+yQ(k-1)*yQ(k));
end
%环路滤波器.每个数据符号计算一次环路滤波器输出
if(ms>1)
w(ms+1)=w(ms)+c1*(time_error(ms)-time_error(ms-1))+c2*time_error(ms);
else
w(ms+1)=w(ms)+c1*time_error(ms)+c2*time_error(ms);
end
ms=ms+1;
end
k=k+1;
u(k)=n(i)/w(ms);
end
i=i+1;
end
figure(2);
subplot(311);plot(u);
subplot(312);plot(time_error);
subplot(313);plot(w);
|