Designing Lead-Lag Compensation with MATLAB

Set the system speed error coefficient to 10, with a gain margin greater than 10 dB and a phase margin greater than 50 degrees.

% Lead-lag compensation numerator
num1=10*1;
% Expected speed error coefficient
den1=conv(conv([1,0],[0.4,1]),[1.2,1]);
% Denominator polynomial
[Gn1,Ph1,Wg1,Wp1]=margin(num1,den1);
% Frequency variable
w1=logspace(-2,2,1000);
% Frequency response
[mag1,pha1]=bode(num1,den1,w1);
k1=find(abs(w1-Wg1)==min(abs(w1-Wg1)));
Wc=Wg1;
w_c2=Wc/12;
beta=15;
num_c2=[1/w_c2,1];
den_c2=[beta/w_c2,1];
w_c1=w_c2;
mag_k=mag1;
mag_k(k1)=2;
i1=1;
while(mag_k(k1)>1)
num_c1=[1/w_c1,1];
den_c1=[1/(w_c1*beta),1];
w_c1=w_c1+0.01;
[num_c,den_c]=series(num_c1,den_c1,num_c2,den_c2);
[num2,den2]=series(num1,den1,num_c,den_c);
[mag_k,pha_k]=bode(num2,den2,w1);
i1=i1+1;
if(i1>9000)
break;
end
end
[Gn2,Ph2,Wg2,Wp2]=margin(num2,den2);
% Frequency response
[mag2,pha2]=bode(num2,den2,w1);
[mag_c,pha_c]=bode(num_c,den_c,w1);
subplot(2,1,1);semilogx(w1,20*log10(mag1),’b’,w1,20*log10(mag2),’r’,w1,20*log10(mag_c),’g’);
grid;
ylabel(‘Magnitude (dB)’);
title(‘Blue line – Before compensation, Red line – After compensation, Green line – Compensation device’);
subplot(2,1,2);semilogx(w1,pha1,’b’,w1,pha2,’r’,w1,pha_c,’g’);
grid;
ylabel(‘Phase (°)’);
xlabel(‘Frequency (rad/s)’);
disp([‘Before compensation: Gain margin=’,num2str(20*log10(Gn1)),’dB’,’,’,’ Phase margin=’,num2str(Ph1),’°’]);
disp([‘After compensation: Gain margin=’,num2str(20*log10(Gn2)),’dB’,’,’,’ Phase margin=’,num2str(Ph2),’°’]);

Leave a Comment