系统辨识与Simulink仿真及PID Tuner

%首先设计一个传递函数
num = [ 0.998 ];
den = [ 0.021,1 ];
sys = tf(num, den);
ts = 0.005; %采样时间
dsys = c2d(sys, ts, 'z'); %离散化
[num, den] = tfdata(dsys, 'v'); %v代表强制以向量的格式输出num和den

e_1 = 0;    %前一时刻的误差
Ee = 0;     %累积误差
u_1 = 0.0;  %前一时刻的控制量
y_1 = 0;    %前一时刻的输出
%PID参数
% Kp = 0.22;
% Ki = 0.13;
%Kd = 0.00099;
u = zeros(1,1000);
time = zeros(1,1000);
for k = 1 : 1000
    time(k) = k * ts;   %时间参数
    r(k) = 1500;        %目标值
    y(k) = -1 * den(2) * y_1 + num(1) * u(k) + num(2) * u_1;
    e(k) = r(k) - y(k);
    Ee = Ee + e(k);
    u(k) = 1500;%Kp * e(k) + Ki * Ee + Kd * (e(k) - e_1);
    y_1 = y(k);
    u_1 = u(k);
    e_1 = e(k);  
end

plot(time, r, '-.');
hold on;
plot(time, y, '--');
grid on;

因为传递函数是一阶的,且den(1)为1,所以

你可能感兴趣的:(matlab,系统辨识,pid,tunner,simulink)