Example of Incremental PID Control Output Simulation for Discrete Systems Using MATLAB

First, fill in the transfer function of the continuous system, determine the sampling time interval, then convert it into the transfer function of the discrete system, and finally determine the incremental PID correction coefficients. Input a sine signal and observe the system’s output signal.
%% Example of Incremental PID Control for Discrete Systems
%%%%%%%%%%%
clear all;close all;clc;
%%%%%%%%%%%%%
sampleTime1=0.01 ; %% Sampling time
sys1=tf(500,[1, 60, 0]); %% Continuous system
sysD=c2d(sys1, sampleTime1, ‘z’) ;
[num1,den1]=tfdata(sysD, ‘v’);
disp(‘Discrete system transfer function:’);
printsys(num1,den1);
inX1=0; %% Input delay variable
inX2=0;
inX3=0;
outY1=0; %% Output delay variable
outY2=0;
outY3=0;
x1=[0; 0; 0];
err1=0; %% Output error
err2=0; %% Output error
Len=2000;
time1=zeros(1,Len);
inX=zeros(1,Len);
outY=zeros(1,Len);
u1=zeros(1,Len);
errOut=zeros(1,Len);
Kp=9; %% PID coefficient
Ki=0.15; %% PID coefficient
Kd=12.0; %% PID coefficient
w1=0.5; %% Sine frequency
%%%%%%%%%%%%%
for k1=1:1:Len
time1(k1)=k1*sampleTime1 ;
inX(k1)=2.5*cos(2*pi*w1*k1*sampleTime1) ; %% Input signal
u1(k1)=Kp*x1(1)+Ki*x1(2)+Kd*x1(3) ; %% PID correction
u2(k1)=inX1+u1(k1) ; %% PID correction
if u2(k1) >= 15
u2(k1) = 15 ;
end
if u2(k1) <= -15
u2(k1) = -15 ;
end
outY(k1)=-den1(2)*outY1-den1(3)*outY2+…
%%-den1(4)*outY3
num1(2)*inX1+num1(3)*inX2; %%+num1(4)*inX3
errOut(k1)=inX(k1)-outY(k1) ;
%%%%%%%%%%
inX3=inX2; %% Save input delay variable
inX2=inX1;
inX1=u2(k1); %% PID correction
outY3=outY2 ; %% Save output delay variable
outY2=outY1 ;
outY1=outY(k1) ;
x1(1)=errOut(k1)-err1 ; %% PID correction
x1(2)=errOut(k1) ;
x1(3)=errOut(k1)-2*err1+err2 ;
err2=err1 ;
err1=errOut(k1);
end
figure(1);plot(time1,inX,’b’,time1,outY,’r’);title(‘Input and Output Curves.’);xlabel(‘t(s)’);ylabel(‘y’);legend(‘Input x’, ‘Output y’);
figure(2);plot(time1, outY-inX, ‘b’);title(‘Output and Input Difference.’);xlabel(‘t(s)’);ylabel(‘y-x’);legend(‘y-x’);
disp(‘End.’);

Leave a Comment