Module 1.scilab
Module 1.scilab
1 13
Scilab Ninja
Control Engineering with Scilab
Like
Share
Share
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
be the sum of motor and gear inertia. By simple calculation, it is easy to show that the
is described by
(1)
where
represents torque constant. We want to describe a model in transfer function form so that a block
diagram can be drawn. To develop the electrical side of DC motor, consider the model shown in Figure 2.
(2)
where
resistance. It is left to the reader to verify that, in Laplace domain, the joint dynamics in Figure 1 can be
described by
(3)
(4)
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
to
, which gives
(5)
to
is found by setting
(6)
To simplify the equation further, we can assume that the electrical constant
mechanical constant
(7)
(8)
respectively. These two equations correspond to second order differential equation in time domain
(9)
By omitting parameter subscripts, (9) can be rewritten as
(10)
with
disturbance input. The reduced block diagram of (10) can be drawn as in Figure 4.
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
(11)
becomes
(12)
Now we demonstrate how to construct a transfer function such as (12) in Scilab. One method begins by
creating the Laplace variable s
-->s=poly(0,'s')
s =
s
So far so good. It already looks like (12). However, this data format still lacks some inside information
necessary for further processing such as frequency response plot. So one more step is needed to convert it to a
continuous-time linear transfer function, by using the syslin() command
-->P = syslin('c',P)
P =
1
--------2
0.1s + 10s
The interactive response shown in Scilab console does not look any different than before. But the first
argument c passed to syslin tells Scilab that this is a continuous-time system. Now P is ready to be used by
other commands such as bode, freqresp etc.
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
In this method, the numerator and denominator of P are created first, as a number 1 for the former and a
polynomial of s for the latter. Note that the row vector passed to poly(), representing the polynomial
coefficients, starts with the lowest order of s.
Frequency Response
Figure 6 depicts frequency response concept in a nutshell. In words, for a Linear Time-Invariant (LTI) system
driven by a sinusoid input, the output is a sinusoid with same frequency, only its magnitude
might change. When the input frequency varies, this results in new values for
and
and phase
through out a range of frequency, actually a vector of complex numbers, constitutes a frequency response for
an LTI system.
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
is removed.
(13)
By this relationship, a frequency response of a transfer function can be plotted the hard way. Using (12) as
an example, we solve for
manually by substituting
, which gives
(14)
Now we can plot the magnitude and phase versus frequency by using the following set of commands
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
that yields Figure 8. First a linear frequency vector is created in Hz and converted to radian/sec. Vectors for
keeping magnitude and phase information are initialized
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
. Slightly adjust
the above Scilab code to yield a much nicer plot range as in Figure 9.
This type of frequency response is known as Bode plot. An easier way to plot from a transfer function created
by syslin() is by the command bode().
-->s=poly(0,'s');
-->P = 1/(10*s^2+0.1*s);
-->P = syslin('c',P);
-->bode(P)
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
This yields the plot in Figure 10. Type help bode to see options such as how to adjust frequency range.
or
from a Bode plot, we can roughly indicate the frequency point where the magnitude curve touches
For example, from Figure 10, the bandwidth is about
line.
Another type of frequency response useful for control design is called a Nyquist plot. Actually, it is the same
data expressed in different format. Recall that each point of frequency response is just a complex number.
When it is described in polar form, we get a Bode plot. A Nyquist plot, on the other hand, is the frequency
response described in rectangular form
yields the plot in Figure 11. We will discuss this type of data more in later modules.
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
(15)
The bandwidth of (15) is about 0.2 Hz, which you can verify by yourself from a Bode plot, or search it more
accurately from data as follows
-->s=poly(0, 's');
-->P=syslin('c',11.375/(10*s^2+0.1*s));
-->f=linspace(0.01,1,1000);
-->fres=repfreq(P,f); // compute frequency respons
-->ibw=find(abs(fres)<0.707); // find index of bandwidth frequency
-->fbw=f(ibw(1)) // locate BW frequency with index
fbw =
0.2022523
In this chunk of code, we use another Scilab frequency response function repfreq() , which returns a vector of
frequency response without plotting anything. Then use function find() to locate the vector index with gain
less than 0.707, and use that index to find the bandwidth frequency.
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
Now, suppose that during operation, the potentiometer circuit that measures plant output is somehow
contaminated by some noise with higher frequency spectrum than the plant bandwidth. To make it simple,
suppose the noise is a sin wave of magnitude
. Consult some analog filter design cookbook to get that the cutoff frequency of this filter
(16)
Simple calculation shows that practical values of
frequency
rad/s or approximately
and
A transfer function for this LPF can be derived easily. It is left to the reader to verify that it equals
(17)
(18)
Plot the frequency response to verify the cutoff frequency. Since we are now interested in only the magnitude
plot, it is convenient to use Scilab function gainplot(), which does as its name says
-->H=syslin('c',1/(1+0.8*s));
-->gainplot(H)
The plot result in Figure 13 shows that our LPF has cutoff frequency about
as desired.
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
and frequency
to the plant output. Use CMSCOPE block that has two channels.
On the first channel, measure the output contaminated by the noise, and on the second channel, measure the
plant output after passing through the LPF. Do you see the noise attenuated? Try varying the noise magnitude
and frequency. What happens when the noise frequency lies within the plant (and LPF) bandwidth?
Summary
In this study module, we discuss transfer function and frequency response basics, concentrating on Scilab
commands and Xcos block usages. This serves as a good foundation for later development, such as feedback
control analysis and design that relies on block diagram manipulation and frequency domain. Bode plot is a
powerful tool used in classical control design since WWII. In the past, plotting manually on a sheet of paper
could be tedious. Nowadays, software such as MATLAB or Scilab can generate magnitude and phase plots
easily and accurately. Some basic knowledge taught in a undergrad control course is still necessary for sanity
check.
Reference
1. M.W.Spong, S. Hutchinson and M. Vidyasagar, Robot Modeling and Control. John Wiley & Sons. 2006.
Supplement
Exercise solution: LPF_exercise.zcos
module1.zip : all Scilab and Xcos files used in this module.
Comments
Module 1: Transfer Functions and Frequency Responses 1 Comment
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016
http://scilab.ninja/study-modules/scilab-control-engineering-basics/mod... 11/11/2016