ece 203 – lab 1 matlab signals and systemsweb.cecs.pdx.edu/~ece2xx/ece203/ece203exp1v21.pdfece 203...

20
Version 2.1 1 of 20 © 2001 Department of Electrical and Computer Engineering at Portland State University. ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS ECE 201 and 202 Labs EXPECTED KNOWLEDGE Linear systems Transfer functions Step and impulse responses (at the level covered in ECE 222) EQUIPMENT Computer with MATLAB Version 6.0 or higher MATERIALS Formatted 1.44 3¼ floppy diskette (optional) OBJECTIVES After completing this lab you should be more familiar with MATLAB. Specifically, you should be able to use MATLAB to analyze transfer functions and know how to use some of the functions provided in the Control Toolbox. INTRODUCTION MATLAB has many tools to help you analyze and design systems. These tools allow you to determine the response of systems, measure system performance, and visualize system dynamics. PRELAB Answer Questions 1 – 3. MATLAB DEMOS MATLAB comes with many demos that can help you get a grasp of how MATLAB can assist in the design and analysis of linear time-invariant (LTI) systems. Two of these demos are the Response Demo (respdemo) and the RLC Demo (rlcdemo). Typing respdemo and rlcdemo at the MATLAB command prompt can access these demos.

Upload: phungdien

Post on 06-Mar-2018

228 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 1 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS

BEFORE YOU BEGIN

PREREQUISITE LABS • ECE 201 and 202 Labs

EXPECTED KNOWLEDGE • Linear systems • Transfer functions • Step and impulse responses (at the level covered in ECE 222)

EQUIPMENT • Computer with MATLAB Version 6.0 or higher

MATERIALS • Formatted 1.44 3¼ floppy diskette (optional)

OBJECTIVES

After completing this lab you should be more familiar with MATLAB. Specifically, you should be able to use MATLAB to analyze transfer functions and know how to use some of the functions provided in the Control Toolbox.

INTRODUCTION

MATLAB has many tools to help you analyze and design systems. These tools allow you to determine the response of systems, measure system performance, and visualize system dynamics.

PRELAB

Answer Questions 1 – 3.

MATLAB DEMOS MATLAB comes with many demos that can help you get a grasp of how MATLAB can assist in the design and analysis of linear time-invariant (LTI) systems. Two of these demos are the Response Demo (respdemo) and the RLC Demo (rlcdemo). Typing respdemo and rlcdemo at the MATLAB command prompt can access these demos.

Page 2: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 2 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

Take some time to explore these three demos to get and idea of MATLAB’s capabilities. In this lab, you will be doing simulations similar to the ones found in these demos.

Answer Questions 4 – 5.

MATLAB STRUCTURES Structures allow the grouping of dissimilar data types into a single variable. This is similar to creating a new data type. For example, you can define a variable called curve that can store information about a curve to be plotted in MATLAB. For example, a curve can be represented as the values for the abscissa data, ordinate data, and line color. For this data, you should use vectors to store the information for the abscissa and the ordinate data points, and a string to hold the information about the line color. Do the following for the curve defined by 122

1 ++= xxy .

Declare the abscissa with the following command:

>> x = -2:0.001:2; >> curve.abscissa = x;

This creates a vector of values in the range of 22 ≤≤− x with a step 001.0=∆x , and fills the abscissa field of the structure curve with these values.

Next, define the ordinate field data as follows:

>> curve.ordinate = x.^2 + 2.*x + 1; and the line field (to hold a text string indicating the line color) as:

>> curve.line = 'r'; Type in the name of the structure, in this case curve. MATLAB displays the name of the structure, followed by information about the structure’s fields.

>> curve curve = abscissa: [1x4001 double] ordinate: [1x4001 double] line: 'r'

The fields for our data structure, curve, are abscissa, ordinate, and line. We can tell from the information above that abscissa and ordinate are vectors (with 4001 elements) and that line is a string.

You can access the individual fields of the structure by using the syntax struct.field. Notice that this is the same syntax we used to enter the information when we created the structure.

Plot the curve, by typing in the following command:

>> plot(curve.abscissa, curve.ordinate, curve.line); The resulting curve is shown in Figure 1.

Page 3: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 3 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

You can store more than one element in our structure curve. Add a second curve defined by 3

2 xy = by typing the following commands:

>> curve(2).abscissa = x; >> curve(2).ordinate = x.^3; >> curve(2).line = 'b';

Figure 1. Plot of Curve 2 2 1x x+ + .

An index (2 in this case) was used to add another element to the structure. You have now created a cell array containing the structure curve that has two elements: curve(1) and curve(2). To access any element in the array, the index must be used. For example, to access the second curve in the array you must type curve(2). Furthermore, you can no longer access the first element by simply typing curve; you must now type curve(1).

Answer Questions 6 – 7.

CELL ARRAYS Cell arrays are multidimensional arrays whose elements are themselves arrays, called cells. Each cell in an array can hold any MATLAB data type. Figure 2 shows an conceptual example of a 2 x

Page 4: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 4 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

2 cell array. Each cell in the array matrix contains a different data type. The cell array represented in Figure 2 can be created with the following commands:

>> C(1,1) = {magic(3)}; >> C(1,2) = {strvcat('Evans','Turner','McNames')}; >> C(2,1) = {7 + 13i}; >> C(2,2) = {-2:2};

Cell 1,1 Cell 1,2

Cell 2,1 Cell 2,2

'Evans'

'Turner'

'McNames'

7 + 13i -2, -1, 0, 1, 2

294

753

618

Figure 2. Example of a 2 X 2 Cell Array. This figure is to demonstrate the structure of a cell array only. MATLAB does not display the contents of cell arrays in exactly this

manner using the cellplot command.

The same cell array could also have been entered with the following commands:

>> C{1,1} = magic(3); >> C{1,2} = {strvcat('Evans','Turner','McNames')}; >> C{2,1} = 7 + 13i; >> C{2,2} = -2:2;

To display the contents of an individual cell, we would use the syntax

cellarray{i, j}

where

i is the row number

Page 5: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 5 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

j is the column number

For example, to display the complex number in row 2, column 1, we would type

>>C{2,1}

Answer Question 8.

THE STRUCT COMMAND There may be times when we want to create a structure with data already contained in a cell array. This can be accomplished with the STRUCT command. The syntax for the STRUCT command is

s = struct(‘field1’,values1,’field2’,values2,…) s = struct(‘field1,{},field2,{},…)

where

s is the name of the structure to be created field1, field2, … are the names of the structure fields values1, values2,… are the cell arrays containing the values of the different structure elements

This second syntax example creates a structure with empty fields. Review the on line documentation on the GETFIELD command to answer the following questions.

Answer Questions 9 – 11.

WORKING WITH POLYNOMIALS

The POLY Command

The POLY command will return the polynomial coefficients of a polynomial equation given a vector that contains the roots of the polynomial. The syntax for the POLY command is

p = poly(r) where

p is a vector containing the polynomial coefficients r is a vector containing the roots of the polynomial

For example, suppose we want to determine the polynomial with roots at –2 and –1. Using the POLY command we would type

>> p = poly([-2 -1]) p = 1 3 2

Therefore, the polynomial with roots at –2 and –1 is 2 3 2x x+ + .

Answer Questions 12 – 13.

Page 6: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 6 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

The ROOTS Command

The ROOTS command is the opposite of the POLY command. The ROOTS command returns the roots of a polynomial given a vector that contains the polynomial coefficients. The syntax for ROOTS is

r = roots(p)

where

r is a vector containing the roots of the polynomial p is a vector containing the polynomial coefficients

If we use the polynomial 2 3 2x x+ + from the POLY example, we can determine its roots by typing

>> r = roots([1 3 2]) r = -2 -1

which match the values of the roots we used with the POLY command above.

Answer Question 14.

The POLYVAL Command

The POLYVAL command evaluates a polynomial at a given value or set of values. The syntax for the POLYVAL command is

y = polyval(p,x)

where

y is the value of the polynomial at x p is a vector containing the polynomial coefficients x is a vector of values at which to evaluate the polynomial

For example, if we wanted to find the value of the polynomial 232 ++ xx when 3=x , we would type the commands

>> p = [1 3 2]; >> y = polyval(p, 3) y = 20

The results tells us that when 3=x , the polynomial equates to 20.

Page 7: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 7 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

If we wanted to find the values of the same polynomial for the values }7,5,3,1{=x , we would type the commands

>> y = polyval(p, [1 3 5 7]) y = 6 20 42 72

Answer Question 15.

The RESIDUE Command

The RESIDUE command converts a ratio of polynomials to pole-residue representation. In other words, it does partial fraction expansion given the ratio of two polynomials. The syntax for the RESIDUE command is

[r p k] = residue(num, den) where

num is a vector containing the polynomial coefficients of the numerator den is a vector containing the polynomial coefficients of the denominator r is a vector containing the residue values p is a vector containing the poles k is a vector of direct terms

The best way to describe the RESIDUE command is with an example. Suppose you want to

perform a partial fraction expansion of 132

12

2

+++

xxx . At the command prompt, type

>> num = [1 0 1]; >> den = [2 3 1]; >> [r p k] = residue(num, den) r = -2.0000e+000 1.2500e+000 p = -1.0000e+000 -5.0000e-001 k = 5.0000e-001

From the values of r, p and k we would write the partial fraction expansion as

5.025.1

125.0

++

+−

xx.

The RESIDUE command can also be used to convert the expansion back to a ratio of two polynomials. The syntax for this is

[num den] = residue(r, p, k)

Page 8: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 8 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

Answer Question 16.

TRANSFER FUNCTION MODELS

The TF and the TFDATA Commands

The TF command is used to create MATLAB representations of systems described by transfer functions. The most commonly used syntax for TF is

sys = tf(num, den)

where

sys is the transfer function num is a vector containing the polynomial coefficients of the numerator den is a vector containing the polynomial coefficients of the denominator

For example, create the transfer function ( )23

12 ++

−=

ssssH with the following command

>> sys = tf([1 -1],[1 3 2]) and get the following results:

Transfer function: s - 1 ------------- s^2 + 3 s + 2

The TFDATA command “undoes” what the TF command does. Given a transfer function model, TFDATA returns the coefficient polynomials for the numerator and the denominator. The syntax for the TFDATA command is

[num, den] = tfdata(sys) or

[num, den] = tfdata(sys,’v’)

where

num is a cell array containing the polynomial coefficients of the numerator den is a cell array containing the polynomial coefficients of the denominator sys is the transfer function model ‘v’ returns the polynomial coefficients of the numerator and the denominator as vectors

If TFDATA is used without the ‘v’ argument, then num and den will be cell arrays. If you want num and den to be vectors, the ‘v’ argument must be used.

Answer Questions 17 – 18.

Page 9: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 9 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

The ZPK and the ZPKDATA Commands

The ZPK is used to specify a linear system by specifying the poles, zeros, and gain of the system, or to convert a system specified in another manner (such as a transfer function) to the zero-pole-gain form. The most commonly used syntax for the ZPK command is

sys = zpk(z,p,k) sys = zpk(s)

where

sys is the transfer function z is a vector containing the real or complex zeros p is a vector containing the real or complex poles k is the real valued scalar gain s is a system model (such as one created by the TF command)

Create the pole-zero-gain model of the transfer function ( ) ( )( )( ) ( )51

2132 −+

+−=

sssssH with the following

command:

>> sys = zpk([1 -2],[-1 -1 5],3)

With result Zero/pole/gain: 3 (s-1) (s+2) ------------- (s+1)^2 (s-5)

Also, create a zero-pole-gain model of the transfer function ( )23

12 ++

−=

ssssH with the

following commands (and result):

>> s = tf([1 -1],[1 3 2]); >> sys = zpk(s) Zero/pole/gain: (s-1) ----------- (s+2) (s+1)

The ZPKDATA returns information about the zero-pole-gain model created by the ZPK command (similar to the TFDATA command). The syntax for ZPKDATA is

[z, p, k] = zpkdata(sys) [z, p, k] = zpkdata(sys,’v’)

where

Page 10: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 10 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

z is a cell array containing the zeros p is a cell array containing the poles k is the real valued scalar gain sys is the transfer function model ‘v’ returns the zeros and poles as vectors

Just like TFDATA, if ZPKDATA is used without the ‘v’ argument, then z and p will be cell arrays. If you want z and p to be vectors, the ‘v’ argument must be used.

Answer Questions 19 – 20.

The POLE and ZERO Commands

The POLE and ZERO commands are used to extract the poles and zeros of system models, such as is created by tf or zpk. The syntax for the two commands are:

p = pole(sys) z = zero(sys) [z, k] = zero(sys)

where

p is a vector containing the real or complex poles z is a vector containing the real or complex zeros k is the gain sys is the system model

Answer Question 21.

THE PZMAP COMMAND PZMAP is a command used to create a pole-zero plot of a linear time invariant system. The syntax for PZMAP is

pzmap(sys) pzmap(sys1, sys2, …)

where

sys, sys1 and sys2 are linear time invariant system models

Figure 3 shows a pole-zero plot created using PZMAP of the transfer function

( )23

12 ++

−=

ssssH . The Xs represent the poles and the Os represent the zeros. To add plot lines

Page 11: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 11 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

of constant damping ratio and natural frequency, the command SGRID (for s-domain) is used in following PZMAP.

PZMAP can also be used to extract the poles and zeros of a linear time invariant system. The syntax for this is

[p, z] = pzmap(sys)

where

p is a vector containing poles z is a vector containing the zeros

When used to extract the poles and zeros the pole-zero diplay is not created.

Answer Question 22.

Figure 3. Pole-Zero Plot of ( )23

12 ++

−=

ssssH .

Page 12: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 12 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

LTIVIEW LTIVIEW is used to create various plots to a linear time invariant (LTI) system. The syntax for LTIVIEW is

ltiview(sys)

where

sys is a system model

When executed, LTIVIEW opens up a viewing window, as shown in Figure 4. Various plots can be selected for viewing by right clicking on the current plot and then selecting Plot Type⇒ and then clicking on the desired plot. Measurements may be made on the curve by positioning the pointer over the curve and left clicking.

Experiment around in LTIVIEW by looking at all the available plots it has to offer.

Answer Questions 23 – 24.

Figure 4. LTI Viewer.

Page 13: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 13 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

LINEAR TIME INVARIANT SYSTEMS

THE LSIM COMMAND The LSIM command is used to simulate and plot the response of linear time invariant (LTI) systems to arbitrary inputs. The syntax for LSIM is

lsim(sys,u,t)

where

sys is a transfer function model u is a vector of (signal) inputs and must be the same length as t t is a vector of time samples

Figure 5 shows an example of a plot created with LSIM. The top plot is a square wave used as the input to the LTI model. The bottom plot is the response to the square wave of the LTI model.

The transfer function ( )52

52 ++

+=

ssssH was used as the LTI system.

Page 14: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 14 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

Figure 5. Responce of LTI System to Square Wave.

Figure 5 was created with the following commands:

>> sys=tf([1 5],[1 2 5]); >> [u,t]=gensig('square',1,10); >> subplot(2,1,1) >> plot(t,u) >> set(gca,'Ylim',[-0.1 1.1]) >> subplot(2,1,2) >> lsim(sys,u,t)

Answer Question 25.

THE STEP AND IMPULSE COMMANDS STEP and IMPULSE commands are used to plot the response of a system to a step and inpulse signal respectively. The syntax for these two commands are

step(sys) step(sys,t) impulse(sys) impulse(sys,t)

where

sys is a system model t is a time vector

If the variable ‘t’ is omitted, the range will be chosen automatically.

Figure 6 shows the step and impulse response to the system ( )52

52 ++

+=

ssssH . The figure was

created with the following commands:

>> subplot(2,1,1) >> step(sys,10) >> subplot(2,1,2) >> impulse(sys,10)

Answer Question 26.

Page 15: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 15 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

Figure 6. The Response of an LTI System to a Step and Impulse Signal.

THE BODE COMMAND You should already be familiar with MATLAB’s BODE command (ECE 202, Lab Experiment 4). The BODE command can also be used with transfer function models to create magnitude and phase Bode plots. The syntax is quite simple:

bode(sys) bode(sys1,sys2,…)

where

sys, sys1, sys2 are system models The BODE command can also be used to return the magnitude and the phase of the transfer function model.

[mag, phase, w] = bode(sys)

Recall that mag is the absolute magnitude of the transfer function; it is not in decibels.

Answer Question 27.

Page 16: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 16 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

SIMULINK

Simulink is a graphical mathematical programming tool which can be used to create signal flow models for time domain simulation, like those typically used in control systems analysis. You will use Simulink to program a set of differential equations represented by the transfer function

( )sss

sssH52

26223 +++−

= and determine a step response of such a system.

To enter Simulink, type simulink at the MATLAB command prompt. This will open up the Simulink Library Browser (Figure 7; More recent versions of Simulink may have more library categories than shown here). The lower right pane shows the mathematical operation block libraries available in Simulink. Take a few minutes to explore the different links to get familiar with what’s available in Simulink.

Create a new model by selecting File⇒New⇒Model. This will open the New Model window. Models are created by addign functional blocks to model window, setting block parameters, and connecting blocks in proper sequence. To add a block to the model, drag and drop the part from the library to the model window. Start by adding the step function to the model window.

The step function can be found in the Source Library. Open the Source Library by double clicking on its icon. Scroll down until you see the Step icon. Drag and drop the Step icon into the model window.

Next, add the Sum and the Slider Gain controls to the model. Both of these items can be found in the Math Library. Now add the Transfer Function block from the Continuous Library and the Scope block from the Sinks Library. Your model should start to look like the one in Figure 8, without the lines connecting blocks.

Page 17: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 17 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

Figure 7. Simulink Library Browser.

Block parameters may be set to specify the operation of each block. Start by double clicking on the Sum icon. This will open up the Block Parameters dialog box. In the “List of signs:” text box you will see two plus signs (++), indicating the block will operate as a two input summer. Change the contents of this box to a plus sign and a minus sign (+-) to configure the block to take the difference of the two inputs and then click OK. See Figure 9.

Double click the Slider Gain icon and change the value in the middle text box from 1 to 0.38 and click OK.

Double-click on the Transfer Function icon and type in the polynomial coefficient vectors for the

numerator and the denominator for the transfer function ( )sss

sssH52

26223 +++−

= (see Figure 10)

and click on OK.

Now that all the blocks are in place and parameter values are set, you must connect the blocks.

Page 18: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 18 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

Figure 8. Simulink Model of Linear System.

Figure 9. Block Parameters: Sum Dialog Box.

Look at the Step block, and will notice a > symbol pointing out of the block; this is an output port. Similarly, looking at the Scope block we will see a > pointing into the block; this is an input port. If we look at all the other blocks, we notice that they have various input and output ports as well. The input and output ports are where we will be connecting the blocks together.

To connect the Step block to the Sum block, place the cursor over the output port of the Step block. Notice how the cursor becomes a crosshair. Hold down the left mouse button and move the crosshairs over to the input port at the left of the Sum block. When you reach the Sum

Page 19: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 19 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

block’s input port, the crosshairs change to a double-lined crosshairs. Release the mouse button to complete the connection. Repeat this procedure to connect the rest of the blocks as shown in Figure 8. Your model should now look like the one in Figure 8. This is a signal flow representation of a system with “plant” described by the transfer function, unity gain output feedback, and an error amplifier creating a “correction” input to the plant. The step response of this system will be quite different from that of the transfer function alone.

You will now run a simulation.

Figure 10. Block Parameters: Transfer Function Dialog Box.

From the menu toolbar, select Simulation⇒Start. After the simulation is complete, double-click on the Scope icon to see the response of the system. Your plot should look like that of Figure 11.

Figure 11. Output of Scope From Simulink Model.

Page 20: ECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMSweb.cecs.pdx.edu/~ece2xx/ECE203/ECE203Exp1V21.pdfECE 203 – LAB 1 MATLAB SIGNALS AND SYSTEMS BEFORE YOU BEGIN PREREQUISITE LABS • ECE

Version 2.1 20 of 20

© 2001 Department of Electrical and Computer Engineering at Portland State University.

Answer Questions 28 – 34.

Different settings for the simulation my be set by doing Simulate -> Simulation Parameters… from the pull down menu bar, or by right clicking in the model window and selecting Simulation Parameters… .

Before exiting Simulink, you may want to save your model (it may be useful for future labs).