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): x(t) + R C i(t) y R (t) + y C (t) + The voltage across the capacitor is y C (t) and the voltage across the resistor is y R (t). From x(t)= y C (t)+ y R (t) it follows that y R (t)= x(t) - y C (t). The current i(t) can be computed as i(t)= x(t) - y C (t) R = Cy (1) C (t) , where y (1) C (t)= dy C (t) dt . Thus, the circuit is characterized by the linear differential equation RC y (1) C (t)+ y C (t)= x(t) , with time constant T c = RC , and initial condition y C (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

Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

ECEN 3300 Linear Systems Spring 20101-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 ofdifferential equations. One way to represent such systems is in the form of block diagrams.Originally, differential equations were often solved using analog computers that implementedthese block diagrams. Nowadays tools, such as Simulink, are used to obtain numericalsolutions to differential equations on digital computers, but still based on block diagramdescriptions. Thus, it is important to learn how to represent analog circuits in the abstractform 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):

◦x(t)

+R C

i(t) →yR(t)+ − yC(t)+ −

The voltage across the capacitor is yC(t) and the voltage across the resistor is yR(t). Fromx(t) = yC(t) + yR(t) it follows that yR(t) = x(t)− yC(t). The current i(t) can be computedas

i(t) =x(t)− yC(t)

R= C y

(1)C (t) , where y

(1)C (t) =

dyC(t)

dt.

Thus, the circuit is characterized by the linear differential equation

RC y(1)C (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 thatuse addition, subtraction, gains (i.e., multiplication by a constant), and integrators. Thesymbol for an integrator with input x(t), output y(t), and initial condition y(0) at t = 0 isshown in the following figure.

1

Page 2: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

y(0)

x(t) y(t)y(t) =

t∫

0

x(τ) dτ + y(0)

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

(1)C (t) as shown

below.

y(0)

y(1)C (t) yC(t)

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

y(1)C (t) =

1

RC[x(t)− yC(t)] .

Using this together with the integral block yields the block diagram

+ 1RC

∫ •

yC(0)

x(t) yC(t)y(1)C (t)+

This is the block diagram of an analog computer with input x(t) and output yC(t) that canbe used to simulate the RC circuit for different values of RC and different initial conditionsyC(0). Another way to express this is to say that the analog computer defined by the block

diagram solves the differential equation RC y(1)C (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

i(t) =yR(t)

R= C y

(1)C (t) =⇒ yR(t) = RC y

(1)C (t) .

Thus, the same analog computer can be used to simultaneously compute yR(t) and yC(t) asshown in the following block diagram.

2

Page 3: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

+ 1RC

∫ •

yC(0)

•x(t) yC(t)

yR(t)RC y(1)C (t)

y(1)C (t)+

1.2 Simulink

Simulink is a software package that simulates the bevaior of a dynamic system at successivetime instants within a given range. The dynamic system is typically described in the form ofa blockdiagram that graphically depicts the relationships between system inputs, outputs,and states. Simulink is closely integrated with Matlab and system parameters, as well asinput, output and state sequences, can be easily imported from and exported to Matlab,e.g., to use Matlab’s powerful graphing capabilities.

Simulink can be used to simulate both continuous time (CT) and discrete time (DT) systemsand combinations thereof. The process of solving a model involves computing successivesystem states depending on the initial state and the input signals, and then to use this datato compute the output signals, all in accordance with the blockdiagram description of thesystem. For CT systems approximations, such as

y((n + 1)Ts) =

∫ (n+1)Ts

0

x(τ) dτ ≈ y(nTs) + Ts x(nTs) ,

which is based on Euler’s forward approximation, need to be used to update the outputs orstates y(t) of all integration blocks in a model a time instants spaced Ts seconds apart. Moresophisticated methods use better approximations for the area under x(t) than the rectangularstripes that Euler’s method uses. In this way more precise results can be obtained with thesame step size Ts, or the simulation time can be reduced by increasing Ts and/or choosingit 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 thendrag and drop individual blocks to your model window.

3

Page 4: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

Most of the blocks needed for ECEN 3300 are in the “Commonly Used Blocks” library shownin the next figure. Note that the label for the integrator block is 1

srather than

∫, because

of the Laplace transform property∫ t

0x(τ)dτ ⇔ 1

sX(s).

4

Page 5: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

1.3 Simulink Simulation of a First Order System

Start Simulink (type simulink in the Matlab workspace or click on ) to open the SimulinkLibrary Browser. Click on “File”, then select “New” and “Model” and drag the followingblocks from the Library Browser into the model window.

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

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

5

Page 6: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

To interconnect two blocks, click on the first block to select it, then hold down the Ctrlkey and click on the second block. Alternatively, drag a wire from one block to another byholding 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, starta wire from the - input of the subtractor as shown next.

6

Page 7: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

Then connect the end of this wire to the wire that runs from the integrator to the scopeblock. 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

Page 8: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

Double click on the “Scope” block to see the result of the simulation as displayed in thefollowing screen snapshot.

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

g(t) = A (1− e−t/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 shownbelow.

Now the Scope graph looks like this:

8

Page 9: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

One thing that is missing in this graph is the input signal from the “Step” source. To showmore than one signal on the Scope, use a “Mux” (multiplexer) block as shown in the newmodel 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 withthe default parameters, then the result displays as follows on the Scope.

9

Page 10: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

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 windowshown below.

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

1.4 Displaying Simulation Results in MATLAB

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

10

Page 11: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

Before running the simulation of this model (with default parameters), check the “DataImport/Export” settings under “Simulation”, “Configuration Parameters...” and make surethe boxes next to “Time: tout” and “Output: yout” are checked and the box next to “Limitdata 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

Page 12: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

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 1’’st 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.

0 1 2 3 4 5 6 7 8 9 10−0.2

0

0.2

0.4

0.6

0.8

1

Step Response of 1’st order circuit, Gain=1

Time t [sec]

x(t)

, y(t

)

x(t)y(t)

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

2 Prelab Questions

P1. First Order Step Response. For the differential equation

RC y(1)C (t) + yC(t) = x(t) , with initial condition yC(0) ,

determine yC(t) and yR(t) = RC y(1)C (t) in response to x(t) = Ax u(t). Sketch and label yC(t)

and yR(t).

12

Page 13: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

P2. Block Diagram Using Differentiator. Show how to implement the differentialequation

RC y(1)C (t) + yC(t) = x(t) , yR(t) = RC y

(1)C (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 bandlimitedsignals).

+ 1RC

yC(0) = 0

x(t) yC(t)y(1)C (t)+

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

3 Lab Experiments

E1. Step/Impulse Response in Simulink. The goal of this experiment is to simulatethe RC circuit

◦x(t)

+R C

i(t) →yR(t)+ − yC(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

Page 14: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

Run this model for RC = 0.1, 1, 10 and make labeled plots of x(t), yC(t), and yR(t) usingthe MATLAB plot command. The default variable-step solver (ode45) should work finefor this. You may have to change the stop time of the simulation and the time at whichthe unit step occurs to obtain characteristic graphs. Also make sure to uncheck the “Limitdata 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 timetr, defined as the time it takes for the unit step response to go from 10% to 90% of its finalvalue. 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, thederivative of the step response can be taken since δ(t) = du(t)/dt and the RC circuit is linearand 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 asshown in the figure below.

14

Page 15: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

Note that if RC = 1 then the unit impulse response of yC(t) is the same as the unit stepresponse 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 toadjust the scaling of the graph to obtain meaningful results or use two separate graphs foryout(:,1) and yout(:,2). Try changing the fixed-step size to 0.1 and observe if and howthat 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 modeland run it with the same parameters that you used in part(b).

Don’t be surprised if the result is not quite right. To obtain the correct result, try otherfixed-step solvers (e.g., ode5, ode4, etc). Which ones do work, which ones don’t? Does

15

Page 16: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

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

E2. Sinusoidal Response in Simulink. The intent of this experiment is to characterizethe RC circuit shown in E1 in terms of its frequency selective behavior. Use the followingSimulink model:

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

16

Page 17: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

Note that, for the settings and frequencies used here, it takes about 3-4 seconds before thesinusoidal outputs (especially the one from yR(t)) reach their steady-state values. Thus, whenyou need to measure the (steady-state) amplitude and phase of yR(t) and yC(t) in response toa 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 don’tlook very smooth. This is a consequence of the fact that Simulink tries to obtain accuratesolution points as quickly as possible and the variable-step solver uses larger time incrementsbetween solution points when nothing big happens. To obtain smoother looking plots youcan 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

Page 18: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

(a) The input signal for the Simulink model shown above is x(t) = sin(ωt). Determine theamplitude and the phase of the sinusoidal steady-state response of yC(t) and yR(t) for RC = 1and ω = 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), determinethe fraction of a whole period by which the output signal is delayed or advanced. Youmay have to adjust the “Stop time” of the simulation to obtain characteristic plots of thesteady-state response. Based on your measurements, which of the outputs acts as highpassfilter (HPF) and which acts as lowpass filter (LPF)? How can you tell from your sinusoidalsteady-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) ofthe RC circuit to a composite input signal x(t).

18

Page 19: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

The results of the simulation are shown in the following plot.

0 1 2 3 4 5 6 7 8 9 10−1.5

−1

−0.5

0

0.5

1

1.5Simulation of RC Circuit with Composite Input Signal

t [sec]

y R(t

)

0 1 2 3 4 5 6 7 8 9 10−1.5

−1

−0.5

0

0.5

1

1.5

t [sec]

y C(t

)

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 yourapproach!

E3. Approximate Differentiator from Integrator. Use the following blockdiagramand your solution from prelab problem 3 to set up the Simulink model of an approximatedifferentiator made from an integrator block.

19

Page 20: Lab 1: First Order CT Systems, Blockdiagrams, Intro- …ece.colorado.edu/~mathys/ecen3300/pdf/lab01.pdfECEN 3300 Linear Systems Spring 2010 1-18-10 P. Mathys Lab 1: First Order CT

+ 1RC

yC(0) = 0

x(t) yC(t)y(1)C (t)+

Your differentiator has to be essentially perfect for signals with frequencies of 10 rad/sec orless and the gain at 10 rad/sec must be equal to 1.

Show your Simulink model and explain your design methodology. Explain how you testedyour model and how you made sure that it satisfies the design requirements. What is thelargest frequency for which your differentiator makes an error of no more than about 10%?Specify the criteria that you used.

c©2002–2010, P. Mathys. Last revised: 01-20-10, PM.

20