You are on page 1of 5

Useful MATLAB Commands

Please check the Matlab help for further information about these commands

Defining Transfer Functions

G = tf(NUM,DEN);
This defines a transfer function with the numerator ‘Num’ and denominator ‘Den’ coefficients
entered in vector form, and saves it to the workspace as transfer function ‘G’.

For example, to define the transfer function


−(𝑠 − 1)
𝐺(𝑠) =
2𝑠 2 + 3𝑠 + 1
the command would be:
G=tf([-1 1],[2 3 1]);

G = zpk(p,z,k);
Transfer functions can also be defined in terms of zeros, poles and gain. For the example, find first
the roots of the denominator using the roots command
roots([2 3 1])
The roots command finds two roots s1 = -1 and s2=-0.5. The example can be re-written as
−(𝑠 − 1)
𝐺(𝑠) =
(𝑠 + 1)(𝑠 + 0.5)
The zpk command would be:
G = zpk([1],[-1 -0.5],-1)

[A,B,C,D] = tf2ss(NUM,DEN);
This command transforms a transfer function into an equivalent state-space representation. The
command for the above example would be:
[A,B,C,D] = tf2ss([-1 1],[2 3 1])
With
−1.5 −0.5 1
𝐴=[ ] ; 𝐵 = [ ] ; 𝐶 = [−0.5 −0.5]; 𝐷 = 0
1 0 0

Keep in mind that there is not unique solution in state space form so the matrices may differ from an
analytical transformation. Nonetheless, the system behaviour will be the same either in transfer
function form or state space form.

pole(G) and zero(G)


These commands return the poles and zeros of the systems, respectively.
Plotting dynamic system response

Step(G);
The time response of a system in transfer function form and subject to an unit step input can be
assessed using the step command. The example time response using the step command would be:

You can use the commands grid, title(‘title here’), xlabel(‘x axis’), ylabel(‘y axis’), to add information
to your plots. You can also annotate in the plot by using the command
annotation(linetype,x,y,Name,Value). For the plot the command used is

Annotation(‘textarrow’,[0.2 0.3],[0.6,0.5],’String’,’g(t)’)

Additionally, in the plot created you can right click on it and a pop-up menu appears where you can
edit the figure and display system characteristics, for example, the figure above shows setting time
and steady state values.

bode(G);
The Bode command plots of the system frequency response as magnitude and phase. This system
can be a transfer function as defined by the ‘tf’ or ‘zpk’ commands or a state-space system like the
‘Above_Rated_XXmps’ wind turbine models you have been provided with.
The bode plots for the example would be
Once again but doing right click on the figure, you can add system characteristics. In this case
minimum stability margins have been added.

margin(G)
This command plot the frequency response of the system and indicates the gain and phase margins
at their corresponding crossover frequencies. The system response using the margin command
would be:

IMPORTANT NOTE: With higher order systems (like wind turbines) MATLAB can produce the
wrong value for phase. It may be out by a multiple of 180deg. Look at the plot and use your
judgement to verify the numbers that you’re given.
Controller design

controlSystemDesigner(views,G,C,H,F)
This command open the control system designer app which lets you design single-input single-
output (SISO) controllers for feedback systems. The default control architecture is

With the following objects:


• G: system
• C: controller/compensator
• H: sensor model/filter
• F: Prefilter

The objects default values when not specified are 1. To design a PI controller, in frequency domain,
for the example., the command would be
controlSystemDesigner(‘bode’,G)

The figure shows


• Left. Data e.g. systems objects, designs, responses
• Middle. Bode plots with stability margins
• Right. Time response plots

You can double click on object C, on the left hand menu, to open the controller and edit it. As no
controller was initially defined, C=1. Follow the instruction on the compensator editor to add
poles/zeros to your controller (Right click in the Dynamics window). To design a PI controller, an
integrator and a real zero have been added to the compensator. Once the controller dynamics have
been added (poles/zeros), you can close the pop-up window. With the new controller, the stability
margins of the bode plot change and the added zero and integrator appear in red. Now you can tune
your controller gain by dragging up and down the magnitude response with the cursor and changing
the value of the added zero by dragging it along the magnitude response. For the example, the
controller zero is set to be s = -0.37.

The app only allows to modify C and F. To design filters in the feedback path, for instance, to design
drivetrain filters, you can do it by using the bode command as follows

bode(G/(1-G*H));

𝐺
where H is your filter to be tuned and (1−𝐺∗𝐹) is the resulting closed loop transfer function. When
you design the drivetrain filter, G will be a below rated system e.g. ‘Below_Rated_10mps’

You might also like