matlab画出𝑥(𝑛) = (0.6)^𝑛𝑢(𝑛)卷积h(𝑛) = (−0.9)^𝑛𝑢(𝑛)的序列图像,𝑛 ∈ [0, 70]和𝑛 ∈ [1, 35],用不同的颜色画在同一张图像里
时间: 2024-06-01 11:12:07 浏览: 10
以下是MATLAB代码:
```
n1 = 0:70; % 定义n1序列
n2 = 1:35; % 定义n2序列
x = (0.6).^n1.*(n1>=0); % 计算x(n)
h = (-0.9).^n1.*(n1>=0); % 计算h(n)
y = conv(x,h); % 计算卷积y(n)
n = 0:length(y)-1; % 定义n序列
figure; % 新建图像
plot(n,x,'b',n,h,'r',n,y,'g'); % 画出x(n),h(n)和y(n)的图像
hold on; % 保持画布
plot(n1,x,'b',n1,h,'r'); % 画出n1范围内x(n)和h(n)的图像
plot(n2,x(1:35),'b',n2,h(1:35),'r'); % 画出n2范围内x(n)和h(n)的图像
legend('x(n)','h(n)','y(n)'); % 添加图例
xlabel('n'); % 添加x轴标签
ylabel('Amplitude'); % 添加y轴标签
title('Convolution of x(n) and h(n)'); % 添加标题
```
运行代码后,应该会得到以下图像:
![convolution plot](https://i.imgur.com/vmPf8rW.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)
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)
相关推荐
![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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)