Compensator Design

In [1]:
%plot inline -f "svg"
In [2]:
pkg load control

the input data:

  1. plant transfer function
  2. $f_C$
  3. $\varphi_m$
In [3]:
T0 = tf([1e4, 1e9], [1, 2e3, 1e8])
fc = 10e3
finalpm = 90
Transfer function 'T0' from input 'u1' to output ...

        1e+04 s + 1e+09   
 y1:  --------------------
      s^2 + 2000 s + 1e+08

Continuous-time model.
fc =  10000
finalpm =  90

set the crossover frequency, $f_C$, this is our second input

In [4]:
wc = 2 * pi * fc;

set the required value of $k$

In [5]:
k = 1 / abs(T0(wc))
k =  3.2598
In [6]:
T1 = k * T0
Transfer function 'T1' from input 'u1' to output ...

      3.26e+04 s + 3.26e+09
 y1:  ---------------------
      s^2 + 2000 s + 1e+08 

Continuous-time model.

determine the phase margin, pm

In [7]:
Twc = T1(wc);
aTwc = abs(Twc)
pm = 180 + 180 / pi * angle(Twc)
aTwc =  1
pm =  34.012

lead compensator, the third input variable, desired phase margin, finalpm

In [8]:
philead = finalpm + 6 - pm;
pl = pi / 180 * philead;
t = tan(pl);
p = t + sqrt(1 + t^2);
Hlead = 1 / p * tf([p / wc, 1], [1 / (p * wc), 1])
Transfer function 'Hlead' from input 'u1' to output ...

      1.592e-05 s + 0.2494
 y1:  --------------------
         3.97e-06 s + 1   

Continuous-time model.

connect the lead compensator, we get $T_2$

In [9]:
T2 = series(Hlead, T1)
Transfer function 'T2' from input 'u1' to output ...

        0.5188 s^2 + 6.001e+04 s + 8.131e+08   
 y1:  -----------------------------------------
      3.97e-06 s^3 + 1.008 s^2 + 2397 s + 1e+08

Continuous-time model.

lag compensator

In [10]:
wl = wc / 10;
Hlag = parallel(1, tf([wl], [1 0]))
Transfer function 'Hlag' from input 'u1' to output ...

      s + 6283
 y1:  --------
         s    

Continuous-time model.

connect the lag compensator

In [11]:
T3 = series(Hlag, T2)
Transfer function 'T3' from input 'u1' to output ...

      0.5188 s^3 + 6.327e+04 s^2 + 1.19e+09 s + 5.109e+12
 y1:  ---------------------------------------------------
         3.97e-06 s^4 + 1.008 s^3 + 2397 s^2 + 1e+08 s   

Continuous-time model.

open loop transfer function Bode plot:

In [12]:
bode(T3)
Gnuplot Produced by GNUPLOT 5.2 patchlevel 8 -40 -20 0 20 40 102 103 104 105 106 107 Magnitude [dB] Bode Diagram gnuplot_plot_1a -140 -120 -100 -80 -60 -40 102 103 104 105 106 107 Phase [deg] Frequency [rad/s] T3 T3

closed loop transfer function:

In [13]:
H3 = feedback(T3)
Transfer function 'H3' from input 'u1' to output ...

             0.5188 s^3 + 6.327e+04 s^2 + 1.19e+09 s + 5.109e+12       
 y1:  -----------------------------------------------------------------
      3.97e-06 s^4 + 1.527 s^3 + 6.567e+04 s^2 + 1.29e+09 s + 5.109e+12

Continuous-time model.

closed loop poles:

In [14]:
pzmap(H3)
legend('location', 'northwest')
Gnuplot Produced by GNUPLOT 5.2 patchlevel 8 -20000 -10000 0 10000 20000 -350000 -300000 -250000 -200000 -150000 -100000 -50000 0 Imaginary Axis Real Axis Pole-Zero Map H3 H3 gnuplot_plot_2a

closed loop step response

In [15]:
step(H3)
Gnuplot Produced by GNUPLOT 5.2 patchlevel 8 0 0.2 0.4 0.6 0.8 1 0 0.0002 0.0004 0.0006 0.0008 0.001 y1 Time [s] Step Response H3 H3

closed loop Bode plot:

In [16]:
bode(H3)
Gnuplot Produced by GNUPLOT 5.2 patchlevel 8 -30 -20 -10 0 102 103 104 105 106 107 Magnitude [dB] Bode Diagram gnuplot_plot_1a -80 -60 -40 -20 0 102 103 104 105 106 107 Phase [deg] Frequency [rad/s] H3 H3

compressed open loop Nyquist plot:

In [17]:
dodato_nestabilnih_polova = pypass(T3);
Gnuplot Produced by GNUPLOT 5.2 patchlevel 8 -2 -1 0 1 2 -2 -1 0 1 2 added 0 unstable poles gnuplot_plot_1a gnuplot_plot_2a gnuplot_plot_3a gnuplot_plot_4a gnuplot_plot_5a