matlab画出𝑥(𝑛) = (0.6)^𝑛𝑢(𝑛)和h(𝑛) = (−0.9)^𝑛𝑢(𝑛)的卷积图像
时间: 2023-10-27 11:08:15 浏览: 34
下面是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)
matlab计算𝑥(𝑛) = (0.6)^𝑛𝑢(𝑛)和h(𝑛) = (−0.9)^𝑛𝑢(𝑛)的卷积
可以使用conv函数计算两个序列的卷积。
首先,定义序列x和h:
```
n = 0:10;
x = (0.6).^n .* (n>=0);
h = (-0.9).^n .* (n>=0);
```
其中,`.*`表示元素相乘,`(n>=0)`表示取值范围为n>=0时为1,否则为0。
然后,使用conv函数计算卷积:
```
y = conv(x,h);
```
最后,绘制结果:
```
stem(y);
xlabel('n');
ylabel('y(n)');
title('Convolution of x(n) and h(n)');
```
结果如下图所示:
![卷积结果](https://i.loli.net/2021/08/23/ujJXA7ZS8bpkNcK.png)