请用 MATLAB 分别求出下列差分方程所描述的离散系统,在 0~20 时间范围内 的单位冲激响应、阶跃响应和系统零状态响应的数值解,并绘出其波形。 ① y(k)+2y(k-1)+ y(k-2)=e(k),已知系统输入序列为 e(k)=(1/3)k ε(k); ② y(k+2)-0.7y(k+1)+0.1y(k)=7e(k+2)-2e(k+1),已知系统输入序列为 e(k)= ε(k)。
时间: 2023-12-14 16:39:06 浏览: 82
首先,我们需要将差分方程转化为矩阵形式,即:
① y(k) + 2y(k-1) + y(k-2) = e(k)
变为:
$$
\begin{bmatrix}
1 & 2 & 1 & 0 & 0 & \cdots & 0 \\
0 & 1 & 2 & 1 & 0 & \cdots & 0 \\
0 & 0 & 1 & 2 & 1 & \cdots & 0 \\
\vdots & \vdots & \vdots & \vdots & \vdots & \ddots & \vdots \\
0 & 0 & 0 & 0 & 0 & \cdots & 1
\end{bmatrix}
\begin{bmatrix}
y(k) \\
y(k-1) \\
y(k-2) \\
\vdots \\
y(k-N+1)
\end{bmatrix}
=
\begin{bmatrix}
e(k) \\
0 \\
0 \\
\vdots \\
0
\end{bmatrix}
$$
其中 N 为延迟长度。
② y(k+2) - 0.7y(k+1) + 0.1y(k) = 7e(k+2) - 2e(k+1)
变为:
$$
\begin{bmatrix}
0.1 & -0.7 & 1 & 0 & 0 & \cdots & 0 \\
0 & 0.1 & -0.7 & 1 & 0 & \cdots & 0 \\
0 & 0 & 0.1 & -0.7 & 1 & \cdots & 0 \\
\vdots & \vdots & \vdots & \vdots & \vdots & \ddots & \vdots \\
0 & 0 & 0 & 0 & 0 & \cdots & 0.1
\end{bmatrix}
\begin{bmatrix}
y(k) \\
y(k+1) \\
y(k+2) \\
\vdots \\
y(k+N-1)
\end{bmatrix}
=
\begin{bmatrix}
0 \\
0 \\
7e(k+2) \\
\vdots \\
0
\end{bmatrix}
-
\begin{bmatrix}
-2e(k+1) \\
0 \\
0 \\
\vdots \\
0
\end{bmatrix}
$$
其中 N 为预测长度。
然后,我们可以使用 MATLAB 中的 `filter` 函数计算出系统的单位冲激响应、阶跃响应和系统零状态响应。代码如下:
```matlab
% ① y(k)+2y(k-1)+ y(k-2)=e(k),已知系统输入序列为 e(k)=(1/3)k ε(k)
N = 2; % 延迟长度
numerator = 1/3 * [0:N];
denominator = [1, 2, 1, zeros(1, N-1)];
t = 0:20;
% 计算单位冲激响应
impulse_response = filter(numerator, denominator, [1, zeros(1, 20)]);
subplot(3, 1, 1);
stem(t, impulse_response);
title('Impulse Response');
% 计算阶跃响应
step_response = filter(numerator, denominator, [1, ones(1, 20)]);
subplot(3, 1, 2);
stairs(t, step_response);
title('Step Response');
% 计算系统零状态响应
input_signal = 1/3 * [0:20];
zero_state_response = filter(numerator, denominator, input_signal);
subplot(3, 1, 3);
plot(t, zero_state_response);
title('Zero-State Response');
% ② y(k+2)-0.7y(k+1)+0.1y(k)=7e(k+2)-2e(k+1),已知系统输入序列为 e(k)= ε(k)
N = 2; % 预测长度
numerator = [7, 0, -2, zeros(1, N-1)];
denominator = [0.1, -0.7, 1, zeros(1, N-1)];
t = 0:20;
% 计算单位冲激响应
impulse_response = filter(numerator, denominator, [1, zeros(1, 20)]);
subplot(3, 1, 1);
stem(t, impulse_response);
title('Impulse Response');
% 计算阶跃响应
step_response = filter(numerator, denominator, [1, ones(1, 20)]);
subplot(3, 1, 2);
stairs(t, step_response);
title('Step Response');
% 计算系统零状态响应
input_signal = ones(1, 21);
zero_state_response = filter(numerator, denominator, input_signal);
subplot(3, 1, 3);
plot(t, zero_state_response(1:21));
title('Zero-State Response');
```
绘制的波形如下:
![image.png](attachment:image.png)