Vous êtes sur la page 1sur 20

ECEN 3300 Linear Systems Spring 2010

1-18-10 P. Mathys

Lab 1: First Order CT Systems, Blockdiagrams, Intro-


duction to Simulink
1 Introduction
Many continuous time (CT) systems of practical interest can be described in the form of
differential equations. One way to represent such systems is in the form of block diagrams.
Originally, differential equations were often solved using analog computers that implemented
these block diagrams. Nowadays tools, such as Simulink, are used to obtain numerical
solutions to differential equations on digital computers, but still based on block diagram
descriptions. Thus, it is important to learn how to represent analog circuits in the abstract
form of block diagrams and how to obtain results for different CT input signals.

1.1 First Order RC Circuit


Consider the following first order RC circuit with input voltage x(t):

R C
i(t)
+
+ y (t) + y (t)
R C
x(t)

The voltage across the capacitor is yC (t) and the voltage across the resistor is yR (t). From
x(t) = yC (t) + yR (t) it follows that yR (t) = x(t) yC (t). The current i(t) can be computed
as
x(t) yC (t) (1) (1) dyC (t)
i(t) = = C yC (t) , where yC (t) = .
R dt
Thus, the circuit is characterized by the linear differential equation
(1)
RC yC (t) + yC (t) = x(t) , with time constant Tc = RC, and initial condition yC (0) .

A convenient way to represent differential equations is in the form of block diagrams that
use addition, subtraction, gains (i.e., multiplication by a constant), and integrators. The
symbol for an integrator with input x(t), output y(t), and initial condition y(0) at t = 0 is
shown in the following figure.

1
t
x(t)  y(t)
y(t) = x( ) d + y(0)
0

y(0)

To use this as a building block for the representation of differential equations, note that if
(1)
the output of the integrator is yC (t), then its input (for t > 0) must be yC (t) as shown
below.

(1)
yC (t)  yC (t)

y(0)

(1)
But the differential equation RC yC (t) + yC (t) = x(t) can be rewritten as

(1) 1
yC (t) = [x(t) yC (t)] .
RC
Using this together with the integral block yields the block diagram

(1)
x(t) + 1
yC (t)  yC (t)
+ RC

yC (0)

This is the block diagram of an analog computer with input x(t) and output yC (t) that can
be used to simulate the RC circuit for different values of RC and different initial conditions
yC (0). Another way to express this is to say that the analog computer defined by the block
(1)
diagram solves the differential equation RC yC (t) + yC (t) = x(t) for the output variable
yC (t).
A second variable of interest in the RC circuit is the resistor voltage yR (t). Note that from

yR (t) (1) (1)


i(t) = = C yC (t) = yR (t) = RC yC (t) .
R
Thus, the same analog computer can be used to simultaneously compute yR (t) and yC (t) as
shown in the following block diagram.

2
(1)
RC yC (t) yR (t)

(1)
x(t) + 1
yC (t)  yC (t)
+ RC

yC (0)

1.2 Simulink
Simulink is a software package that simulates the bevaior of a dynamic system at successive
time instants within a given range. The dynamic system is typically described in the form of
a blockdiagram that graphically depicts the relationships between system inputs, outputs,
and states. Simulink is closely integrated with Matlab and system parameters, as well as
input, output and state sequences, can be easily imported from and exported to Matlab,
e.g., to use Matlabs powerful graphing capabilities.
Simulink can be used to simulate both continuous time (CT) and discrete time (DT) systems
and combinations thereof. The process of solving a model involves computing successive
system states depending on the initial state and the input signals, and then to use this data
to compute the output signals, all in accordance with the blockdiagram description of the
system. For CT systems approximations, such as
Z (n+1)Ts
y((n + 1)Ts ) = x( ) d y(nTs ) + Ts x(nTs ) ,
0

which is based on Eulers forward approximation, need to be used to update the outputs or
states y(t) of all integration blocks in a model a time instants spaced Ts seconds apart. More
sophisticated methods use better approximations for the area under x(t) than the rectangular
stripes that Eulers method uses. In this way more precise results can be obtained with the
same step size Ts , or the simulation time can be reduced by increasing Ts and/or choosing
it adaptively.
To start Simulink click on this icon or type simulink at the Matlab command prompt.
This brings up the Simulink Library Browser shown below from which you select and then
drag and drop individual blocks to your model window.

3
Most of the blocks needed for ECEN 3300 are in the Commonly Used Blocks libraryR shown
1
in the next figure. Note that the label for the integrator block is s rather than , because
Rt
of the Laplace transform property 0 x( )d 1s X(s).

4
1.3 Simulink Simulation of a First Order System
Start Simulink (type simulink in the Matlab workspace or click on ) to open the Simulink
Library Browser. Click on File, then select New and Model and drag the following
blocks from the Library Browser into the model window.

The Step block is from the Sources library and all other blocks are from the Commonly
Used Blocks library. The Sum block is set up for addition of two input signals when it
comes from the library. To make it into a subtractor, select the block by clicking on it. Then
right-click on it and select Sum Parameters... as shown next.

Change the List of signs entry from |++ to |+- as shown below.

5
To interconnect two blocks, click on the first block to select it, then hold down the Ctrl
key and click on the second block. Alternatively, drag a wire from one block to another by
holding down the left mouse key while moving the cursor from one connection to the other.
The feedforward connections for the first order model are shown in the following figure.

To make the feedback connection from the output of the integrator to the subtractor, start
a wire from the - input of the subtractor as shown next.

6
Then connect the end of this wire to the wire that runs from the integrator to the scope
block. The finished first order block diagram looks like this:

Save the model by clicking on File and selecting Save. To run a simulation click on
Simulation and select Start as shown in the next figure.

7
Double click on the Scope block to see the result of the simulation as displayed in the
following screen snapshot.

As expected, the step response at the output of the integrator of a first order system with
zero intial conditions is of the form

g(t) = A (1 et/Tc ,

where A is the amplitude and Tc is the time constant of the system.


To obtain a better Scope picture, right-click on the Scope graph and select Axes Prop-
erties.... Change the Y-min and the Y-max values and enter a graph title as shown
below.

Now the Scope graph looks like this:

8
One thing that is missing in this graph is the input signal from the Step source. To show
more than one signal on the Scope, use a Mux (multiplexer) block as shown in the new
model below.

If necessary, the number of inputs for the Mux block can be increased under Mux Pa-
rameters... (select the block, then right click on it). If the model above is simulated with
the default parameters, then the result displays as follows on the Scope.

9
To look at the (default) parameters that were actually used in the simulation, click on
Simulation and then choose Configuration Parameters. This brings up the window
shown below.

The default start and stop times are 0.0 and 10.0. The default solver is a variable-step solver
that attempts to optimize the tradeoff between speed and accuracy of the solution. The
alternative choice is a fixed-step solver which needs to be used for instance to produce results
with a specified fixed sampling rate. In either case a numerical integration technique needs to
be specified if the system to be modeled contains CT components. The default variable-step
solver is ode45 as shown in the above solver window. For fixed-step simulations the default
solver is ode3. Both of these work well for most of the systems that will be simulated in
ecen3300.

1.4 Displaying Simulation Results in MATLAB


One of the problems when working directly in Simulink is that the graphing capabilities of
the Scope block are fairly limited. There is a good reason for this, namely the fact that data
can be passed very easily from Simulink to MATLAB and therefore any postprocessing and
graphing of data from a simuation can make use of the power of MATLAB. To export data
from a Simulink model output ports are used like the Out1 block shown in the following
augmented version of the first order CT system model.

10
Before running the simulation of this model (with default parameters), check the Data
Import/Export settings under Simulation, Configuration Parameters... and make sure
the boxes next to Time: tout and Output: yout are checked and the box next to Limit
data points to last: 1000 is unchecked (red circle), as shown in the screen snapshot below.

Then, after runnung the simulation in Simulink, use the MATLAB commands

11
plot(tout,yout(:,1),.-b,tout,yout(:,2),o-r)
%tout and yout are column vectors
%yout has two columns here
grid
title(Step Response of 1st order circuit, Gain=1)
ylim([-0.2,1.2])
xlabel(Time t [sec])
ylabel(x(t), y(t))
legend(x(t),y(t),4)

to produce the following more informative graph.

Step Response of 1st order circuit, Gain=1

0.8

0.6
x(t), y(t)

0.4

0.2

0 x(t)
y(t)
0.2
0 1 2 3 4 5 6 7 8 9 10
Time t [sec]

Type help plot at the MATLAB command prompt to learn more about making plots in
MATLAB and labeling them. As can be seen from the graph, the points (red circles) for
which the output was computed by Simulink are quite evenly spaced. If you look at the
variables tout and yout in the MATLAB workspace, then you can see that at t = 1 where
the step in the input signal occurs there are three samples very close together, one just before
and two just after the step.

2 Prelab Questions
P1. First Order Step Response. For the differential equation
(1)
RC yC (t) + yC (t) = x(t) , with initial condition yC (0) ,
(1)
determine yC (t) and yR (t) = RC yC (t) in response to x(t) = Ax u(t). Sketch and label yC (t)
and yR (t).

12
P2. Block Diagram Using Differentiator. Show how to implement the differential
equation
(1) (1)
RC yC (t) + yC (t) = x(t) , yR (t) = RC yC (t) ,
in the form of a block diagram that uses only adders, subtractors, gains, and differentiators
(d/dt blocks). Show the input x(t) and both outputs, yC (t) and yR (t), in your block diagram.

P3. Approximate Differentiator Using Integrator. Show how the following block dia-
gram which uses an integrator can be used as an approximate differentiator (for bandlimited
signals).

(1)
x(t) + 1
yC (t)  yC (t)
+ RC

yC (0) = 0

How does RC have to be chosen and which signal would be used as output? How would you
test that the system indeed acts as a differentiator?

3 Lab Experiments
E1. Step/Impulse Response in Simulink. The goal of this experiment is to simulate
the RC circuit

R C
i(t)
+
+ y (t) + y (t)
R C
x(t)

for different values of RC and to make plots of the unit step responses of yC (t) and yR (t),
and the unit impulse response of yC (t).
(a) Build the following model in Simulink:

13
Run this model for RC = 0.1, 1, 10 and make labeled plots of x(t), yC (t), and yR (t) using
the MATLAB plot command. The default variable-step solver (ode45) should work fine
for this. You may have to change the stop time of the simulation and the time at which
the unit step occurs to obtain characteristic graphs. Also make sure to uncheck the Limit
data points to last: 1000 option under Simulation, Configuration Parameters... in the
Data Import/Export window. From the plots of yC (t) determine the system rise time
tr , defined as the time it takes for the unit step response to go from 10% to 90% of its final
value. From your observations, can you tell how tr and RC are related?
(b) To obtain the unit impulse response hC (t) of the voltage yC (t) across the capacitor, the
derivative of the step response can be taken since (t) = du(t)/dt and the RC circuit is linear
and time-invariant (LTI). The corresponding Simulink model looks as follows.

To run a simulation for this model use a fixed-step solver with fixed-step size of 0.01 as
shown in the figure below.

14
Note that if RC = 1 then the unit impulse response of yC (t) is the same as the unit step
response of yR (t), so the result obtained from this Simulink model can be checked easily.
Before you run the simulation, make sure to uncheck the Limit data points to last: 1000
option under Simulation, Configuration Parameters... in the Data Import/Export
window. Then plot and label the result of the simulation in Matlab. You may have to
adjust the scaling of the graph to obtain meaningful results or use two separate graphs for
yout(:,1) and yout(:,2). Try changing the fixed-step size to 0.1 and observe if and how
that changes the result.
(c) It is tempting to think that it is better to obtain the unit impulse response hC (t) of yC (t)
by actually using a unit impulse as input for the simulation. Try the following Simulink model
and run it with the same parameters that you used in part(b).

Dont be surprised if the result is not quite right. To obtain the correct result, try other
fixed-step solvers (e.g., ode5, ode4, etc). Which ones do work, which ones dont? Does

15
the model that you used in (b) show the same sensitivity when you use different fixed-step
solvers? What conclusions can you draw?

E2. Sinusoidal Response in Simulink. The intent of this experiment is to characterize


the RC circuit shown in E1 in terms of its frequency selective behavior. Use the following
Simulink model:

This is the same model as the one used in E1a, except that the source is now a sinusoidal
signal (Sine Wave from the Sources library). If you run this model with the default
settings (variable-step ode45 solver) and the Stop time set to 20.0, then you should obtain
a graph in MATLAB (use plot(tout,yout), grid) similar to the one shown below.

16
Note that, for the settings and frequencies used here, it takes about 3-4 seconds before the
sinusoidal outputs (especially the one from yR (t)) reach their steady-state values. Thus, when
you need to measure the (steady-state) amplitude and phase of yR (t) and yC (t) in response to
a sinusoidal input, you need to look at the waveforms after the initial transients have died out.
Another thing to observe from the graph above is that even in steady-state the sinusoids dont
look very smooth. This is a consequence of the fact that Simulink tries to obtain accurate
solution points as quickly as possible and the variable-step solver uses larger time increments
between solution points when nothing big happens. To obtain smoother looking plots you
can increase the Refine factor (under Simulation, Configuration Parameters... in the
Data Import/Export window), e.g., from 1 to 10 as shown in the screen snapshot below.

Now, after adding labels and a legend, the graph looks like this:

17
(a) The input signal for the Simulink model shown above is x(t) = sin(t). Determine the
amplitude and the phase of the sinusoidal steady-state response of yC (t) and yR (t) for RC = 1
and = 0.1, 1, 10 rad/sec. To change the frequency of the Sine Wave source, double-
click on it and then enter the value (in rad/sec) in the dialog box under Parameters and
Frequency. To measure the phase shift of yC (t) and yR (t) with respect to x(t), determine
the fraction of a whole period by which the output signal is delayed or advanced. You
may have to adjust the Stop time of the simulation to obtain characteristic plots of the
steady-state response. Based on your measurements, which of the outputs acts as highpass
filter (HPF) and which acts as lowpass filter (LPF)? How can you tell from your sinusoidal
steady-state response measurements that this is a first order system?
(b) The Simulink model shown below was used to obtain the responses yC (t) and yR (t) of
the RC circuit to a composite input signal x(t).

18
The results of the simulation are shown in the following plot.
Simulation of RC Circuit with Composite Input Signal
1.5

0.5
yR(t)

0.5

1.5
0 1 2 3 4 5 6 7 8 9 10
t [sec]

1.5

0.5
yC(t)

0.5

1.5
0 1 2 3 4 5 6 7 8 9 10
t [sec]

Determine the source and the gain K that was used for the simulation. Recreate the sim-
ulation and make a labeled plot of the signal x(t). Is the solution unique? Explain your
approach!
E3. Approximate Differentiator from Integrator. Use the following blockdiagram
and your solution from prelab problem 3 to set up the Simulink model of an approximate
differentiator made from an integrator block.

19
(1)
x(t) + 1
yC (t)  yC (t)
+ RC

yC (0) = 0

Your differentiator has to be essentially perfect for signals with frequencies of 10 rad/sec or
less and the gain at 10 rad/sec must be equal to 1.
Show your Simulink model and explain your design methodology. Explain how you tested
your model and how you made sure that it satisfies the design requirements. What is the
largest frequency for which your differentiator makes an error of no more than about 10%?
Specify the criteria that you used.

20022010,
c P. Mathys. Last revised: 01-20-10, PM.

20

Vous aimerez peut-être aussi