原创 carrier track in matlab

2008-6-12 02:13 2173 0 1 分类: 处理器与DSP

%================= by G.S @ 607 08.05.08 ====================
clear all;
close all;
clc;
%==================================================
pi=3.1416;                      % PI
MHz=1000000;
KHz=1000;                       % kilo


%========freq vars====================
fs=4*KHz;                      % freq of sample


fc_base=0*KHz;                 % 基准频率
fc_local=0*KHz;                % now freq of local carrier
%=========global vars==================
N=fs*0.001;                           % data Length once in cycle: 1 ms


mod_track=10;
mod_rotate=10;


p_track=0;
p_rotate=0;


%==========loop filter parameters===========
K0=2^(-3);                 
K1=2^(-7);                     


%==========track var==================
d_cic_track=0;
Ri_track=zeros(1,2);              
Rq_track=zeros(1,2);
delta_phase=zeros(1,2);         % input of input of the loop filter
LF_out=zeros(1,2);              % output of the loop filter


fc_local_test=[];


%=========phase var==============
phase_local=0;
ROT=exp(-j*(phase_local));


d_cic_rotate=0;
Ri_rotate=0;              
Rq_rotate=0;


x_phy=zeros(1,2);
y_phy=0;


x_phy_test=[];


%========= NCO init============
n=0:N-1;
NCO=exp(-j*(2*pi*fc_local*n/fs));
last_phase_carrier = mod(2*pi*fc_local*(N-1)/fs,2*pi);
first_phase_carrier = last_phase_carrier + 2*pi*fc_local/fs;


%============data init============
delta_f=30;
snr=-6;
time=3;
[signal_noise,fc_in] = signal_gen(delta_f,snr,time);
%========== global switch


track_en=1;         %是否跟踪
rotate_en=1;        %是否纠相
%================================
cycle_close=length(signal_noise)/N;
for cycle="1:cycle"_close
    %=== 跟踪150ms后,频率锁定 =====================
    if(cycle*N/fs*1000 >= 500)% && track_en == 1)
        track_en = 0;
        fc_local=30+20*rand(1)-10;
    end


    %======================= get data =========================
    din = signal_noise( (cycle-1)*N+1 : cycle*N );
   
    %======================= ddc, rotate =========================
    dout_ddc = din.*NCO;


    dout_rot = dout_ddc.*ROT;
   
    %============================ freq_track 


    if(track_en==1)  
        p_track = p_track + 1;
        d_cic_track = d_cic_track + sum(dout_ddc);   


        %========================track========================
        if( p_track==mod_track )
            p_track = 0;  
            Ri_track(2) = real(d_cic_track);
            Rq_track(2) = imag(d_cic_track);
           
            %==============叉积鉴频=======
            delta_phase(2) = atan2(Ri_track(1)*Rq_track(2)-Ri_track(2)*Rq_track(1), Ri_track(1)*Ri_track(2)+Rq_track(1)*Rq_track(2))*fs/(2*pi*(N*mod_track));
            %==============环路滤波器===============================      
            LF_out(2) = (K0+K1)*delta_phase(2) - K0*delta_phase(1) + LF_out(1);
            %==============update vars=============================
            LF_out(1) = LF_out(2);
            delta_phase(1) = delta_phase(2);
            Ri_track(1) = Ri_track(2);     
            Rq_track(1) = Rq_track(2);
            d_cic_track = 0;
            %==============freq of output of the NCO===============
            fc_local = fc_local + LF_out(2);
            NCO="exp"(-j*(2*pi*fc_local*n/fs + first_phase_carrier));
            last_phase_carrier = mod(2*pi*fc_local*(N-1)/fs + first_phase_carrier, 2*pi);
            first_phase_carrier = last_phase_carrier + 2*pi*fc_local/fs;
        else
            NCO="exp"(-j*(2*pi*fc_local*n/fs + first_phase_carrier));
            last_phase_carrier = mod(2*pi*fc_local*(N-1)/fs + first_phase_carrier, 2*pi);
            first_phase_carrier = last_phase_carrier + 2*pi*fc_local/fs;
        end
    else %=== ( track_en==0 )
        NCO="exp"(-j*(2*pi*fc_local*n/fs + first_phase_carrier));
        last_phase_carrier = mod(2*pi*fc_local*(N-1)/fs + first_phase_carrier, 2*pi);
        first_phase_carrier = last_phase_carrier + 2*pi*fc_local/fs;
    end 



    if(rotate_en==1)
        p_rotate = p_rotate + 1;
        d_cic_rotate = d_cic_rotate + sum(dout_rot);
        if( p_rotate==mod_rotate )
            p_rotate = 0;
            Ri_rotate = real(d_cic_rotate);              
            Rq_rotate = imag(d_cic_rotate);
            d_cic_rotate = 0;
            %=============================
            x_phy(2) = atan2(Rq_rotate, Ri_rotate); 
            y_phy = (x_phy(1) + x_phy(2))/8;
            x_phy(1) = x_phy(2);


            phase_local = phase_local + y_phy;
            ROT = exp(-j*(phase_local));
        end
    end
    %================record NCO freq==========================               
    fc_local_test = [fc_local_test fc_local];
    x_phy_test = [x_phy_test x_phy(2)];
end


t=(1:length(fc_local_test))*N/fs*1000;
figure;
subplot(3,1,1);
plot(t,fc_local_test-fc_base,'.-b');grid on;
subplot(3,1,2);
plot(fc_in(1:4:end)-fc_local_test,'.-r');grid on;
subplot(3,1,3);
plot(t,x_phy_test*180/pi,'.-r');grid on;

PARTNER CONTENT

文章评论1条评论)

登录后参与讨论

用户169075 2008-10-6 11:43

似乎少了signal_gen子函数 能否共享 学习中
相关推荐阅读
用户148750 2008-06-21 15:30
u-boot c部分流程
c部分代码分析。...
用户148750 2008-06-21 15:26
u-boot-120 移植
支持nandflash启动,nandflash操作。修改go命令,支持kernel的引导。...
用户148750 2008-06-21 15:14
u-boot 关于代码搬移
对u-boot启动代码start.s(汇编部分)的注解。需要注意的是代码的搬运过程。对于从nandflash启动的s3c2410,上电后会自动从nandflash搬移4k代码(肯定包含start.s部...
用户148750 2008-06-21 14:15
u-boot intro
u-boot简介。u-boot命令说明。u-boot添加自定义命令流程。u-boot启动流程。...
用户148750 2008-06-12 02:55
a sample of apologyletter
        前言:真的没想到陈冠希会用全英文做道歉陈述,虽然知道他是CBC(Canadian Born Chinese),但英文水平还是让我佩服。他500多字的道歉信, 用词准确地道,词汇难度较高...
用户148750 2008-06-12 02:39
what Sharon Stone said
Well you know it was very interesting because at first, you know, I am not happy about the ways the ...
我要评论
1
0
关闭 站长推荐上一条 /3 下一条