实现了一个简单的PD控制器,其中Kp和Kd是控制器的参数,T是系统的参数。然后,定义了系统的传递函数,输入信号,并计算系统的响应。最后,使用plot函数画出了系统的响应图像。
clear;
close all;
% Define the parameters for the system
Kp = 1;
Kd = 1;
T = 10;
% Define the transfer function for the system
num = [Kd, Kp];
den = [T, 1];
G = tf(num, den);
% Define the input signal
t = 0:0.01:20;
u = sin(t);
% Compute the response of the system to the input signal
[y, t] = lsim(G, u, t);
% Plot the response of the system
figure;
plot(t, u, 'r', 'LineWidth', 2);
hold on;
plot(t, y, 'b', 'LineWidth', 2);
xlabel('Time (s)');
ylabel('Amplitude');
legend('Input Signal', 'System Response');
title('PD Controller');