得出的结果图好乱,不是书上那种,主要是error问题
using TyPlot
using TyMath
wm = 1;
wc = 1.1wm;
Ts = 0.7pi/wm;
ws = 2pi/Ts;
n = -100:100;
nTs = nTs;
f = sinc.(nTs/pi); # 使用点操作符进行元素级的 sinc 计算
Dt = 0.005;
t = -15:Dt:15;
t_vector = collect(t); # 将范围转换为向量
创建与t_vector相同长度的矩阵,每行都是nTs的值
nTs_matrix = repeat(nTs, 1, length(t_vector));
创建与nTs相同长度的矩阵,每列都是t_vector的值
t_matrix = repeat(t_vector', length(nTs), 1); # 使用转置以匹配维度
确保t_matrix和nTs_matrix维度匹配
由于nTs_matrix和t_matrix的维度已经匹配,我们可以直接进行运算
fa = f .* Ts * wc/pi .* sinc.((wc/pi) .* (t_matrix .- nTs_matrix));
计算 sinc.(t/pi) 并确保其维度与fa相同
sinc_t = sinc.(t / pi);
sinc_t_matrix = repeat(sinc_t', length(nTs), 1); # 将sinc_t转置并扩展成与fa相同维度的矩阵
计算error
error = abs.(fa .- sinc_t_matrix);
绘图
t1=-15:0.5:15;
f1=sinc(t1/pi);
subplot(311);
stem(t1,f1);
xlabel("kTs");
ylabel("f(kTs)");
title("sa(t)=sinc(t/pi)的采样信号");
subplot(312);
plot(t,fa)
xlabel("t");
ylabel("fa(t)");
title("由sa(t)=sinc(t/pi)的采样信号重构sa(t)");
subplot(313);
plot(t,error);
xlabel("t");
ylabel("error(t)");