代码之家  ›  专栏  ›  技术社区  ›  Christiana S. F. Chamon

如何在MATLAB中修复频率偏移?

  •  0
  • Christiana S. F. Chamon  · 技术社区  · 7 年前

    我试图模拟一个非理想的零阶保持,但我得到了频率的增加。这是我的代码:

    amp = 1;
    f = 1e9;
    fs = 10e9;
    phase = 90;
    phase = phase/180*pi;
    Ts = 1/fs;
    start = 0;
    cycles = 10;
    duration = cycles * Ts;
    ts = start:Ts:duration;
    vin = amp*cos(2*pi*f*ts + phase);
    t = start:0.0001*Ts:duration;
    v0 = 0;
    vf = vin;
    tau = 10e-12;
    m = length(t);
    n = length(ts);
    sections = m/n;
    vt = zeros(n,sections);
    temp = vector2matrix(t,sections);
    for ii = 1:1:n
        for jj = 1:1:sections
            vt(ii,jj) = vf(ii) + (v0 - vf(ii))*exp(-temp(ii,jj)/tau); %ZOH formula
        end
    end
    vt = vt';
    vt = vt(:)';
    figure;
    plot(t,vt);%xlim([0 0.1e-9]);
    hold on
    stairs(ts,vf);
    hold off
    

    在下图中,我得到了蓝色的痕迹,而它应该看起来像橙色的痕迹:

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  1
  •   ViG    7 年前

    没有频移,这是因为没有足够的样本来跟踪蓝线。红色曲线具有

    ts =1.0e-09 *[0    0.1000    0.2000    0.3000    0.4000    0.5000    0.6000    0.7000    0.8000    0.9000    1.0000]
    

    ,因此与蓝色曲线相比,它显示函数的点要少得多。在这些点上,蓝色和红色曲线重合,因此它们是正确的。另一种方法是在 ts . 考虑以下代码:

    ...
    cycles = 12;
    duration = cycles * Ts;
    ts = start:.8*Ts:duration-.8*Ts;
    vin = amp*cos(2*pi*f*ts + phase);
    t = start:0.0001*Ts:duration-0.0001*Ts;
    ...
    figure;
    plot(t,vt,'k');%xlim([0 0.1e-9]);
    hold on
    stairs(ts,vf,'y--');
    hold off 
    

    除了循环次数和步骤外,所有代码都相同 ts (现在增加了4个样本)。获得以下图表:

    现在这两者很好地重叠,所以你可以看到没有频率偏移。