matlab实现离散系统卷积计算
时间: 2023-11-07 18:49:08 浏览: 70
假设有两个离散时间信号 $x[n]$ 和 $h[n]$,它们的卷积 $y[n] = x[n] * h[n]$ 可以用 MATLAB 中的 conv 函数实现。具体步骤如下:
1. 定义输入信号 $x[n]$ 和 $h[n]$。例如:
```matlab
x = [1 2 3 4 5];
h = [0.5 0.4 0.3];
```
2. 使用 conv 函数进行卷积计算,得到输出信号 $y[n]$。例如:
```matlab
y = conv(x, h);
```
3. 可以通过 subplot 函数将输入和输出信号绘制在同一张图上,观察卷积的结果。例如:
```matlab
subplot(3,1,1);
stem(x);
title('Input signal x[n]');
subplot(3,1,2);
stem(h);
title('Impulse response h[n]');
subplot(3,1,3);
stem(y);
title('Output signal y[n] = x[n] * h[n]');
```
完整的代码演示如下:
```matlab
% Define input signals
x = [1 2 3 4 5];
h = [0.5 0.4 0.3];
% Convolve the signals
y = conv(x, h);
% Plot the input and output signals
subplot(3,1,1);
stem(x);
title('Input signal x[n]');
subplot(3,1,2);
stem(h);
title('Impulse response h[n]');
subplot(3,1,3);
stem(y);
title('Output signal y[n] = x[n] * h[n]');
```
运行结果如下图所示:
![Convolution in MATLAB](https://i.imgur.com/X9DdbtU.png)