Pluto-Network/code/matlab/BPSK/receiver/rx_timing_recovery.m

94 lines
2.7 KiB
Matlab
Raw Permalink Normal View History

2018-01-30 06:11:44 +00:00
function [time_error,iq] = rx_timing_recovery(signal)
N=ceil((length(signal))/4);
Ns=4*N; %<25>ܵIJ<DCB5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bt=2e-2/1.3;
c1=8/3*bt;
c2=32/9*bt*bt;
w=[0.5,zeros(1,N-1)]; %<25><>·<EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>Ϊ0.5
n=[0.9,zeros(1,Ns-1)]; %NCO<43>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>Ϊ0.9
n_temp=[n(1),zeros(1,Ns-1)];
u=[0.6,zeros(1,2*N-1)]; %NCO<43><4F><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>Ϊ0.6
out_signal_I=zeros(1,2*N); %I·<49>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
out_signal_Q=zeros(1,2*N); %Q·<51>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
time_error=zeros(1,N); %Gardner<65><72>ȡ<EFBFBD><C8A1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
ik=time_error;
qk=time_error;
k=1; %<25><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾTiʱ<69><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾu,yI,yQ
ms=1; %<25><><EFBFBD><EFBFBD>ָʾT<CABE><54>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ָʾa,b<>Լ<EFBFBD>w
strobe=zeros(1,Ns);
aI=real(signal);
bQ=imag(signal);
ns=length(aI)-1;
i=1;
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);
%<25>ڲ<EFBFBD><DAB2>˲<EFBFBD><CBB2><EFBFBD>ģ<EFBFBD><C4A3>
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);
out_signal_I(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);
out_signal_Q(k)=(FQ1*u(k)+FQ2)*u(k)+FQ3;
strobe(k)=mod(k,2);
<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡģ<C8A1><EFBFBD><E9A3AC><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>Gardner<65>
if(strobe(k)==0)
<><C8A1><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
ik(ms)=out_signal_I(k);
qk(ms)=out_signal_Q(k);
%ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>ż<EFBFBD><C5BC><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(k>2)
Ia=(out_signal_I(k)+out_signal_I(k-2))/2;
Qa=(out_signal_Q(k)+out_signal_Q(k-2))/2;
time_error(ms)=[out_signal_I(k-1)-Ia]*(out_signal_I(k)-out_signal_I(k-2))+[out_signal_Q(k-1)-Qa]*(out_signal_Q(k)-out_signal_Q(k-2));
else
time_error(ms)=(out_signal_I(k-1)*out_signal_I(k)+out_signal_Q(k-1)*out_signal_Q(k));
end
%<25><>·<EFBFBD>˲<EFBFBD><CBB2><EFBFBD>,ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>ż<EFBFBD><C5BC><EFBFBD>һ<EFBFBD>λ<EFBFBD>·<EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(ms>1)
w(ms+1)=w(ms)+c1*(time_error(ms)-time_error(ms-1))+c2*time_error(ms-1);
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
iq=ik+1i*qk;
c1=max([abs(real(iq)),abs(imag(iq))]);
iq=iq ./c1;
% figure(1);
% subplot(311);
% plot(u);
% xlabel('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
% ylabel('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
% grid on;
% subplot(312);
% plot(time_error);
% xlabel('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
% ylabel('<27><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>');
% grid on;
% subplot(313);
% plot(w);
% xlabel('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
% ylabel('<27><>·<EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
% grid on;
end