??? Undefined function or variable "t3".
时间: 2023-06-30 12:19:43 浏览: 47
这个错误提示是因为在 `xt_t` 的长度截取之前,`t3` 这个向量还没有被定义。你需要将 `t3` 的定义放到 `xt_t` 之前。修改后的代码如下:
```matlab
clear all;
close all;
dt = 0.01;
t = 0:dt:10;
xt = 0.1*sin(2*pi*t) + 0.5*cos(4*pi*t);
[f, xf] = FFT_SHIFT(t,xt); %号抽样信号,抽样速率为4Hz
fs = 4;
sdt = 1/fs;
t1 = 0:sdt:10;
st = 0.1*sin(2*pi*t1) + 0.5*cos(4*pi*t1);
[f1, sf] = FFT_SHIFT(t1,st); %8恢复原始信号
t2 = -50:dt:50;
gt = sinc(fs*t2);
stt = resample(st,1,sdt/dt);
t3 = -50:dt:60+sdt-dt; % 将 t3 的定义提前
xt_t = conv(stt,gt);
xt_t = xt_t(1:length(t3)); % 截取和 t3 长度相同的部分
figure(1)
subplot(3,1,1);
plot(t,xt);
title('原始信号');
subplot(3,1,2);
stem(t1,st);
title('抽样信号');
subplot(3,1,3);
plot(t3,xt_t);
title('抽样信号恢复');
axis([0 10 -1 1])
```
这个修改后的代码中将 `t3` 的定义放到了 `xt_t` 之前,避免了上述错误提示。