如何修复 MATLAB 中的频率偏移?
How to fix a shift in frequency in MATLAB?
我正在尝试模拟一个非理想的零阶保持,但我的频率正在增加。这是我的代码:
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
在下图中,我得到的是蓝色迹线,而它看起来应该类似于橙色迹线:
没有频移,这是因为没有足够的样本来跟随蓝线。红色曲线有
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 个样本)之外,所有代码都是相同的。得到如下图:
现在两者很好地重叠,所以您可以看到没有频移。
我正在尝试模拟一个非理想的零阶保持,但我的频率正在增加。这是我的代码:
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
在下图中,我得到的是蓝色迹线,而它看起来应该类似于橙色迹线:
没有频移,这是因为没有足够的样本来跟随蓝线。红色曲线有
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 个样本)之外,所有代码都是相同的。得到如下图:
现在两者很好地重叠,所以您可以看到没有频移。