h(t)=u(t)-u(t-1)
x(t)=u(t)-u(t-1)
t = -2:0.01:3; % 定义时间范围
x = heaviside(t) - heaviside(t-1); % x(t) heaviside是门函数
h = heaviside(t) - heaviside(t-1); % h(t)
convolution = conv(x, h,'same'); % 计算卷积
% 绘制结果
subplot(3,1,1);
plot(t, x);
title('x(t)');
xlabel('t');
ylabel('x(t)');
subplot(3,1,2);
plot(t, h);
title('h(t)');
xlabel('t');
ylabel('h(t)');
subplot(3,1,3);
plot(t, convolution);
title('x(t)*h(t)');
xlabel('t');
ylabel('x(t)*h(t)');