matlab将𝑥(𝑛) = (0.6)^𝑛𝑢(𝑛)和h(𝑛) = (−0.9)^𝑛𝑢(𝑛)图像用不同的颜色画在一张图里
时间: 2023-12-07 09:03:14 浏览: 39
可以使用以下代码实现:
n = 0:20; % 定义序列的范围
x = (0.6).^n.*(n>=0); % 定义 x(n)
h = (-0.9).^n.*(n>=0); % 定义 h(n)
figure; % 新建一个图形窗口
hold on; % 启用“保持”模式
stem(n,x,'r','filled'); % 画 x(n) 的图像,使用红色
stem(n,h,'b','filled'); % 画 h(n) 的图像,使用蓝色
legend('x(n)','h(n)'); % 添加图例
xlabel('n'); % 添加 x 轴标签
ylabel('Amplitude'); % 添加 y 轴标签
title('x(n) and h(n)'); % 添加标题
运行后,将会得到以下图像:
![image.png](attachment:image.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)
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)
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)