Answer to Question #223717 in Electrical Engineering for Jhony beristow

Question #223717
Design a PI-Controller using MATLAB assuming a second-order approximation as follows:
Allow the user to input from the keyboard the desired percent overshoot
Design a PI controller and gain to yield zero steady-state error for a closed-loop step response as well as meet the percent overshoot specification
Display the compensated closed-loop step response
Test your program on and 25% overshoot
1
Expert's answer
2021-08-12T07:27:17-0400
CODE:
clc
close all
clear all
K=input('Type K to meet steady-state error ');
numg=K*[1 7];
deng=poly([0 -5 -15]);
G=tf(numg,deng);
'G(s)'
Gzpk=zpk(G)
%Input transient response specifications
Po=input('Type %OS ');
Ts=input('Type settling time ');
%Tp=input('Type peak time ');
T=feedback(G,1);
step(T)
title('Gain Compensated')
pause
%Determine required bandwidth
z=(-log(Po/100))/(sqrt(pi^2+log(Po/100)^2));
wn=4/(z*Ts);
%wn=pi/(Tp*sqrt(1-z^2));
wBW=wn*sqrt((1-2*z^2)+sqrt(4*z^4-4*z^2+2));
%wBW=(4/(Ts*z))*sqrt((1-2*z^2)+sqrt(4*z^4-4*z^2+2));
%wBW=(pi/(Tp*sqrt(1-z^2)))*sqrt((1-2*z^2)+sqrt(4*z^4-4*z^2+2));
%Determine required phase margin
Pmreq=atan(2*z/(sqrt(-2*z^2+sqrt(1+4*z^4))))*(180/pi)+5;
%Choose new phase margin frequency
wpm=0.8*wBW;
%Determine additional phase lead required at the
%new phase margin frequency from the lead compensator
[M,P]=bode(G,wpm);
Pmreqc=Pmreq-(180+P);
beta=(1-sin(Pmreqc*pi/180))/(1+sin(Pmreqc*pi/180));
%Display data
fprintf('\nPercent Overshoot = %g',Po)
fprintf(', Settling Time = %g',Ts)
%fprintf(', Peak Time = %g',Tp)
fprintf(', Damping Ratio = %g',z)
fprintf(', Required Phase Margin = %g',Pmreq)
fprintf(', Required Bandwidth = %g',wBW)
fprintf(', New Phase Margin Frequency = %g',wpm)
fprintf(', Required Phase from Lead Compensator = %g',Pmreqc)
fprintf(', Beta = %g',beta)
bode(numg,deng)
title('Gain compensated')
pause
%Design lag compensator
zclag=wpm/10;
pclag=zclag*beta;
Kclag=beta;
'Lag compensator'
'Gclag'
Gclag=tf(Kclag*[1 zclag],[1 pclag]);
Gclagzpk=zpk(Gclag)
%Design lead compensator
zclead=wpm*sqrt(beta);
pclead=zclead/beta;
Kclead=1/beta;
'Lead compensator'
'Gclead'
Gclead=tf(Kclead*[1 zclead],[1 pclead]);
Gcleadzpk=zpk(Gclead)
%Create compensated forward path
'Gclag(s)Gclead(s)G(s)'
Ge=G*Gclag*Gclead;
Gezpk=zpk(Ge)
%Test lag-lead compensator
T=feedback(Ge,1);
bode(Ge)
title('Lag-lead Compensated')
[M,P,w]=bode(Ge);
[Gm,Pm,wcp,wcg]=margin(M,P,w);
'Compensated System Results'
fprintf('\nResulting Phase Margin = %g',Pm)
fprintf(', Resulting Phase Margin Frequency = %g',wcg)
pause
step(T)
title('Lag-lead Compensated')
Results 



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS