0% found this document useful (0 votes)
20 views

Lab Program

This document contains MATLAB code to simulate and analyze the step response of different types of systems including 1st order systems with and without delay, 2nd order systems with and without delay. It also contains code for Bode plot analysis, phase and gain margin calculation. Finally it contains code to tune PID controllers and compare the step response of P, PI and PID controllers.

Uploaded by

mohan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Lab Program

This document contains MATLAB code to simulate and analyze the step response of different types of systems including 1st order systems with and without delay, 2nd order systems with and without delay. It also contains code for Bode plot analysis, phase and gain margin calculation. Finally it contains code to tune PID controllers and compare the step response of P, PI and PID controllers.

Uploaded by

mohan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

% PROGRAM : Step response of 1st order system without delay

n=[0 10];
d=[1 1];
a= tf(n,d);
y=step(a);
plot(y)
xlabel('Time')
ylabel('Amplitude')
title('Step response of 1st order system without delay')

%Step response of 1st order system with delay


n=10;
d=[1 1];
a=tf(n,d);
a.inputdelay=0.8;
step(a);
xlabel('Time');
ylabel('Amplitude');
title('Step response of 1st order system with delay')
%Step response of 2nd order system without delay
n1=[0 2 3];
d1=[3 2 1];
[n2, d2]=pade(0.2,1);
n3=conv(n1,n2);
d3=conv(d1,d2);
a=tf(n3,d3);
b=step(a);
xlabel('Time');
ylabel('Amplitude');
title('Step response of 2nd order system without delay');

%Step response of 2nd order system with delay


n1=[0 2 3];
d1=[3 2 1];
[n2,d2]=pade(0.2,1);
n3=conv(n1,n2);
d3=conv(d1,d2);
a=tf(n3,d3);
a.inputdelay=0.8;
step(a);
xlabel('Time');
ylabel('Amplitude');
title('Step response of 2nd order system with delay');
%bode plot to find phase margin and gain margin
num=[5 1 2];
den=[7 9 3 4];
g=tf(num,den)
bode(g)
margin(g)

Tuning of PID controller

%t=0:0.5:50;
t=0:0.01:500;
n1=[0 2];
d1=[10 1];
Kp = 2.25;
[nc,dc]= cloop (Kp*n1,d1);
y=step(nc,dc,t);
%subplot(2,2,1);
%plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('P-Controller');
Kp1 = 2.25;
Kil = 2.025;
n2=[Kp1 Kil];
d2=[1 0];
[nc1,dc1] = cloop(conv(n1,n2),conv(d1,d2));
y1=step(nc1,dc1,t);
%subplot(2,2,2); %plot(t,y1);
xlabel('Time');
ylabel('Amplitude');
title('PI-Controller');
Kp2 = 2.25;
Ki2 = 2.825;
Kd2 = 2.655;
n3=[Kd2 Kp2 Ki2];
d3=[0 1 0];
[nc2,dc2] = cloop(conv(n1,n3),conv(d1,d3));
y2=step(nc2,dc2,t);
%subplot(2,2,3);
%plot(t,y2);
xlabel('Time');
ylabel('Amplitude');
title('PID-Controller');
%subplot(2,2,4);
plot(t,y,'r',t,y1,'b',t,y2,'g');
xlabel('Time');
ylabel('Amplitude');
title('P,PI,PID RESPONSE');

You might also like