Example of Discrete Delay System Integral Separation PID Correction Simulated with 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 then determine the integral separation PID correction coefficients. Finally, input a sine signal and observe the system’s output signal.

%% Integral Separation PID Correction Algorithm

%%%%%%%%%%%

clear all;

close all;

clc;

%%%%%%%%%%%%%

sampleTime1=0.01 ; %% Sampling time

sys1=tf(200,[50, 1], ‘inputdelay’,0.04); %% Continuous system

sysD=c2d(sys1, sampleTime1, ‘zoh’) ;

[num1,den1]=tfdata(sysD, ‘v’);

disp(‘Discrete system transfer function:’);

printsys(num1,den1);

inX1=0; %% Input delay variable

inX2=0;

inX3=0;

inX4=0;

outY1=0; %% Output delay variable

outY2=0;

outY3=0;

err0=0; %% Output error

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=5.0; %% PID coefficient

Ki=0.1; %% PID coefficient

Kd=0.015; %% PID coefficient

w1=0.5; %% Sine frequency

coef1=1.0 ;

%%%%%%%%%%%%%

for k1=1:1:Len

time1(k1)=k1*sampleTime1 ;

inX(k1)=5.0*cos(2*pi*w1*k1*sampleTime1) ; %% 1.0;%%30.0; %%

outY(k1)=-den1(2)*outY1+num1(2)*inX4 ;

errOut(k1)=inX(k1)-outY(k1) ;

err0=err0+errOut(k1)*sampleTime1 ;

if 20 < abs( errOut(k1) ) && abs( errOut(k1) ) <= 30

coef1=0.9 ;

elseif 10 < abs( errOut(k1) ) && abs( errOut(k1) ) <= 20

coef1=0.6 ;

elseif 5 < abs( errOut(k1) ) && abs( errOut(k1) ) <= 10

coef1=0.4 ;

else

coef1=0.2 ;

end

%%%%%%%%%%%%%

u1(k1)=Kp*errOut(k1)+coef1*Ki*err0+Kd*(errOut(k1)-err1)/sampleTime1 ; %% PID correction

if u1(k1) >= 100

u1(k1) = 100 ;

end

if u1(k1) <= -100

u1(k1) = -100 ;

end

%%%%%%%%%%

inX4=inX3; %% Save input delay variable

inX3=inX2; %% Save input delay variable

inX2=inX1;

inX1=u1(k1); %% PID correction

outY3=outY2 ; %% Save output delay variable

outY2=outY1 ;

outY1=outY(k1) ;

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 Deviation.’);

xlabel(‘t(s)’);

ylabel(‘y-x’);

legend(‘y-x’);

disp(‘End.’);

Leave a Comment