专栏
标签
信号采样与重构
一般问题
发布于 2024-12-24 10:02:13
查看 25过去552天

using TyPlot
using TyMath

wm = 1;
wc = 1.1wm;
Ts = 0.7
pi/wm;
ws = 2pi/Ts;
n = -100:100;
nTs = n
Ts;

f = sinc.(nTs/pi);

Dt = 0.005;
t = -15:Dt:15;
t_vector = collect(t);
nTs_matrix = repeat(nTs, 1, length(t_vector));

t_matrix = repeat(t_vector', length(nTs), 1);

fa = f .* Ts * wc/pi .* sinc.((wc/pi) .* (t_matrix .- nTs_matrix));

sinc_t = sinc.(t / pi);
sinc_t_matrix = repeat(sinc_t', length(nTs), 1);

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)");

tightlayout()
我的问题是该代码得出的结果图Snipaste_2024-12-24_08-58-30.png与书上的微信图片_20241224100111.jpg不一样,不知道问题出在哪里?求解答

所属专栏:Julia语言
产品信息:Syslab科学计算环境
控制工程
采纳的回答
发布于 2024-12-24 14:19:59

您好,这里主要在f以及fa的计算,f按照您代码中的定义得到的结果是向量,按照书中的定义f应该是矩阵,那么向量使用点乘矩阵的结果和矩阵乘以矩阵的结果是不一致的。一下代码可供参考。

wm=1;
wc=1.1*wm; 
Ts=0.7*pi/wm;
ws=2*pi/Ts;
n=-100:100;
nTs=n*Ts
f=reshape(sinc(nTs/pi),1,201);
Dt=0.005
t=-15:Dt:15;
t_reshape=reshape(collect(t),1,6001)
t_Matrix=ones(length(nTs),1) .* t_reshape
nTs_reshape=reshape(collect(nTs),1,201)
nTs_Matrix=nTs_reshape'*ones(1,length(t))
fa=f * Ts * wc / pi * sinc((wc/pi) *(t_Matrix-nTs_Matrix));
error=abs.(fa.-sinc(t_reshape/pi));   #重构信号与原信号误差
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_reshape,fa)
xlabel("t");
ylabel("fa(t)");
title("由sa(t)=sinc(t/pi)的过采样信号重构sa(t)");
grid("on");
subplot(313);
plot(t_reshape,error);
xlabel("t");
ylabel("error(t)");
title("过采样信号与原信号的误差error(t)");

全部回答 1

发布于 2024-12-24 14:19:59

您好,这里主要在f以及fa的计算,f按照您代码中的定义得到的结果是向量,按照书中的定义f应该是矩阵,那么向量使用点乘矩阵的结果和矩阵乘以矩阵的结果是不一致的。一下代码可供参考。

wm=1;
wc=1.1*wm; 
Ts=0.7*pi/wm;
ws=2*pi/Ts;
n=-100:100;
nTs=n*Ts
f=reshape(sinc(nTs/pi),1,201);
Dt=0.005
t=-15:Dt:15;
t_reshape=reshape(collect(t),1,6001)
t_Matrix=ones(length(nTs),1) .* t_reshape
nTs_reshape=reshape(collect(nTs),1,201)
nTs_Matrix=nTs_reshape'*ones(1,length(t))
fa=f * Ts * wc / pi * sinc((wc/pi) *(t_Matrix-nTs_Matrix));
error=abs.(fa.-sinc(t_reshape/pi));   #重构信号与原信号误差
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_reshape,fa)
xlabel("t");
ylabel("fa(t)");
title("由sa(t)=sinc(t/pi)的过采样信号重构sa(t)");
grid("on");
subplot(313);
plot(t_reshape,error);
xlabel("t");
ylabel("error(t)");
title("过采样信号与原信号的误差error(t)");
用户
和原帖交流更多问题细节吧,去
我要发帖 我要发帖
资料中心 资料中心
查看更多>
热门帖子 热门帖子
主要贡献者 主要贡献者
过去7天