matlab用stem画出𝑥(𝑛) = (0.6)^𝑛𝑢(𝑛)卷积h(𝑛) = (−0.9)^𝑛𝑢(𝑛)的图像,将n在[0,70]和[1,35]的卷积图像用不同的颜色画在同一张图像里
时间: 2024-06-04 22:13:58 浏览: 13
n = 0:70;
x = (0.6).^n.*(n>=0);
h = (-0.9).^n.*(n>=0);
y = conv(x,h);
figure;
stem(n,y(1:length(n)),'r'); % 绘制n在[0,70]的卷积图像,红色
hold on;
stem(n,y(2:length(n)+1),'b'); % 绘制n在[1,35]的卷积图像,蓝色
xlabel('n');
ylabel('y(n)');
title('Convolution of x(n) and h(n)');
legend('n=[0,70]','n=[1,35]');
相关问题
matlab画出𝑥(𝑛) = (0.6)^𝑛𝑢(𝑛)卷积h(𝑛) = (−0.9)^𝑛𝑢(𝑛)的图像
代码如下:
```matlab
n = -10:50; % 定义时间序列
x = (0.6).^n.*(n>=0); % 定义信号x(n)
h = (-0.9).^n.*(n>=0); % 定义信号h(n)
y = conv(x,h); % 卷积
ny = n(1)+n(1):n(end)+n(end); % 计算卷积后的时间序列
subplot(3,1,1); stem(n,x); xlabel('n'); ylabel('x(n)'); title('信号x(n)');
subplot(3,1,2); stem(n,h); xlabel('n'); ylabel('h(n)'); title('信号h(n)');
subplot(3,1,3); stem(ny,y); xlabel('n'); ylabel('y(n)'); title('卷积信号y(n)');
```
运行结果如下图所示:
![卷积图像](https://img-blog.csdnimg.cn/20210720165119185.png)
matlab画出𝑥(𝑛) = (0.6)^𝑛𝑢(𝑛)和h(𝑛) = (−0.9)^𝑛𝑢(𝑛)的卷积图像
下面是MATLAB代码和卷积图像:
```matlab
% 定义两个序列
n = 0:20;
x = (0.6).^n.*(n>=0);
h = (-0.9).^n.*(n>=0);
% 计算卷积
y = conv(x, h);
% 画出卷积图像
figure;
subplot(3,1,1);
stem(n,x);
title('x(n)');
xlabel('n');
ylabel('Amplitude');
subplot(3,1,2);
stem(n,h);
title('h(n)');
xlabel('n');
ylabel('Amplitude');
n_y = 0:length(y)-1;
subplot(3,1,3);
stem(n_y, y);
title('Convolution of x(n) and h(n)');
xlabel('n');
ylabel('Amplitude');
```
卷积图像如下所示:
![convolution](https://i.loli.net/2021/11/01/7VW4K8X9Jf6MxOv.png)